Professional Documents
Culture Documents
TRAVERSING THE
SHORTEST PATH
PROBLEM
MATHEMA
TICS FOR
EFFICIENC
Y
THE PROBLEM
THE PROBLEM
DESTINATION
STARTING POINT
THE PROBLEM
What is a
shortest
path from
the
starting
point to
the
destination
point?
ORDER AND SIZE OF A GRAPH
The order of , denoted by , is the number of
vertices in .
The size of , denoted by , is the number of
edges in .
MULTIPLE EDGES AND LOOPS
If
there is more than one edge joining vertices
and , then contains a multiple edge.
An edge from a vertex to itself is called a loop.
Thereare three
edges that are
incident to both
𝐻 : vertex and .
Moreover, there is
a loop at vertex .
MULTIGRAPH AND SIMPLE GRAPH
:
is a simple graph while is a multigraph.
DEGREE AND
NEIGHBORHOOD OF A
VERTEX
The
degree of the vertex, denoted by , is the
number of edges that are incident to the vertex .
𝑢 𝑢
𝑢 𝑢 𝑢
The neighborhood of , denoted by , is the set of all
vertices that are adjacent to .
WALKING ON A GRAPH
A
walk of length from vertex to vertex is a
sequence of vertices such that two consecutive
vertices are joined by an edge.
Denote this walk by
The walk is illustrated as
(check animation).
WALKING ON A GRAPH
A
walk of length from vertex to vertex is a
sequence of vertices such that two consecutive
vertices are joined by an edge.
Denote this walk by
said to be
connected if
there is
always a path
from a vertex
to another.
This is a disconnected graph (WHY?). Otherwise, is
disconnected.
WEIGHTED GRAPH
We say that graph is a weighted graph if all
𝐷:
DIJKSTRA’S
ALGORITHM
Is
a method for determining a shortest path from a
starting vertex to any destination vertex.
It applies to simple connected positive-weighted
graphs (directed or undirected).
FORMAL DESCRIPTION
State of a vertex: distance value and status label
The distance value of a vertex represents an
estimate of its distance from vertex . This may be
updated each time a step is carried out.
Status labels: Permanent or Temporary.
Once a vertex reaches permanent status label,
that means we have determined its shortest
distance from the starting point.
At each step of the algorithm, one vertex is
designated as current.
9 b
a 6
2
14 For our first
e 11
9 example, copy this
c
graph using pencil
s
10
15
7
f
STEP 1: INITIALIZATION
Assign the zero distance value to the starting vertex (say )
and label it as permanent.
Assign the distance value to all other vertices and label
them as temporary.
Designate the vertex as the current vertex.
(,t) 9 b (,t)
CURRENT DISTANCE
a 6 VERTEX FROM
2 STARTING
14 (,t) VERTEX
e 11 s 0
9 (,t)
c
(0,p) s
10
Current vertex
15
7
f
(,t)
STEP 2: DISTANCE VALUE UPDATE
OF NEIGHBORS OF CURRENT VERTEX
(,t) 9 b (,t)
(,t)
a 6
2
14 (,t)
(,t)
e 11
9 (,t)
c
(0,p) s
10
15
7
f
(,t)
(,t)
STEP 3: CURRENT VERTEX DESIGNATION
UPDATE
Among the temporary vertices (this may or may not be adjacent to
the current vertex), choose the one with the lowest distance value.
The one with the lowest distance value becomes permanent and
becomes the new current vertex.
(,t)
9 b CURRENT DISTANCE
(,t)
a VERTEX FROM
6 STARTING
2 VERTEX
14 (,t)
11 (,t) s 0
e
9 c f 7
(0,p) s
10
15
7
f (,t)
(,p) Current Vertex
REPEAT STEP 2 AND STEP 3…
9 b (,t)
(,t) CURRENT DISTANCE
a 6 VERTEX FROM
2 Current Vertex
(,t)=(17,t) STARTING
14 (9,p)
(,t) (,t)=(22,t) VERTEX
e 11 s 0
9 (,t)
c (22,t)
f 7
(0,p) s
10 e
e 9
9
15
7
f
(,p)
REPEAT STEP 2 AND STEP 3
(11+9,t)=(20,t)
9 b (20,t)
(,t) CURRENT DISTANCE
(11,p) VERTEX FROM
a 6 STARTING
2 VERTEX
14 (9,p)
Current Vertex s 0
e 11
9 c (20,p) f 7
(20,t)
(0,p) s e
e 9
9
10 a 11
a 11
15 c 20
7 c 20
f
(,p)
ENDING CURRENT
VERTEX
DISTANCE
FROM
(20+6,t)=(26,t) STARTING
VERTEX
(20,p)
9 b (20,t) s 0
(11,p)
a 6 f 7
2 e
e 9
9
14 (9,p)
a
a 11
11
e 11
9 c (20,p) c 20
c 20
(0,p) s b 20
10 b 20
15
7
f
(,p)
2
a b
3 8
6 7 1
s c
4 4
e f
5
STEP 1: INITIALIZATION
2
a b
3 8
6 7 1
(0,p) s c
4 4
e f
5
STEP 1: INITIALIZATION
(∞,t) (∞,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
Current Vertex
4 4
e f
5
(∞,t) (∞,t)
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
Current Vertex Distance from s
s 0
Current Vertex a 3
(3,p)
(3,t)
(∞,t) (∞,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(∞,t) (∞,t)
(4,t)
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
(3,p) (∞,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,t) (∞,t)
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
Current Vertex Distance from s
s 0
a 3
e 4
(3,p) (5,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p)
(4,t) (10,t)
Current Vertex
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
(3,p) (5,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (10,t)
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
(3,p) (5,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (10,t)
STEP 2: UPDATE DISTANCE VALUE OF
NEIGHBORS OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT
VERTEX
(3,p) (5,t)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (9,t)
STEP 2: UPDATE DISTANCE VALUE OF NEIGHBORS
OF CURRENT VERTEX
STEP 3: CHOOSE NEW CURRENT VERTEX
Current Vertex Distance from s
s 0
a 3
e 4
b 5
Current Vertex
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (9,t)
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (9,t)
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (∞,t)
4 4
e f
5
(4,p) (9,t)
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (13,t)
4 4
e f
5
(4,p) (6,t)
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (13,t)
4 4
e f
5
(4,p) (6,t)
Current Vertex Distance from s
REPEAT… s
a
0
3
e 4
b 5
f 6
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (13,t)
4 4
e f
5
(4,p) (6,p)
Current Vertex
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (13,t)
4 4
e f
5
(4,p) (6,p)
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (10,t)
4 4
e f
5
(4,p) (6,p)
REPEAT…
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (10,p)
4 4
e f
5
(4,p) (6,p)
Current Vertex Distance from s
s 0
a 3
ENDING e 4
b 5
f 6
c 10
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (10,p)
4 4
e f
5
(4,p) (6,p)
ENDING
(3,p) (5,p)
2
a b
3 8
6 7 1
(0,p) s c (10,p)
4 4
e f
5
(4,p) (6,p)
KNOWLEDGE CHECK
1.
5A
Find the least expensive route from I to L and state its
cost.
12
J K
0 80
15
0
L
I 40 10 50
0
12 N 30
0 70
40
P
30 M
30
80
O
KNOWLEDGE CHECK
2.
5A
Find the shortest path from vertex A to vertex Z.