In operation union ab we move the elements of the

Info iconThis preview shows pages 9–13. Sign up to view the full content.

View Full Document Right Arrow Icon
in operation  union (A,B), we move the elements of the  smaller set to the sequence of the larger set and update  their references the time for operation  union (A,B) is min(|A|, |B|) Whenever an element is processed, it goes into a  set of size at least double, hence each element is  processed at most log n times
Background image of page 9

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

View Full Document Right Arrow Icon
© 2010 Goodrich, Tamassia Partition-Based Implementation Partition-based  version of  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
Background image of page 10
© 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  
Background image of page 11

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

View Full Document Right Arrow Icon
© 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
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page9 / 17

in operation union AB we move the elements of the smaller...

This preview shows document pages 9 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online