AlgoFrames

Which node is settled next?

Standard · Trace the algorithm · about 6 min

Follow Dijkstra from node 0. Each time the queue is about to be popped, click the node that gets settled next.

Example 1

Input:

{"edges":[[0,1,2],[0,2,6],[1,2,3],[1,3,5],[2,3,1],[3,4,4],[2,5,9]],"source":0}

Output:

[0,1,2,3,4,5]

Nodes settle in order of final distance.

Constraints

  • Edge weights are non-negative.

Learn the idea first: Dijkstra's algorithm, a visual lesson.

More Dijkstra's algorithm problems