COT 5405 Analysis of Algorithm
Midterm Exam II Solution
Problem 1(30pts)
.
Given an undirected simple weighted graph
G
= (
V, E
) (having no selfloops or
multiedges) with two designated vertices
s, t
∈
V
and weight
w
e
(unnecessarily positive) for any edge
e
∈
E
.
A path
p
s,t
is said to be shortest from
s
to
t
if the aggregate weight of
p
s,t
, defined as
c
(
p
s,t
) =
∑
edge
e
∈
p
s,t
w
e
,
is the smallest among all paths from
s
to
t
.
A
second
smallest path is a path
p
′
s,t
with
c
(
p
′
s,t
)
≥
c
(
p
s,t
) and contains at least one different edge from
p
s,t
,
while
c
(
p
′
s,t
)
≤
c
(
q
) for any other
s
−
t
path
q
.
1. (15pts) Design an algorithm to find such a second smallest
s
−
t
path. Please describe your algorithm
and sketch its correctness. Pseudocode is NOT required.
2. (15pts) Two (or more) paths are edgedisjoint if they have no edges in common. The
K
shortest
Edge
Disjoint
Path Problem is to find the shortest, 2
nd
shortest,
· · ·
,
K
th
shortest
s
−
t
paths which are
EdgeDisjoint. Design an algorithm to find these
K
paths. Please describe your algorithm and sketch its
correctness. Pseudocode is NOT required. (
HINT:
translate this into a ﬂow problem. )
3. (
Bonus
10pts) Two (or more) paths are nodedisjoint if they have no common intermediate nodes. Design
an algorithm to find the
K
shortest
NodeDisjoint
Paths. Please describe your algorithm and sketch it
s correctness. Pseudocode is NOT required. (
HINT
: Convert to K shortest EdgeDisjoint Path Problem.)
Solution
: Note that
simple
graph is a graph with no
self
loop or multiple edges. Directed or undirected
simple graphs have the same solution for this question.
(1) Use a similar idea of FloydWarshall algorithm.
Step 1
: Use FloydWarshall algorithm to find the shortest paths from
s
to all
v
∈
V
and those from all
v
∈
V
to
t
in
O
(

V

3
) time.
Denote the shortest path between
i
and
j
as
π
1
(
i, j
).
Initialize the second
shortest path as
π
2
(
i, j
) with
length
(
π
2
(
i, i
)) = 0 and
length
(
π
2
(
i, j
)) =
∞
for
i
̸
=
j
.
Step 2
:
For every edge (
x, y
)
∈
E
Let the path
tmp
(
s, t
) be the concatenation:
π
1
(
s, x
)
,
(
x, y
)
, π
1
(
y, t
)
if (
tmp
(
s, t
) is not shorter than
π
1
(
s, t
) and with at least one different edge from
π
1
(
s, t
)) &&
(
tmp
(
s, t
) is shorter than
π
2
(
s, t
))
π
2
(
s, t
) =
tmp
(
s, t
)