MIT6.006 R15. Shortest Paths
BFS for Shortest Paths BFS can actually be used to find shortest paths! …provided that all weights equal 1. How can we fix this to apply to more general cases? We may use a priority queue instead. Each time we pop out only the nearest guy and deal with it, but that would be Dijkstra. A simpler thing that we can do is to add fake nodes to the graph . For example, 3 fake nodes for an edge with length 4, just to split up the edge into small unit edges. Analysis for the tweaked BFS: E = W ′ E ′ , V = W ′ E ′ + V ′ E=W'E',V=W'E'+V' E = W ′ E ′ , V = W ′ E ′ + V ′ T ( n ) = O ( V ′ + W ′ E ′ ) T(n)