Graph Theory37 sections · 1633 units
Open in Course

When BFS Wins

(Unweighted graphs only)

BFS finds shortest paths when every edge has weight 11. This includes most grid problems and social network graphs.

If weights vary, BFS gives wrong answers. It treats a path of 1010 edges as longer than a path of 22 edges with weight 100100 each.

Use BFS only when the problem states "unweighted" or all edges clearly have the same cost. In grid problems, each cell-to-cell move costs 11, so BFS is the default choice for grid shortest paths.