Chapter 24 Answers

Document last modified: 

Question 24.1

  RELAX(u, v, w)
1    if v.d > u.d + w(u, v)
2       then v.d u.d + w(u, v)
3                v.π u

Question 24.2 - w is the weight of the edge. Give the result of:

  r s t x y z
π NIL NIL s s NIL NIL
d 0 2 6

 

24.2 Single-source shortest paths in directed acyclic graphs

  r s t x y z
π NIL NIL NIL NIL NIL NIL
d 0
  RELAX(r, s, w)
1 if s.d > r.d + w(r, s)
2     then s.d r.d + w(r, s)
3             s.π  r
  RELAX(r, t, w)
1 if t.d > r.d + w(r, t)
2     then t.d r.d + w(r, t)
3             t.π r

Question 24.3 - No change from r→t or r→s. Why? r is the first vertex in the topological sort. However r is not the source, the RELAX algorithm only is applied to sorted vertices following the source.

 

Analysis

Similar to DFS analysis since DFS part of topological sort.

Time = Θ(V + E).

Question 24.4

Explain the Θ(V + E) cost.

3 for each vertex u taken in topologically sorted order       Θ(V)
4    for each vertex v ∈ Adj[ u ] Θ(V+E)
5        RELAX( u, v, w ) Θ(V+E)

Must always examine every V vertex and, for every vertex, each E edge. There are a total of V+E vertices and edges.

 

Critical Path Analysis (PERT)

Longest path in blue.

  r s t x y z
π NIL NIL s t x x
d 0 -2 -9 -8 -10
Earlier shortest path analysis.

 

  r s t x y z
π NIL NIL s s x y
d 0 2 6 5 3

Question 24.5

D˙kstra's Algorithm

  D˙kstra(V, E, w, s)
1 Init-Single-Source(V, s)
2 S ← ∅
3 Q ← V
4 while Q ≠ |
5         u ← Extract-Min( Q )
6         S ← S ∪ { u }
7         for each vertex v ∈ Adj[ u ]
8               Relax(u, v, w)

Question 24.6