# CSE 431/531 Homework 4 Due date: Apr 15, 2016 Lecturer: Shi Li

```CSE 431/531 Homework 4
Due date: Apr 15, 2016
Lecturer: Shi Li
Problems
Max. Score
1
10
2
12
3
14
4
14
Total Score
50
Problem 1 (10 points). Use Dijkstra’s algorithm to compute the shortest paths from s to all
other vertices in the following undirected graph.
a
40
8
b
s
13
25
f
1
17
19
c
5
e
18
5
19
d
16
You can use the following table to describe the execution of the algorithm. The algorithm
maintains a set S of vertices. The d value of a vertex v ∈ S is the distance from s to v; the d value
of a vertex v ∈
/ S is minu∈S:(u,v)∈E (d(u) + w(u, v)). The π value of a vertex v is the vertex u such
that d(v) = d(u) + w(u, v); if d(v) = ∞, then π(v) =“/”.
iteration
1
2
3
4
5
6
7
s
a
d
13
b
π
s
d
∞
1
c
π
/
d
∞
d
π
/
d
∞
e
π
/
d
5
f
π
s
d
25
π
s
Problem 2 (12 points). Suppose we are give a directed graph G = (V, E) with edge weights
w : E → R, and there are no negative cycles in G. Prove that after the k-th iteration of FloydWarshall algorithm, f [i, j] is at most the length of the shortest path from i to j that only uses
{1, 2, 3, &middot; &middot; &middot; , k} as intermediate vertices.
Problem 3 (14 points). Suppose we are give a directed graph G = (V, E) with edge weights
w : E → R. The Floyd-Warshall algorithm described in the class assumes that G does not contain
a negative cycle. Show how to use the f values (i.e., f [i, j] for every i, j ∈ V ) computed by the
algorithm to check if G contains a negative cycle or not. You need to prove the correctness of your
solution.
Problem 4 (14 points). Given a directed graph G = (V, E) with weights w : E → R≥0 , and
two vertices s and t, we want to compute the shortest path from s to t that uses even number of
edges. Show how to use Dijkstra’s algorithm to solve the problem.
2
```