Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Kruskal's algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Complexity == For a graph with {{mvar|E}} edges and {{mvar|V}} vertices, Kruskal's algorithm can be shown to run in time {{math|''O''(''E'' log ''E'')}} time, with simple data structures. This time bound is often written instead as {{math|''O''(''E'' log ''V'')}}, which is equivalent for graphs with no isolated vertices, because for these graphs {{math|''V''/2 β€ ''E'' < ''V''<sup>2</sup>}} and the logarithms of {{mvar|V}} and {{mvar|E}} are again within a constant factor of each other. To achieve this bound, first sort the edges by weight using a [[comparison sort]] in {{math|''O''(''E'' log ''E'')}} time. Once sorted, it is possible to loop through the edges in sorted order in constant time per edge. Next, use a [[disjoint-set data structure]], with a set of vertices for each component, to keep track of which vertices are in which components. Creating this structure, with a separate set for each vertex, takes {{mvar|V}} operations and {{math|''O''(''V'')}} time. The final iteration through all edges performs two find operations and possibly one union operation per edge. These operations take [[amortized time]] {{math|''O''(''Ξ±''(''V''))}} time per operation, giving worst-case total time {{math|''O''(''E'' ''Ξ±''(''V''))}} for this loop, where {{mvar|Ξ±}} is the extremely slowly growing [[inverse Ackermann function]]. This part of the time bound is much smaller than the time for the sorting step, so the total time for the algorithm can be simplified to the time for the sorting step. In cases where the edges are already sorted, or where they have small enough integer weight to allow [[integer sorting]] algorithms such as [[counting sort]] or [[radix sort]] to sort them in linear time, the disjoint set operations are the slowest remaining part of the algorithm and the total time is {{math|''O''(''E'' ''Ξ±''(''V''))}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)