Dijkstra'S Algorithm: Fibonacci Heap Implementation
Dijkstra'S Algorithm: Fibonacci Heap Implementation
Dijkstra'S Algorithm: Fibonacci Heap Implementation
DIJKSTRAS ALGORITHM
Fibonacci Heap Implementation
Dijkstras Algorithm
Question: How do you know that Dijkstras
algorithm finds the shortest path and is
optimal when implemented with the
Fibonacci heap?
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.
Pseudocode
for every vertex v in V do
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 u in V VT that is adjacent to u* do
Dijkstras Algorithm
2
6
2
f
1
4
Dijkstras Algorithm
2
5
8
Tree vertices
a(-, 0)
Remaining vertices
b(a, 2) c(a, 5) d(a, 8) e(-, ) f(-, )
Dijkstras Algorithm
2
6
2
Tree vertices
b(a, 2)
Remaining vertices
c(b, 2+2) d(a, 8) e(-, ) f(b, 2+6)
Dijkstras Algorithm
2
6
2
f
1
Tree vertices
c(b, 4)
Remaining vertices
d(a, 8) e(c, 4+1) f(b, 8)
Dijkstras Algorithm
2
6
2
1
4
Tree vertices
e(c, 5)
Remaining vertices
d(a, 8) f(b, 8)
Dijkstras Algorithm
2
6
2
1
4
Tree vertices
d(a, 8)
Remaining vertices
f(b, 8)
Dijkstras Algorithm
a
b
6
2
f
1
Manipulation of heap/queue
Time complexity efficiency
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbits
5
9
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)
Worst-case complexity
Formula to discover the worst-case complexity for
Dijkstras algorithm:
W(n,m) = O(n * cost of insert +
n * cost of delete_min +
m * cost of decrease_key)
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)
Adversary Argument
Since we have already determined the shortest
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_anim