You are on page 1of 7

MANUAL

Design and Analysis of Algorithms


[PATTERN 2020]

A lab manual for implementation of lab practicals in the course


Design and Analysis of Algorithms for

Third Year Bachelor Of Technology


AY-2023-24, Sem-V

Course Coordinator
Dr. Gauri Ghule

Course Teachers
Dr. Arti Bang

Head of Department
Prof.(Dr.) Shraddha. K. Habbu

Department of Electronics and Telecommunication Engineering


VISHWAKARMA INSTITUTE OF INFORMATION TECHNOLOGY, PUNE
(An Autonomous Institute Affiliated to Savitribai Phule Pune University)

i
Certificate

This is to certify that Riteshkumar Kacharu Sadgir, (GR. No.22110889) (Roll


No.311040) of Third Year Bachelor Of Technology has performed the
mentioned Experiments in the “Design and Analysis of Algorithms” in
Department of Electronics and Telecommunication Engineering, laboratories of
Vishwakarma Institute Of Information Technology, Pune 411048.

Dr.Arti Bang Prof.(Dr.) S. K. Habbu


Course Teacher Head,
Department of E&TC Engineering VIIT,
Pune

Prof. (Dr.) Vivek S. Deshpande

Director

Vishwakarma Institute of Information Technology, Pune

Date: 9 November 2023

Place: Pune

ii
Lab Manual –Design and Analysis of Algorithms

2018 course

EXPERIMENT NO: 08

TITLE OF EXPERIMENT: Program to implement Graph Traversal: Breadth First


Traversal

Department of E & TC, Vishwakarma Institute of Information Technology, Pune 3


Lab Manual –Design and Analysis of Algorithms

2018 course

Program to implement Graph Traversal: Breadth First Search Traversal

8.1 Aim: Program to implement Breadth First Search Traversal

8.2 Problem statement: To write a JAVA program to perform Breadth First Search
Traversal for given graph.

8.3 Theory:

BFS Breadth First Search is an algorithm used to search the Tree or Graph. BFS search
starts from root node then traversal into next level of graph or tree and continues, if item
found it stops otherwise it continues. The disadvantage of BFS is it requires more memory
compare to Depth First Search (DFS).

8.4 Algorithm:

A standard BFS implementation puts each vertex of the graph into one of two
categories:

Visited

Not Visited

The purpose of the algorithm is to mark each vertex as visited while avoiding cycles.

The algorithm works as follows:

Step 1: Start by putting any one of the graph's vertices at the back of a queue.

Step 2: Take the front item of the queue and add it to the visited list.

Step 3: Create a list of that vertex's adjacent nodes. Add the ones which aren't in the
visited list to the back of the queue.

Step 4: Keep repeating steps 2 and 3 until the queue is empty.

Department of E & TC, Vishwakarma Institute of Information Technology, Pune 4


Lab Manual –Design and Analysis of Algorithms

2018 course

Code:

Department of E & TC, Vishwakarma Institute of Information Technology, Pune 5


Lab Manual –Design and Analysis of Algorithms

2018 course

Output :

8.5 Write answers to the following questions

(1) Explain the time complexity of BFS traversal.

Ans : Time complexity of BFS depends upon the data structure used to represent the graph.
The time complexity of BFS algorithm is O(V+E), since in the worst case, BFS algorithm
explores every node and edge. In a graph, the number of vertices is O(V), whereas the
number of edges is O(E).The space complexity of BFS can be expressed as O(V), where V
is the number of vertices.

(2) Write applications of BFS algorithm.

Ans :
1. Shortest Path and Minimum Spanning Tree for unweighted graph
2. Social Networking Websites
3. GPS Navigation systems
4. Broadcasting in Network
5. Path Finding
6. Network Security
7. Image processing
8. Topological sorting

Department of E & TC, Vishwakarma Institute of Information Technology, Pune 6


Lab Manual –Design and Analysis of Algorithms

2018 course

8.6 Conclusion :Thus we successfully wrote a JAVA program to perform Breadth First
Search Traversal for given graph.

Department of E & TC, Vishwakarma Institute of Information Technology, Pune 7

You might also like