Introduction - BFS is a graph traversal algorithm.
- Explores all vertices at the present depth level before moving on.
- Uses a queue data structure to keep track of vertices to visit.
Example-1: A BFS Traversal Graph:
A - B - C
| | |
D - E - F
Traversal Order:
A → B → D → C → E → F
- Explores neighbors before going deeper.
- Ensures shortest path in unweighted graph.
Example-2: Non-BFS Traversal Graph:
A - B - C
| | |
D - E - F
Wrong Order:
A → D → E → B → C → F
- Jumps depth levels.
- Does not follow BFS rules.
Time Complexity O(V + E)
Where V = number of vertices
E = number of edges
Applications - Shortest path in unweighted graphs
- Web crawling
- Social network analysis
- Broadcasting in networks