MST-Kruskal( G, w ). 1. A // initially A is empty 2. for each vertex v V [ G ] // line 2-3 takes O ( V ) time 3. do Create-Set( v ) // create set for each vertex 4. sort the edges of E by nondecreasing weight w
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
1. A // initially A is empty
2. for each vertex v V[G] // line 2-3 takesO(V) time
3. do Create-Set(v)// create set for each vertex
4. sort the edges of E by nondecreasing weight w
5. for each edge (u,v) E, in order bynondecreasing weight
6. do if Find-Set(u) Find-Set(v) // u&v on different trees
7. then A A {(u,v)}
8. Union(u,v)
9. return A
Total running time is O(E lg E).
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
1. Q V[G]
2. for each vertex u Q// initialization: O(V) time
3. do key[u]
4. key[r] 0// start at the root
5.[r] NIL// set parent of r to be NIL
6. while Q // until all vertices in MST
7. do u Extract-Min(Q) // vertex with lightest edge
8. for each v adj[u]
9. do if v Qand w(u,v) < key[v]
10. then [v] u
11. key[v] w(u,v) // new lighter edge out of v
12. decrease_Key(Q, v, key[v])
Lin/Foskey/Manocha
T(n) = uV(lg n + deg(u)lg n) = uV (1+ deg(u))lg n
= lg n (n + 2e) = O((n + e)lg n)
Essentially same as Kruskal’s: O((n+e) lg n) time
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha
Lin/Foskey/Manocha