The short answer
What is the order of Kruskal’s algorithm? It is O(E log E), where E is the number of edges. For a simple graph this is usually written O(E log V), where V is the number of vertices. The two forms are equivalent in Big O notation for simple graphs with no isolated vertices.
What “order” means here
“Order” refers to Big O notation, which describes how running time grows as the graph gets larger. It does not give an exact time in seconds. It gives a growth rate, so you can compare methods on large inputs.
The steps
- Sort all E edges by weight.
- Treat each vertex as its own tree. This takes O(V) time.
- Go through the sorted edges in order. For each edge, check whether its two endpoints are in different trees. If they are, merge the two trees. If not, skip the edge.
- Stop once V − 1 edges have been added.
Where the time goes
Sorting is the expensive step. A standard comparison sort, such as merge sort, takes O(E log E) time on E edges, and that dominates the total. The main loop looks at each edge once, and its union-find checks are cheap.
Union-find cost
The checks and merges use a disjoint-set structure. With union by rank and path compression, each operation takes amortized time measured by the inverse Ackermann function, written α. That function grows so slowly that it is effectively constant for any input size you could store. The edge loop therefore costs about O(E α(E, V)), which is much smaller than the sort. That is why sorting sets the overall order.
Putting it together
- Sorting: O(E log E)
- Edge loop with union-find: O(E α(E, V)), effectively O(E)
- Total: O(E log E), usually written O(E log V)
If the edges are already sorted, the sorting step disappears, and the total drops to O(E α(E, V)).
Tracing the order on an example
Take a graph with five vertices and seven edges: A–B 1, B–C 2, C–D 3, A–C 4, B–D 5, C–E 6, and D–E 7. Kruskal’s sorts the seven edges, then adds A–B, B–C, and C–D. It skips A–C and B–D, since each would close a cycle. It adds C–E, which is the fourth edge and completes the tree, so it stops there. D–E is never examined.
Space
The algorithm stores the edge list, which takes O(E) space, and the union-find arrays, which take O(V) space. Total space is O(V + E), not counting any extra working space the sort may use.
Compared with Prim’s
Prim’s running time depends on its data structure. It is O(V²) with an adjacency matrix, O(E log V) with a binary heap, and O(E + V log V) with a Fibonacci heap. On dense graphs, the matrix version can be a better match, because E is close to V² and Kruskal’s sort then costs roughly V² log V. On sparse graphs, the two are usually comparable.