Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Cheapest Route

Learn
Play
Prove
Problem context and objectives
Mission briefing

Realm network architect · Routes have costs, dependencies, and unreliable bridges

Choose the next frontier that preserves the route guarantee: The Cheapest Route.

One locally tempting edge can invalidate the whole journey.

How you win

  1. 1Recognize when Dijkstra shortest path matches the clues
  2. 2Keep this true after every move: every settled node has its final shortest distance
  3. 3Reach the result within O((V + E) log V)

Rules and pressure

  • Target cost: O((V + E) log V)
  • State rule: every settled node has its final shortest distance
Lesson 1 of 3

Live algorithm trace

Dijkstra shortest path

Complete execution
1 of 7
0
current
1
2

Only the start node has a known distance, zero.

1dist[start] = 0
2pop smallest distance
3relax outgoing edges
4return dist[end]
start = 0end = 1dist = [0, ∞, ∞]heap = [(0, 0)]
Truth to preserve / Cost target
Truth to preserve

every settled node has its final shortest distance

Cost target

O((V + E) log V)

Dijkstra always expands the unsettled node with the smallest known distance. Nonnegative edges guarantee that this distance can no longer improve.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead