Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Efficient shortest path algorithm for graphs where edge weights are only 0 or 1. By using a Double-Ended Queue (Deque), it achieves linear complexity O(V + E), bypassing the overhead of a Priority Queue.
Weight 0 edges are unshifted to the front, while weight 1 edges are pushed to the back. This maintains the sorted order naturally.
If all weights are the same, BFS works. If they are 0/1, we can still avoid Dijkstra's sorting by prioritizing 0-weight "free" moves.