Order the steps
Put Kruskal's algorithm in order.
- Give every office its own group
- Sort all cables by cost
- Stop after n - 1 cables, or report -1 if you run out first
- For each cable, take it if its two offices are in different groups, and join the groups
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B A D C
- Sort all cables by cost Cheap cables are considered first.
- Give every office its own group Union-find starts with n separate groups.
- For each cable, take it if its two offices are in different groups, and join the groups Cables inside a group would only make a loop.
- Stop after n - 1 cables, or report -1 if you run out first A tree on n offices has n - 1 edges.