23. MST-outside

Kruskals algorithm cluster merges as unions cluster

• Notes
• 17

This preview shows pages 10–16. Sign up to view the full content.

Kruskal’s  Algorithm  Cluster merges  as unions  Cluster locations  as finds Running time  O (( n + m ) log n ) PQ operations  O ( m log n ) UF operations  O ( n log n ) Minimum Spanning Trees 10 Algorithm KruskalMST ( G ) Initialize a partition P for each vertex v in G do P.makeSet ( v ) let Q be a priority queue. Insert all edges into Q T { T is the union of the MSTs of the clusters} while T has fewer than n - 1 edges do e Q.removeMin () .getValue () [ u , v ] G.endVertices ( e ) A P.find ( u ) B P.find ( v ) if A B then Add edge e to T P.union ( A, B ) return T

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Minimum Spanning Trees 11 Prim-Jarnik’s Algorithm Similar to Dijkstra’s algorithm We pick an arbitrary vertex  s  and we grow the MST as  a cloud of vertices, starting from  s We store with each vertex  v  label  d ( v )  representing the  smallest weight of an edge connecting  v to a vertex in  the cloud  At each step: We add to the cloud the vertex  u  outside the cloud with the  smallest distance label We update the labels of the vertices adjacent to  u
©  2010 Goodrich, Tamassia Minimum Spanning Trees 12 Prim-Jarnik’s Algorithm (cont.) A heap-based adaptable  priority queue with  location-aware entries  stores the vertices  outside the cloud Key: distance Value: vertex Recall that method  replaceKey ( l,k )  changes  the key of entry  l We store three labels  with each vertex: Distance Parent edge in MST Entry in priority queue Algorithm PrimJarnikMST ( G ) Q new heap-based priority queue s a vertex of G for all v G.vertices () if v = s v.setDistance (0) else v.setDistance ( ) v.setParent ( ) l Q.insert ( v.getDistance () , v ) v.setLocator ( l ) while ¬ Q.empty () l Q.removeMin () u l.getValue () for all e u.incidentEdges () z e.opposite ( u ) r e.weight () if r < z.getDistance () z.setDistance ( r ) z.setParent ( e ) Q.replaceKey ( z.getEntry () , r )

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Minimum Spanning Trees 13 Example B D C A F E 7 4 2 8 5 7 3 9 8 0 7 2 8 B D C A F E 7 4 2 8 5 7 3 9 8 0 7 2 5 7 B D C A F E 7 4 2 8 5 7 3 9 8 0 7 2 5 7 B D C A F E 7 4 2 8 5 7 3 9 8 0 7 2 5 4 7
©  2010 Goodrich, Tamassia Minimum Spanning Trees 14 Example (contd.) B D C A F E 7 4 2 8 5 7 3 9 8 0 3 2 5 4 7 B D C A F E 7 4 2 8 5 7 3 9 8 0 3 2 5 4 7

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Minimum Spanning Trees 15 Analysis Graph operations
This is the end of the preview. Sign up to access the rest of the document.
• Fall '09
• Vertex, Tamassia, Minimum Spanning Trees

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern