U lgetvalue for all e uincidentedges z eopposite u r

Info iconThis preview shows pages 12–17. Sign up to view the full content.

View Full Document Right Arrow Icon
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 )
Background image of page 12

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 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
Background image of page 13
© 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
Background image of page 14

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 15 Analysis Graph operations Method incidentEdges is called once for each vertex Label operations We set/get the distance, parent and locator labels of vertex  z   O (deg( z ))   times Setting/getting a label takes  O (1)  time Priority queue operations Each vertex is inserted once into and removed once from the priority  queue, where each insertion or removal takes  O (log n ) time The key of a vertex  w  in the priority queue is modified at most  deg( w ) times, where each key change takes  O (log n ) time  Prim-Jarnik’s algorithm runs in  O (( n + m ) log n )  time provided the  graph is represented by the adjacency list structure Recall that  Σ v deg( v ) = 2 m The running time is  O ( m log n )  since the graph is connected
Background image of page 15
© 2010 Goodrich, Tamassia Minimum Spanning Trees 16 Baruvka’s Algorithm (Exercise) Like Kruskal’s Algorithm, Baruvka’s algorithm grows many  clusters at once and maintains a forest  T Each iteration of the while loop halves the number of connected  components in forest  T The running time is  O ( m log n ) Algorithm BaruvkaMST ( G ) T V {just the vertices of G } while T has fewer than n - 1 edges do for each connected component C in T do Let edge e be the smallest-weight edge from C to another component in T if e is not already in T then Add edge e to T return T
Background image of page 16

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

View Full Document Right Arrow Icon
© 2010 Goodrich, Tamassia Example of Baruvka’s  Algorithm (animated) CSC 316 17 1 5 4 3 2 3 4 4 9 6 8 7 6 5 4 9 6 8 Slide by Matt Stallmann  included with permission. Slide by Matt Stallmann  included with permission. 1 5 4 3 2 3 4 4 9 6 8 7 6 5
Background image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page12 / 17

u lgetValue for all e uincidentEdges z eopposite u r...

This preview shows document pages 12 - 17. Sign up to view the full document.

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