0% found this document useful (0 votes)
126 views20 pages

Dijkstra Demo

Dijkstra's algorithm is a greedy algorithm that finds the shortest paths between nodes in a graph. It can be used on directed or undirected, weighted or unweighted graphs. The algorithm works by initializing a distance array and repeatedly selecting the node with the minimum distance and updating the distances of its unselected neighbors.

Uploaded by

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

Dijkstra Demo

Dijkstra's algorithm is a greedy algorithm that finds the shortest paths between nodes in a graph. It can be used on directed or undirected, weighted or unweighted graphs. The algorithm works by initializing a distance array and repeatedly selecting the node with the minimum distance and updating the distances of its unselected neighbors.

Uploaded by

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

Dijkstra’s Algorithm

• Single Source Multiple Destination

• Shortest Path Algorithm


Definitions and Representation
• Graphs can be represented by their adjacency
matrix or an edge (or vertex) list.
• Adjacency matrices have a value ai,j = 1 if nodes i
and j share an edge; 0 otherwise. In case of a
weighted graph, ai,j = wi,j, the weight of the edge.
• The adjacency list representation of a graph G =
(V,E) consists of an array Adj[1..|V|] of lists. Each
list Adj[v] is a list of all vertices adjacent to v.
• For a grapn with n nodes, adjacency matrices take
Θ(n2) space and adjacency list takes Θ(|E|) space.
Definitions and Representation

An undirected graph and its adjacency matrix representation.

• An undirected graph and its adjacency list representation.


Requirements
• Works with directed and undirected graphs
• Works with weighted and unweighted graphs
• Rare type of algorithm 
A greedy algorithm that produces an
optimal solution
Walk-Through
2
Initialize array
3
5 F C K dv pv
A 10 7 3 A F  
8 4
18 B F  
4
9
B D C F  
10
H 9 25
D F  
2
3 E F  
G 7
E F F  
G F  
H F  
2
Start with G
3
5 F C K dv pv
10
A 7
4
3 A
8 B
18
4
9
B D C
10
H 9 25
D
2
3 E
G 7
E F
G T 0 
H
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A
8 B
18
4
9
B D C
10
H 9 25
D 2 G
2
3 E
G 7
E F
G T 0 
H 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A
8 B
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E
G 7
E F
G T 0 
H 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A
8 B
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 20 D
G T 0 
H 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A
8 B
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 20 D
G T 0 
H T 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A 7 H
8 B 12 H
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 20 D
G T 0 
H T 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B 12 H
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 20 D
G T 0 
H T 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B 12 H
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 17 A
G T 0 
H T 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B T 12 H
18
4
9
B D C
10
H 9 25
D T 2 G
2
3 E 27 D
G 7
E F 17 A
G T 0 
H T 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B T 12 H
18
4
9
B D C 16 B
10
H 9 25
D T 2 G
2
3 E 22 B
G 7
E F 17 A
G T 0 
H T 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B T 12 H
18
4
9
B D C T 16 B
10
H 9 25
D T 2 G
2
3 E 22 B
G 7
E F 17 A
G T 0 
H T 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B T 12 H
18
4
9
B D C T 16 B
10
H 9 25
D T 2 G
2
3 E 22 B
G 7
E F 17 A
G T 0 
H T 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
3 A T 7 H
8 B T 12 H
18
4
9
B D C T 16 B
10
H 9 25
D T 2 G
2
3 E 22 B
G 7
E F T 17 A
G T 0 
H T 3 G
2
Update unselected nodes
3
5 F C K dv pv
10
A 7
4
A T 7 H
8 B T 12 H
18
4
9
B D C T 16 B
10
H 9 25
D T 2 G
2
3 E 19 F
G 7
E F T 17 A
G T 0 
H T 3 G
2
Select minimum distance
3
5 F C K dv pv
10
A 7
4
A T 7 H
8 B T 12 H
18
4
9
B D C T 16 B
10
H 9 25
D T 2 G
2
3 E T 19 F
G 7
E F T 17 A
G T 0 
H T 3 G

Done

You might also like