Professional Documents
Culture Documents
Course Coordinator
Dr. Gauri Ghule
Course Teachers
Dr. Arti Bang
Head of Department
Prof.(Dr.) Shraddha. K. Habbu
i
Certificate
Director
Place: Pune
ii
Lab Manual –Design and Analysis of Algorithms
2018 course
EXPERIMENT NO: 08
2018 course
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.
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.
2018 course
Code:
2018 course
Output :
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.
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
2018 course
8.6 Conclusion :Thus we successfully wrote a JAVA program to perform Breadth First
Search Traversal for given graph.