0% found this document useful (0 votes)
184 views3 pages

10.6 Shortest-Path Problems

This document discusses shortest path problems and algorithms. It introduces Dijkstra's algorithm, which finds the shortest path between a starting node and all other nodes in a graph with positive edge weights. It then provides two examples applying Dijkstra's algorithm to find the shortest path between nodes a and z in weighted graphs.

Uploaded by

Filipus Kevin
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)
184 views3 pages

10.6 Shortest-Path Problems

This document discusses shortest path problems and algorithms. It introduces Dijkstra's algorithm, which finds the shortest path between a starting node and all other nodes in a graph with positive edge weights. It then provides two examples applying Dijkstra's algorithm to find the shortest path between nodes a and z in weighted graphs.

Uploaded by

Filipus Kevin
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/ 3

ICS 241: Discrete Mathematics II (Spring 2015)

10.6 Shortest-Path Problems


• Given a graph G = (V, E), a weighting function w(e), w(e) > 0, for the edges of G, and a
source vertex, v0 .

• We wish to determine a shortest path from v0 to vn

Dijkstra’s Algorithm
Dijkstra’s algorithm is a common algorithm used to determine shortest path from a to z in a graph.

Algorithm dijkstra(G : weighted connected simple graph with all weights positive)
{G has vertices a = v0 , v1 , . . . , vn = z and lengths w(vi , vj ) where w(vi , vj ) = ∞ if {vi , vj } is not
an edge in G}
1: for i = 1 to n do
2: L(vi ) = ∞
3: end for
4: L(a) = 0
5: S = ∅ {the labels are now initialized so that the label of a is 0 and all other labels are ∞, and
S is the empty set }
6: while z 6∈ S do
7: u = a vertex not in S with L(u) is minimal
8: S = S ∪ {u}
9: for all vertices v not in S do
10: if L(u) + w(u, v) < L(v) then
11: L(v) = L(u) + w(u, v)
12: end if
13: end for
14: end while
15: return L(z){L(z) = length of shortest path from a to z}

Traveling Salesman
The traveling salesman problem asks for the circuit of minimum total weight in a weighted, com-
plete, undirected graph that visits each vertex exactly once and returns to its starting point.

• Equivalent of asking for a Hamilton circuit with a minimum total weight in the complete
graph.
(n − 1)!
• circuits to examine
2
• This problem is NP-complete

• An approximation algorithm is used in practical approach

1
ICS 241: Discrete Mathematics II (Spring 2015)

10.6 pg. 716 # 5


Find the length and shortest path between a and z in each of the weighted graphs

a )

Use Dijkstra’s algorithm.


k L(a) L(b) L(c) L(d) L(e) L(z) Vertex
added Prior vertex on shortest path to
to S k b c d e z
0 0 ∞ ∞ ∞ ∞ ∞ a 1 a a
1 0 2 3 ∞ ∞ ∞ b 2 b b
2 0 2 3 7 4 ∞ c 3
3 0 2 3 7 4 ∞ e 4 e e
4 0 2 3 5 4 8 d 5 d
5 0 2 3 5 4 7 z
Our shortest path is a, b, e, d, z with length 7.

b )

2
ICS 241: Discrete Mathematics II (Spring 2015)

k L(a) L(b) L(c) L(d) L(e) L(f ) L(g) L(z) Vertex


added
to S
0 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ a
1 0 4 3 ∞ ∞ ∞ ∞ ∞ c
2 0 4 3 6 9 ∞ ∞ ∞ b
3 0 4 3 6 9 ∞ ∞ ∞ d
4 0 4 3 6 7 11 ∞ ∞ e
5 0 4 3 6 7 11 12 ∞ f
6 0 4 3 6 7 11 12 18 g
7 0 4 3 6 7 11 12 16 z
Prior vertex on shortest path to
k b c d e f g z
1 a a
2 c c
3
4 d d
5 e
6 f
7 g
Our shortest path is a, c, d, e, g, z with length 16.

You might also like