Software Engineer (SDE)dsaadvanced3 interactive MCQs in app
Shortest Path: Dijkstra & Bellman-Ford
Dijkstra min-heap + stale entry guard on non-negative weightsBellman-Ford O(VE) for negative weightswhy negative edges break Dijkstra greedy settle
Core Concept
Dijkstra’s algorithm finds single-source shortest paths on **non-negative weighted** graphs in `O((V + E) log V)` using a min-heap `(dist, node)`. Always check stale heap entries: `if d > dist[u]: continue`! When weights can be **NEGATIVE** (no negative cycles), use Bellman-Ford relaxing all `E` edges `V - 1` times in `O(V * E)`.
Worked Example
from `A` with edges `A->B(4), A->C(1), C->B(2)`, Dijkstra pops `(1, C)` before `(4, B)` and relaxes `dist[B]` down to `1 + 2 = 3` cleanly!
Common Pitfall
running Dijkstra on negative edge weights (greedy pop assumes settled `dist[u]` can never drop later, which negative edges break!) or forgetting stale heap skip.
Recommended Readings & Practice
Practice Shortest Path: Dijkstra & Bellman-Ford with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.