8/10/2019 Boc Can Mckenzie 080910
1/23
DIJKSTRASALGORITHMFibonacci Heap Implementation
by Amber McKenzieand Laura Boccanfuso
8/10/2019 Boc Can Mckenzie 080910
2/23
DijkstrasAlgorithm
Question: How do you know that Dijkstras
algorithm finds the shortest path and isoptimal when implemented with theFibonacci heap?
8/10/2019 Boc Can Mckenzie 080910
3/23
Single-Source Shortest Path
For a given vertex, determine the shortest
path between that vertex and every other
vertex, i.e. minimum spanning tree.
8/10/2019 Boc Can Mckenzie 080910
4/23
Premise of DijkstrasAlgorithm
First, finds the shortest path from the vertex to
the nearest vertex.
Then, finds the shortest path to the nextnearest 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.
8/10/2019 Boc Can Mckenzie 080910
5/23
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 thosefringe vertices that are left.
8/10/2019 Boc Can Mckenzie 080910
6/23
Pseudocode
for every vertex vin Vdo
dv ;pv null
Insert(Q, v, dv) //initialize vertex priority in the priority queue
ds 0; Decrease(Q, s, ds) //update priority of s with ds
VT
for i 0 to |V| - 1 do
u* DeleteMin(Q) //delete the minimum priority element
VT Vt U {u*}
for every vertex uin VVT that is adjacent to u*do
if du*+ w(u*, u) < du
du du* + w(u*, u); pu u*
Decrease(Q, u, du)
8/10/2019 Boc Can Mckenzie 080910
7/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
3
7
5
8
2
1
6
4
8/10/2019 Boc Can Mckenzie 080910
8/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
5
8
a(-, 0)
Tree vertices Remaining vertices
b(a, 2) c(a, 5) d(a, 8) e(-, ) f(-, )
8/10/2019 Boc Can Mckenzie 080910
9/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
5
8
26
b(a, 2)
Tree vertices Remaining vertices
c(b, 2+2) d(a, 8) e(-, ) f(b, 2+6)
8/10/2019 Boc Can Mckenzie 080910
10/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
3
5
8
2
1
6
c(b, 4)
Tree vertices Remaining vertices
d(a, 8) e(c, 4+1) f(b, 8)
8/10/2019 Boc Can Mckenzie 080910
11/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
3
7
5
8
2
1
6
4
e(c, 5)
Tree vertices Remaining vertices
d(a, 8) f(b, 8)
8/10/2019 Boc Can Mckenzie 080910
12/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
3
7
5
8
2
1
6
4
d(a, 8)
Tree vertices Remaining vertices
f(b, 8)
8/10/2019 Boc Can Mckenzie 080910
13/23
DijkstrasAlgorithm
a
d
c
b
f
e
2
8
2
1
6
8/10/2019 Boc Can Mckenzie 080910
14/23
DijkstrasAlgorithm: Priority Queue
Tree vertices Remaining 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)
8/10/2019 Boc Can Mckenzie 080910
15/23
Fibonacci Heap Implementation
Manipulation of heap/queue
Time complexity efficiency
What makes the Fibonacci Heap optimally suitedfor implementing the Dijkstra algorithm?
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbits
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.htmlhttp://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html8/10/2019 Boc Can Mckenzie 080910
16/23
Fibonacci Heap Implementation
Manipulation of heap/queue
Insert operation: creates a new heap with one element thenperforms 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 nodeor 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
8/10/2019 Boc Can Mckenzie 080910
17/23
Fibonacci Heap Implementation
Operation USDL
List*
2-3 tree Heap Binomial Fibonacci
make O(1) O(1) O(1) O(1) O(1)
empty O(1) O(1) O(1) O(1) O(1)
insert O(1) O(logn) O(logn) O(logn) O(1)
find_min O(n) O(logn) O(1) O(logn) O(1)
delete_min O(n) O(logn) O(logn) O(logn) O(logn)
delete O(1) O(logn) O(logn) O(logn) O(logn)
merge O(1) O(n) O(n) O(logn) O(1)
decrease_key O(1) O(logn) O(logn) O(logn) O(1)
* USDL list: Unsorted Doubly Linked list
Time Complexity Efficiency
8/10/2019 Boc Can Mckenzie 080910
18/23
Worst-case complexity
Formula to discover the worst-case complexity forDijkstras 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)
8/10/2019 Boc Can Mckenzie 080910
19/23
Worst-case complexity (cont.)
Unsorted linked list:
W(n,m) = O(n* 1 + n * n + m * 1) = O(n2)
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)
8/10/2019 Boc Can Mckenzie 080910
20/23
Optimality of DijkstrasAlgorithm
Adversary argument
In this case, it is the argument that there exists a
path between the source vertex sand the target
vertex tthat is shorter than the path alreadydetermined by the algorithm.
s t
8/10/2019 Boc Can Mckenzie 080910
21/23
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 tgoes through some other vertex vwhosedistance from shas yet to be determined
(meaning it is still in the priority queue).
s tv
8/10/2019 Boc Can Mckenzie 080910
22/23
Adversary Argument Cont.
The catch is that if this other vertex v
through which tpasses is still in the priority
queue, then its distance to sis 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.s tv
8/10/2019 Boc Can Mckenzie 080910
23/23
References
Algorithms and Data StructuresDesign, 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
Animationhttp://www.cs.auckland.ac.nz/software/AlgAnim/dijkstra.html#dijkstra_anim
http://www.cs.auckland.ac.nz/software/AlgAnim/dijkstra.htmlhttp://www.cs.auckland.ac.nz/software/AlgAnim/dijkstra.htmlTop Related