Topic 16 / 16
Advanced Graphs
Dijkstra, Bellman-Ford, Prim's, Kruskal's. Weighted shortest paths and minimum spanning trees.
Advanced graph algorithms handle weighted edges. Dijkstra finds the shortest path in O((V + E) log V) using a min-heap โ but only works with non-negative weights. Bellman-Ford handles negative weights in O(V ร E) and detects negative cycles. Prim's and Kruskal's build minimum spanning trees. These appear in FAANG system design and hard LC problems.
- โShortest path in a weighted graph โ Dijkstra (non-negative weights)
- โShortest path with negative weights โ Bellman-Ford
- โMinimum cost to connect all nodes โ Prim's or Kruskal's (MST)
- โCheapest flights, network delay, city routing problems
- โFloyd-Warshall for all-pairs shortest path
What data structure does Dijkstra's algorithm use to always process the nearest node?
When should you use Bellman-Ford instead of Dijkstra?
In Kruskal's MST algorithm, what prevents adding an edge that creates a cycle?
Check each question you can answer confidently before moving to the next topic.