Dijkistra algorithm analysis, Lecture notes of Design and Analysis of Algorithms

This is a presentation about analysis of dijkistra algorithm. i.e. to find the complexity in terms of time and space.

Typology: Lecture notes

2017/2018

Uploaded on 03/24/2018

Shakirorakzai7
Shakirorakzai7 🇵🇰

3 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dijkistra’s algorithm
Dijkistras algorithm
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Dijkistra algorithm analysis and more Lecture notes Design and Analysis of Algorithms in PDF only on Docsity!

Dijkistra’s algorithmDijkistra’s algorithm

Single-

Source Shortest Path Problem

Single-

Source Shortest Path Problem

problem of finding shortest paths from a source vertex

v

to all other vertices in the graph

Source Shortest Path Problem

Source Shortest Path Problem

  • The

problem of finding shortest paths from a source

to all other vertices in the graph

Example A B C

Pre

Example D E

Example (contd…) A B C

Pre

Example (contd…) D E

Example (contd…) A B C A A A

Pre

Example (contd…) D E

Dijkstra Animated Example A B C A C A

Pre

Dijkstra Animated Example D E C C

Example (contd…) A B C A C A

Pre

Example (contd…) D E C C

Example (contd…) A B C A C A

Pre

Example (contd…) D E C C

Example (contd…) A B C A C A

Pre

Example (contd…) D E B C

Dijkstra's algorithm

Dijkstra(G,s) dist[s]
for all
v
V–{s}
do
dist[v]
(set all other distances to infinity)
Pre[v]
S
(S, the set of visited vertices)
Q
V
[G]
(Q, initially contains all nodes )
Q
V
[G]
(Q, initially contains all nodes )
while
Q ≠
(while the queue is not empty)
do
u
mindist
(Q, dist)
(select element of Q with min. dist )
S
S
{u}
(add u to list of visited vertices)
for all
v
Adj[u]
do if
dist[v] > dist[u] + w(u, v) then
d[v]
d[u] + w(u, v)
Pre[v]
u
return
S
dist

Dijkstra's algorithm

- Pseudocode

(set all other distances to infinity) (S, the set of visited vertices) (Q, initially contains all nodes )(Q, initially contains all nodes ) (while the queue is not empty) (select element of Q with min. dist ) (add u to list of visited vertices)
dist[v] > dist[u] + w(u, v)
d[u] + w(u, v)
Dijkstra’s algorithm calculates the shortest path to every vertex.
However, it is about as computationally expensive to calculate the shortest path from vertex u to every vertex using Dijkstra’s as it is to calculate the shortest

C ONCLUSION

vertex using Dijkstra’s as it is to calculate the shortest path to some particular vertex v.
Dijkstra’s algorithm calculates the shortest path to However, it is about as computationally expensive to calculate the shortest path from vertex u to every vertex using Dijkstra’s as it is to calculate the shortestvertex using Dijkstra’s as it is to calculate the shortest path to some particular vertex v.Therefore, anytime we want to know the optimal path Therefore, anytime we want to know the optimal path to some other vertex from a determined origin, we can to some other vertex from a determined origin, we can use Dijkstra’s algorithm.