Kruskal vs Prim
Warm-up · Multiple choice · about 3 min
A network has 2,000 sites and a cable price for almost every pair, about 2 million edges, stored as a 2,000 × 2,000 matrix. Which approach fits best?
Example 1
Input:
{"V":2000,"E":2000000}
Output:
Prim with an array of keys
V² is 4 million steps; sorting 2 million edges costs about 42 million.
Learn the idea first: Prim's algorithm, a visual lesson.
More Prim's algorithm problems
- Prim order Warm-up
- Implement Prim Standard
- Supply water to every house Standard
- Cost of the array version Standard
- MST on a dense matrix graph Challenge