11-28 notes - Alg and Data Structures(LAB 4B Dijktras...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
11/28/11 Alg and Data Structures (LAB 4B) Dijktra’s Algorithm Assumes all weights w(u,v) 0 Use min-first priority queue Q of vertices Key is estimated distance from s to each vertex Given G=(v,E), starting s Dijkstra(G,S) o //init o S.distance O o S. parent null o Q.insert (0,S) o For each u € V-S{ u.distance INF u.parent null Q.insert(INF,u) o } o While Q is not empty{ U Q.extractMin() If u.distance = INF, STOP For each v € Adj[u]{ If(Q.decreaseKey(v, w(u,v)+u.distance)) o V.distance u.distance + w(u,v) o V.parent u } } o } Efficiency o Init: one insert per vertex o Outer Loop: one extractMin per vertex o Inner Loop: one decreaseKey per edge o n = |v|, m = |E| o T(n,m) = n.T insert (n,m) + n.T extractMin (n,m) + m.T decreaseKey (n,m) o Binary Heap: all 3 ops are O(log n) T(n,m) = O(m log n) o Fibonacci Heap Insert – O(1)
Background image of page 1

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

View Full Document Right Arrow Icon
ExtractMin – O(log n) DecreaseKey – O(1) T(n,m) = O(n log n + m)
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

11-28 notes - Alg and Data Structures(LAB 4B Dijktras...

This preview shows document pages 1 - 2. Sign up to view the full document.

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