Graphs & Connectivity Hard
Time-Constrained BFS
Breadth-first search finds the fewest one-year jumps while checking each bypass is still open on arrival.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(V²)
AverageO(V²)
WorstO(V²)
SpaceO(V)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
A bypass from i to j works only when its positive expiration year is greater than the number of years already traveled.
- Treating every listed bypass as permanently open.
- Allowing a bypass whose expiry equals the arrival year.
- Using weighted shortest path when each crossing costs one year.
Algorithm code
JavaGalaxyPath.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1