Download Presentation
Dijkstra’s Algorithm Fibonacci Heap Implementation

Loading in 2 Seconds...

1 / 18

# Dijkstra’s Algorithm Fibonacci Heap Implementation - PowerPoint PPT Presentation

Dijkstra’s Algorithm Fibonacci Heap Implementation. Single-Source Shortest Path. For a given vertex, determine the shortest path between that vertex and every other vertex, i.e. spanning tree with minimal path costs from the source vertex. Premise of Dijkstra’s Algorithm.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

## PowerPoint Slideshow about ' Dijkstra’s Algorithm Fibonacci Heap Implementation' - norris

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Dijkstra’s Algorithm Fibonacci Heap Implementation

Single-Source Shortest Path
• For a given vertex, determine the shortest path between that vertex and every other vertex, i.e. spanning tree with minimal path costs from the source vertex.
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.
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 ← VtU {u*}

for every vertex u in V– VT that is adjacent to u* do

if du* + w(u*, u) < du

du← du* + w(u*, u); pu← u*

Decrease(Q, u, du)

Dijkstra’s Algorithm

2

b

a

5

6

2

c

8

f

3

1

d

4

7

e

Dijkstra’s 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(-, ∞) f(-, ∞)

Dijkstra’s Algorithm

2

b

a

5

6

2

c

8

f

d

e

Tree vertices Remaining vertices

b(a, 2)

c(b, 2+2) d(a, 8) e(-, ∞ ) f(b, 2+6)

Dijkstra’s 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, 4+1) f(b, 8)

Dijkstra’s 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)

Dijkstra’s 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)

Dijkstra’s Algorithm: 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)

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/Fibonacci/fibnat.html#Rabbits

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

5

7

9

Fibonacci Heap Implementation

Time Complexity Efficiency

* USDL list: Unsorted Doubly Linked list

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)

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)