AlgoFrames

MST edges in order

Warm-up · Trace the algorithm · about 5 min

Run Kruskal on this graph. First click the edge it looks at right after B-D. Then put the edges of the MST in the order Kruskal adds them.

Example 1

Input:

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

Output:

["C-D","A-C","B-D","C-E"]

The MST weighs 1 + 2 + 3 + 6 = 12.

Constraints

  • Edge weights are all different.

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

More Kruskal's algorithm problems