Topic 13: Shortest Path Algorithms π
Now we move deeper into graphs. The key interview question is: Given a graph, how do I find the minimum-cost path from one node to another? The correct algorithm depends mainly on edge weights. Memorize this table: Graph Algorithm Unweighted graph BFS Weights are only 0 and 1 0-1 BFS Non-negative weights Dijkstra Negative weights possible Bellman-Ford All-pairs shortest paths Floyd-Warshall DAG Topological-order shortest path Unweighted β BFS Non-negative weighted β Dijkstra Negative edges β Bellman-Ford You already saw this with BFS. Example: 0 --- 1 --- 2 | 3 Every edge has equal cost.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in