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!
==Pseudocode== The following code is implemented with a [[disjoint-set data structure]]. It represents the forest ''F'' as a set of undirected edges, and uses the disjoint-set data structure to efficiently determine whether two vertices are part of the same tree. '''function''' Kruskal(''Graph G'') '''is''' F:= β '''for each''' v '''in''' G.Vertices '''do''' MAKE-SET(v) '''for each''' {u, v} '''in''' G.Edges ordered by increasing weight({u, v}) '''do''' '''if''' FIND-SET(u) β FIND-SET(v) '''then''' F := F βͺ { {u, v} } UNION(FIND-SET(u), FIND-SET(v)) '''return''' F
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)