0% found this document useful (0 votes)
43 views17 pages

Shortest Path Problems: Dijkstra's Algorithm

Dijkstra's algorithm finds the shortest path between nodes in a graph. It works by assigning initial distances from the starting node to all other nodes and then iteratively updating the distances as shorter paths are found. At each step, it selects the unvisited node with the lowest distance and updates the distances to neighboring nodes if a shorter path is found through the selected node. This continues until all nodes are visited. The algorithm has a runtime of O(n^2) and finds the single-source shortest paths in a graph with positive edge weights.

Uploaded by

Sachin Prakash
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)
43 views17 pages

Shortest Path Problems: Dijkstra's Algorithm

Dijkstra's algorithm finds the shortest path between nodes in a graph. It works by assigning initial distances from the starting node to all other nodes and then iteratively updating the distances as shorter paths are found. At each step, it selects the unvisited node with the lowest distance and updates the distances to neighboring nodes if a shorter path is found through the selected node. This continues until all nodes are visited. The algorithm has a runtime of O(n^2) and finds the single-source shortest paths in a graph with positive edge weights.

Uploaded by

Sachin Prakash
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/ 17

Shortest Path Problems

Dijkstra’s Algorithm

TAT ’01 Michelle Wang


Introduction
Many problems can be modeled using
graphs with weights assigned to their
edges:
 Airline flight times
 Telephone communication costs
 Computer networks response times
Where’s my motivation?
Fastest way to get to school by car
Finding the cheapest flight home
How much wood could a woodchuck
chuck if a woodchuck could chuck
wood?
Optimal driving time
UCLA 25

The Red
19
9
5 Garter
the beach (dude)

16 21
31
In N’ Out

36 My cardboard box on Sunset


Tokyo Subway Map
Setup:
 G = weighted graph
 In our version, need POSITIVE weights.
 G is a simple connected graph.
 A simple graph G = (V, E) consists of V, a nonempty set of
vertices, and E, a set of unordered pairs of distinct elements
of V called edges.
 A labeling procedure is carried out at each iteration
 A vertex w is labeled with the length of the shortest path
from a to w that contains only the vertices already in the
distinguished set.
Outline of Algorithm
Label a with 0 and all Once u is added to Sk
others with . we update the labels of
L0(a) = 0 and L0(v) =  all the vertices not in Sk
Labels are shortest To update labels:
paths from a to vertices
Sk = the distinguished Lk(a, v) = min{Lk-1(a, v),
set of vertices after k Lk-1(a, u) + w(u, v)}
iterations. S0 = . The
set Sk is formed by
adding a vertex u NOT
in Sk-1 with the smallest
label.
Using the previous example, we will find the
shortest path from a to c.

a 25

r
19
9 5
b

16 21
i 31

36 c
Label a with 0 and all others with . L0(a) = 0
and L0(v) = 

L0(a) = 0 25

L0(r) = 
19
9 5
L0(b) = 

16 21
L0(i) =  31

36 L0(c) = 
Labels are shortest paths from a to vertices.
S1 = {a, i}

L1(a) = 0 25

L1(r) = 
19
9 5
L1(b) = 

16 21
L1(i) = 9 31

36 L1(c) = 
Lk(a, v) = min{Lk-1(a, v), Lk-1(a, u) + w(u, v)}
S2 = {a, i, b}

L2(a) = 0 25

L2(r) = 
19
9 5
L2(b) = 19

16 21
L2(i) = 9 31

36 L2(c) = 
S3 = {a, i, b, r}

L3(a) = 0 25

L3(r) = 24
19
9 5
L3(b) = 19

16 21
L3(i) = 9 31

36 L3(c) = 
S4 = {a, i, b, r, c}

L4(a) = 0 25

L4(r) = 24
19
9 5
L4(b) = 19

16 21
L4(i) = 9 31

36 L4(c) = 45
Remarks
Implementing this algorithm as a computer
program, it uses O(n2) operations [additions,
comparisons]
Other algorithms exist that account for
negative weights
Dijkstra’s algorithm is a single source one.
Floyd’s algorithm solves for the shortest path
among all pairs of vertices.
Endnotes 1
Endnotes 2
For Math 3975:

You might also like