Breadth-First Search (BFS)

Explores graph level by level using a queue. Finds shortest path in unweighted graphs and shortest hops in social networks. Queue FIFO; visited set prevents revisits.

Method

• Enqueue start, mark visited. • Dequeue, visit neighbours, enqueue unvisited. • Repeat until queue empty.

Limitations

Memory O(V) for queue; DFS is lighter for deep searches. Use a queue and mark vertices on enqueue. Minimum edge-count paths are shortest paths for unweighted/equal-weight graphs, not arbitrary weighted graphs.

Example

Friend-of-friend: BFS level 1 = friends, level 2 = friends-of-friends.

Editorial clarification

Use a queue and mark vertices on enqueue. Minimum edge-count paths are shortest paths for unweighted/equal-weight graphs, not arbitrary weighted graphs.

Sources

Educational reference only, not professional advice.

All algorithms