Breadth-First Search (BFS)
What is BFS?
Breadth-First Search is a graph traversal algorithm that explores nodes level by level, starting from a designated root node.
Key Steps of BFS
- Start by adding the source node to a queue.
- Remove a node from the queue and visit it.
- Add all unvisited neighbors to the queue.
- Repeat steps 2-3 until the queue is empty.
Advantages of BFS
- Finds the shortest path in unweighted graphs.
- Can be used to test graph connectivity.
- Simple and easy to implement using a queue.
BFS Diagram
Learn More
For more detailed information, visit
GeeksforGeeks: Breadth First Search or BFS for a Graph
.