Presentation is loading. Please wait.

Presentation is loading. Please wait.

By Amber McKenzie and Laura Boccanfuso. Dijkstra’s Algorithm Question: How do you know that Dijkstra’s algorithm finds the shortest path and is optimal.

Similar presentations


Presentation on theme: "By Amber McKenzie and Laura Boccanfuso. Dijkstra’s Algorithm Question: How do you know that Dijkstra’s algorithm finds the shortest path and is optimal."— Presentation transcript:

1 by Amber McKenzie and Laura Boccanfuso

2 Dijkstra’s Algorithm Question: How do you know that Dijkstra’s algorithm finds the shortest path and is optimal when implemented with the Fibonacci heap?

3 Single-Source Shortest Path  For a given vertex, determine the shortest path between that vertex and every other vertex, i.e. minimum spanning tree.

4 Premise of Dijkstra’s Algorithm  First, finds the shortest path from the vertex to the nearest vertex.  Then, finds the shortest path to the next nearest vertex, and so on.  These vertices, for which the shortest paths have been found, form a subtree.  Thus, the next nearest vertex must be among the vertices that are adjacent to those in the subtree; these next nearest vertices are called fringe vertices.

5 Premise cont.  The fringe vertices are maintained in a priority queue which is updated with new distances from the source vertex at every iteration.  A vertex is removed from the priority queue when it is the vertex with the shortest distance from the source vertex of those fringe vertices that are left.

6 Pseudocode for every vertex v in V do d v ← ∞; p v ← null Insert(Q, v, d v ) //initialize vertex priority in the priority queue d s ← 0; Decrease(Q, s, d s ) //update priority of s with d s V T ← Ø for i ← 0 to |V| - 1 do u* ← DeleteMin(Q) //delete the minimum priority element V T ← V t U {u*} for every vertex u in V – V T that is adjacent to u* do if d u* + w(u*, u) < d u d u ← d u* + w(u*, u); p u ← u* Decrease(Q, u, d u )

7 Dijkstra’s Algorithm a d c b f e 2 3 7 5 8 2 1 6 4

8 a d c b f e 2 5 8 a(-, 0) Tree verticesRemaining vertices b(a, 2) c(a, 5) d(a, 8) e(-, ∞) f(-, ∞)

9 Dijkstra’s Algorithm a d c b f e 2 5 8 2 6 b(a, 2) Tree verticesRemaining vertices c(b, 2+2) d(a, 8) e(-, ∞ ) f(b, 2+6)

10 Dijkstra’s Algorithm a d c b f e 2 3 5 8 2 1 6 c(b, 4) Tree verticesRemaining vertices d(a, 8) e(c, 4+1) f(b, 8)

11 Dijkstra’s Algorithm a d c b f e 2 3 7 5 8 2 1 6 4 e(c, 5) Tree verticesRemaining vertices d(a, 8) f(b, 8)

12 Dijkstra’s Algorithm a d c b f e 2 3 7 5 8 2 1 6 4 d(a, 8) Tree verticesRemaining vertices f(b, 8)

13 Dijkstra’s Algorithm a d c b f e 2 8 2 1 6

14 Dijkstra’s Algorithm: Priority Queue Tree verticesRemaining vertices a(-, 0)b(a, 2) c(a, 5) d(a, 8) e(-, ∞) f(-, ∞) b(a, 2)c(b, 2+2) d(a, 8) e(-, ∞ ) f(b, 2+6) c(b, 4)d(a, 8) e(c, 4+1) f(b, 8) e(c, 5)d(a, 8) f(b, 8) d(a, 8)f(b, 8) f(b, 8)

15 Fibonacci Heap Implementation  Manipulation of heap/queue  Time complexity efficiency What makes the Fibonacci Heap optimally suited for implementing the Dijkstra algorithm? http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbitswww.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbits

16 Fibonacci Heap Implementation Manipulation of heap/queue  Insert operation: creates a new heap with one element then performs a merge  Merge operation: concatenate the lists of tree roots of the two heaps  Decrease_key: take the node, decrease the key and reorder nodes if necessary, mark node or cut (if smaller than parent)  Delete_min: take root of min element and remove; decrease number of roots by linking together ones with same degree, check each remaining node to find minimum and delete 4 7 2 9 5

17 Fibonacci Heap Implementation OperationUSDL List* 2-3 tree HeapBinomialFibonacci make O (1) empty O( 1 ) insert O( 1 )O( logn ) O( 1 ) find_min O( n )O( logn )O (1) O( logn )O( 1 ) delete_min O( n )O( logn ) delete O( 1 )O( logn ) merge O( 1 )O(n) O( logn )O( 1 ) decrease_key O( 1 )O( logn ) O( 1 ) * USDL list: Unsorted Doubly Linked list Time Complexity Efficiency

18 Worst-case complexity  Formula to discover the worst-case complexity for Dijkstra’s algorithm: W(n,m) = O(n * cost of insert + n * cost of delete_min + m * cost of decrease_key) (Where n = maximum size of priority queue m = number of times inner loop is performed)

19 Worst-case complexity (cont.)  Unsorted linked list: W(n,m) = O(n* 1 + n * n + m * 1) = O(n 2 )  2-3 Tree : W(n,m) = O(n * logn + n * logn + m * logn) = O(mlogn)  Fibonacci Heap: W(n,m) = O(n * 1 + n * logn + m * 1) = O(nlogn + m)

20 Optimality of Dijkstra’s Algorithm  Adversary argument  In this case, it is the argument that there exists a path between the source vertex s and the target vertex t that is shorter than the path already determined by the algorithm. st

21 Adversary Argument  Since we have already determined the shortest paths to all the previous vertices that are now in the tree, this must mean that the path from s to t goes through some other vertex v whose distance from s has yet to be determined (meaning it is still in the priority queue). st v

22 Adversary Argument Cont.  The catch is that if this other vertex v through which t passes is still in the priority queue, then its distance to s is longer than that of all other vertices already in the tree.  Thus it cannot be a shorter distance than that which is already determined between s and t. st v

23 References  “ Algorithms and Data Structures Design, Correctness and Analysis” Jeffrey H. Kingston  “ A Result on the Computational Complexity of Heuristic Estimates for the A* Algorithm” Marco Valtorta  “ The Design & Analysis of Algorithms” Anany Levitin  Animation http://www.cs.auckland.ac.nz/software/AlgAnim/dijkstra.html#dijkstra_animwww.cs.auckland.ac.nz/software/AlgAnim/dijkstra.html#dijkstra_anim


Download ppt "By Amber McKenzie and Laura Boccanfuso. Dijkstra’s Algorithm Question: How do you know that Dijkstra’s algorithm finds the shortest path and is optimal."

Similar presentations


Ads by Google