# Dijkstra - PowerPoint PPT Presentation

View by Category
Title:

## Dijkstra

Description:

### First, finds the shortest path from the vertex to the nearest vertex. ... http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbits ... – PowerPoint PPT presentation

Number of Views:868
Avg rating:3.0/5.0
Slides: 24
Provided by: AMB126
Category:
Tags:
Transcript and Presenter's Notes

Title: Dijkstra

1
Dijkstras Algorithm Fibonacci Heap
Implementation
• by Amber McKenzie
• and Laura Boccanfuso

2
Dijkstras Algorithm
• Question How do you know that Dijkstras
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 Dijkstras 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
• dv ? 8 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
• if du w(u, u) lt du
• du ? du w(u, u) pu ? u
• Decrease(Q, u, du)

7
Dijkstras Algorithm
8
Dijkstras Algorithm
2
b
a
5
c
8
f
d
e
Tree vertices Remaining vertices
a(-, 0)
b(a, 2) c(a, 5) d(a, 8) e(-, 8) f(-, 8)
9
Dijkstras Algorithm
2
b
a
5
6
2
c
8
f
d
e
Tree vertices Remaining vertices
b(a, 2)
c(b, 22) d(a, 8) e(-, 8 ) f(b, 26)
10
Dijkstras Algorithm
2
b
a
5
6
2
c
8
f
3
1
d
e
Tree vertices Remaining vertices
c(b, 4)
d(a, 8) e(c, 41) f(b, 8)
11
Dijkstras Algorithm
2
b
a
5
6
2
c
8
f
3
1
d
4
7
e
Tree vertices Remaining vertices
e(c, 5)
d(a, 8) f(b, 8)
12
Dijkstras Algorithm
2
b
a
5
6
2
c
8
f
3
1
d
4
7
e
Tree vertices Remaining vertices
d(a, 8)
f(b, 8)
13
Dijkstras Algorithm
14
Dijkstras Algorithm Priority Queue
• Tree vertices Remaining vertices
• a(-, 0) b(a, 2) c(a, 5) d(a, 8) e(-, 8) f(-,
8)
• b(a, 2) c(b, 22) d(a, 8) e(-, 8 ) f(b, 26)
• c(b, 4) d(a, 8) e(c, 41) 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
• What makes the Fibonacci Heap optimally suited
• for implementing the Dijkstra algorithm?
• Manipulation of heap/queue
• Time complexity efficiency

http//www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon
acci/fibnat.htmlRabbits
16
Fibonacci Heap Implementation
• Manipulation of heap/queue
• Insert operation creates a new heap with one
element then performs a merge

4
2
• 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

7
5
9
17
Fibonacci Heap Implementation
Time Complexity Efficiency
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
18
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)
• (Where n maximum size of
priority queue
• m number of times inner loop is performed)

19
Worst-case complexity (cont.)
• 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)

20
Optimality of Dijkstras Algorithm
• 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

21
• 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).

v
22
• 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.

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/A
lgAnim/dijkstra.htmldijkstra_anim