AlgoFrames

Relaxation table

Warm-up · Trace the algorithm · about 5 min

Follow Dijkstra from node 0. After each node is settled, type the distance that the next relaxation writes into the distance table.

Example 1

Input:

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

Output:

[0,5,2,6,8]

Final distances from 0 are 0, 5, 2, 6, 8.

Constraints

  • Edge weights are non-negative.
  • Edges leave a node in the order they are listed.

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

More Dijkstra's algorithm problems