Introduction to
BFS

Introduction to Breadth First Search
Breadth First Search (BFS) is a graph traversal algorithm that explores all the vertices in a graph at the current depth before moving on to the vertices at the next depth level. It starts at a specified vertex and visits all its neighbors before moving on to the next level of neighbors. BFS is commonly used in algorithms for pathfinding, connected components, and shortest path problems in graphs.






Steps to understand BFS:
1. Initially queue and visited arrays are empty.
2. For example, Push node 0 into queue and mark it visited.
3.Now,Remove node 0 from front of queue and visit the unvisited neighbours and push them into queue.
4. Now, Remove node 1 from the front of queue and visit the unvisited neighbours and push them into queue.
5. Repeats the steps until queue becomes empty, which means we have visited all the nodes and our BFS traversal ends.