Dijkstra's Shortest Paths
Step by Step
Settle the nearest unsettled node first, and with no negative edges no route found later can beat it.
Move forward and back at your own pace, then share a link to the step where you got stuck.
What You Watch While Distances Settle
Distances change on every step, and the visualiser tracks them for you.
Settling the nearest node first works because no edge is negative, so no later route can beat it. That logic sounds clean and gets hard to follow once distances start changing on step nine.
CodeStory's visualiser shows the frontier spreading and marks which nodes are settled for good. Code lines light up beside the graph as they execute. Move forward, move back or let the algorithm play.
Try a graph with a longer cheap route, a node you cannot reach and two routes of equal cost. Edge cases like these decide interview answers.
How Dijkstra Finds the Shortest Path
Steps below match the picture, so you can follow them beside the drawing.
- 1Give the source distance 0 and every other node an infinite distance.
- 2Take the unsettled node with the smallest distance from the frontier.
- 3Check every neighbour and update its distance when the route through this node is shorter.
- 4Mark the node settled, because no later route can beat it.
- 5Repeat until every reachable node is settled.
Dijkstra Cost in Time and Space
Interviewers ask about time and space, so the visualiser counts both live.
- Time
- O((V + E) log V)measured as real operations on your graph, not copied from a table
- Space
- O(V + E)extra memory for distances and the frontier
- Pattern
- GraphsEdge weights decide the order, not the number of edges.
From Watching to Solving
Watching shows the idea and solving makes it yours.
Everything in the App in One Place
Practice, interviews and tools all start free. Swipe to see the rest.
DSA practice
Problems filed under the pattern that solves them, not a sheet.
352 problemsOpenCompany sets
Practise what one company asks in the week before your round.
463 companiesOpenCoding interview
Choose a role, write in a real editor and answer while you type.
scored reportOpenMock interviews, spoken
You answer out loud and CodeStory follows up on what you said.
32 topicsOpenDatabase round
Answer DBMS the way a panel asks it, with indexes, joins and normal forms.
in Core CSOpenOOP round
Inheritance, polymorphism and the follow-up you never rehearse.
in Core CSOpenSystem design
How real systems are built, from the primitives to the AI stack.
27 chaptersOpenSQL practice
Real schemas, your query, the rows it returns and a clear verdict.
39 questionsOpenAptitude
Quant, logical, verbal, DI and technical, timed like the real test.
280 questionsOpenOnline assessment
Get a clock, marks per question and hidden tests like a company's judge.
37 papersOpenAlgorithm visualiser
Watch it play on your own input, one step at a time.
26 algorithmsOpenAI that helps, not solves
Hints one at a time and AI review before a mentor sees your work.
100 free creditsOpenResume builder
Build it inside the app, next to the work you practised.
in the appOpenProgress and readiness
One score and the axis where you are weakest.
tracked dailyOpen
Sign up for 100 AI credits now and get 100 more every month. Start free in the app
Dijkstra Visualiser FAQs
Open the visualiser and watch the answers play out.
Open the visualiserWhat does the Dijkstra visualiser show?
CodeStory's visualiser shows the frontier spreading and marks which nodes are settled for good, on a graph you choose. It highlights the line of code being executed, and you can step forward, step back or let it play.
What is the time complexity of Dijkstra's algorithm?
Dijkstra's algorithm takes O((V + E) log V) time and O(V + E) space. CodeStory's visualiser counts real operations as it plays, so you watch the number grow instead of trusting the formula.
Why does Dijkstra fail with negative edges?
Dijkstra settles the nearest node first, which is only safe when no edge is negative. Negative edges can make a later route cheaper than a node you already settled.
What is a settled node?
Settled nodes have their final shortest distance, so no later route can beat them.
Can I use my own input?
Yes. Type your own graph and the visualiser plays Dijkstra's algorithm on it, edge cases included.
Is the visualiser free?
Yes. You start free with 100 AI credits when you sign up and 100 every month, and watching an algorithm costs no credits.
Stuck on Graphs? Get a Free Callback
Tell CodeStory where graphs lose you, and a mentor plans your next steps.
- 1CodeStory finds your starting point, from your first edge to interview ready.
- 2CodeStory explains online and campus batches, with timings for your mornings or evenings.
- 3You decide. No pressure, no payment on the call.