AlgoScope

0-1 BFS

AlgorithmadvancedShortest Path

A deque replaces the heap when weights are 0 or 1: a 0 edge pushes to the front, a 1 edge to the back.

Decision · step 3 of 22Shortest Paths: 0-1 BFS with a deque
101011000112345u

Edge 0 to 1 weighs 1: 0 + 1 = 1 against 1's current infinity. Shorter, so 1 becomes 1 and joins the back of the deque: one step further than 0. Deque now 1.

Open in the player →or start at step 3

What you will see

The deque beside the graph; zero-weight neighbours jump the line.

How shortest paths works →

Cost

BestO(V + E)
AverageO(V + E)
WorstO(V + E)
SpaceO(V)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Vertices announce name, tentative distance and parent; each step announces the relaxation and whether it improved a distance.

Reduced motion: Distance updates change the label with a crossfade instead of radiating from the edge.

Related

Taught by the same lesson

Shortest Paths covers these too, in the same run.