Dijkstra - a. distance check for a given vertex updated is...

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

View Full Document Right Arrow Icon
Dijkstra’s Shortest Path Shorted paths from x to y in a weighted graph (positive weights, undirected or directed) Step 0 For each neighbor, w, of source d(w) = wt(source, w) Step 1 While fringe not empty v - min distance vertex in fringe for each neighbor, w, of v if d(w) > d(v) + wt(v, w) d(w) = d(v) + wt(v, w) if w is not in fringe, add to fringe “Done” D[B] D[C] D[D] D[E] D[F] D[G] A 5 10 B 10 11 8 E 10 10 10 C 10 10 D 16 10 G 12 F when the vertex reaches the “done”, there is no shorter path “fringe” - all vertices that are NOT done with non-infinity distances i.e. [5, 10] was a fringe, then after updating B, [10, 11, 8] is the new fringe “Induced” shortest path tree store this in a file the first time the algorithm is run from some source (find paths to all vertices) subsequent graphs with same source, can be answered by retracing answer from pile Storage structures 1. Graph (n+e) in adj linked lists 2. Array length n for distances
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a. distance check for a given vertex updated is O(1) 3. array length n for previous vertex 4. Fringe: WHAT STRUCTURE? 5. stack to determine path Worst case analysis of running time things to count toward running time 1. add (A) vertex to fringe 2. pick (P) minimum distance vertex from fringe 3. check (C) neighbors for distance 4. update (U) neighbors distance version 1: fringe is an unsorted linked list -- O(n 2 ) A: all vertices added to fringe in O(n) [each is added to front, O(1)] P: O(n 2 ) best case: A - B - C - D -E worst case: 1. start with n-1 vertices in fringe 2. each pick gets last in LL (n-1)+(n-2)++1 = O(n 2 ) C: how many distance checks? e -- each check is O(1) time since distance are in array, indexable by vertex number. overall, O(e) U: worst possible number is e - every check results in update: O(e) [each update O(1), just like check]...
View Full Document

This note was uploaded on 03/29/2012 for the course CS 112 taught by Professor Sesh during the Spring '07 term at Rutgers.

Page1 / 2

Dijkstra - a. distance check for a given vertex updated is...

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