0% found this document useful (0 votes)
21 views25 pages

DS - Module-5-Part-2-I

The document discusses Dijkstra's algorithm for finding the shortest paths between a source vertex and all other vertices in a graph. It provides an example of running Dijkstra's algorithm on a weighted graph with 5 vertices labeled a through e. The algorithm builds a shortest path tree and identifies the shortest paths and their lengths from the source vertex a to each of the other vertices.

Uploaded by

Shashank Katti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views25 pages

DS - Module-5-Part-2-I

The document discusses Dijkstra's algorithm for finding the shortest paths between a source vertex and all other vertices in a graph. It provides an example of running Dijkstra's algorithm on a weighted graph with 5 vertices labeled a through e. The algorithm builds a shortest path tree and identifies the shortest paths and their lengths from the source vertex a to each of the other vertices.

Uploaded by

Shashank Katti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Module-5: Decrease-and-Conquer and Greedy Technique 21

4.3 Dijkstra’s Algorithm

• Single-source shortest-paths problem:


- “For a given vertex called the source in a weighted connected graph, find shortest paths to
all its other vertices”. Some paths may, have edges in common.
- The best-known algorithm for the single-source shortest-paths problem is a Dijkstra’s
algorithm
• Example: b 4 c
3 2 5 6
7 4
a d e

a (_, 0) b(a,3) c(_, ∞) d(a, 7) e(_,∞)


a

b
b (a, 3) c(b, 3+4) d(b, 3+2) e(_,∞) 3
a

b
d (b, 5) c(b, 7) e(d, 5+4 ) 3 2
a d

4
b c
c (b, 7) e(d, 5+4 ) 3 2
a d
4
b c
e(d, 9 ) 3 2
4
a d e

The next closest vertex is shown in bold


--------------------------------------------------------------------------------------------------
The shortest paths (identified by following nonnumeric labels backward from a destination
vertex in the left column to the source) and their lengths (given by numeric labels of the tree
vertices) are as follows:
from (a to b): a - b of length 3
from (a to d): a - b - d of length 5
from (a to c): a - b - c of length 7
from (a to e): a - b - d - e of length 9
Note:
Algorithm is applicable to undirected and directed graphs with nonnegative weights only.

Prof. Nandan G P, MCA, RNSIT

You might also like