Time and Space Complexity
Lesson 7 of 9 in Coddy's Kruskal's Algorithm - Graph Algorithms course.
Time Complexity:
- Sorting the E edges is O(E log E); each union-find operation is nearly O(1) with path compression, so classic Kruskal is O(E log E). The min-selection version we build here is O(E2), which is fine for small graphs.
Space Complexity:
- O(V) for the parent array (plus the input edges).
Summary:
- Kruskal grows an MST by adding the cheapest cycle-free edge at each step, using union-find to test for cycles.
- All MSTs share the same total weight, so the answer is unique.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Kruskal's Algorithm - Graph Algorithms
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)