VIEWS: 2 PAGES: 2

• pg 1
```									lCS311 Spring 2008 Homework Solution, Ch. 25 Find the shortest paths for the graph given by the adjacency matrix below, using SLOW-ALL-PAIRSSHORTEST-PATHS, FASTER-ALL-PAIRS-SHORTEST-PATHS, and Floyd Warshall algorithms. Show each L(k). and D(k). matrix, as well as each parent matrix π(k), for each algorithm (so there will be a π(k), matrix for each L(k). matrix, and a π(k), matrix for each D(k). matrix). What is the final solution? L(3) and D(4) How will you check if your results are correct? Do so. In this case, the graphs are small so it is easy to visually inspect them.
a a b c d b c d

1.

∞ ∞ ∞ ∞

5 ∞ ∞ 1

3 2 ∞ ∞

∞ ∞ 4 ∞

Hint: what kind of matrix is required as input to the algorithm? 0s on the main diagonal  otherwise, the solution for the final L[i,j] will be the smallest L[i,j] amongst all L matrices. Therefore, we have to start from:
a a b c d b c d

0 ∞ ∞ ∞

5 0 ∞ 1

3 2 0 ∞

∞ ∞ 4 0

SLOW ALL PAIRS SHOWING (d, pi) L(1): 0 5,1 3,1 inf inf 0 2,2 inf inf inf 0 4,3 inf 1,4 inf 0 L(2): 0 inf inf inf L(3): 0 inf inf inf

5,1 0 5,4 1,4

3,1 2,2 0 3,2

7,3 6,3 4,3 0

5,1 0 5,4 1,4

3,1 2,2 0 3,2

7,3 6,3 4,3 0

FAST ALL PAIRS L(2): 0 5 0 5 7 0 inf 0 6 5 inf 5 4 1 inf 1

L(4): 0 inf inf inf

5 0 5 1

3 2 0 3

7 6 4 0

FLOYD WARSHALL D(0): 0 5,1 3,1 inf inf 0 2,2 inf inf inf 0 4,3 inf 1,4 inf 0

D(1): 0 5,1 inf 0 inf inf inf 1,4

3,1 inf 2,2 inf 0 4,3 inf 0

D(2): 0 5,1 inf 0 inf inf inf 1,4

3,1 inf 2,2 inf 0 4,3 3,2 0

D(3): 0 5,1 inf 0 inf inf inf 1,4

3,1 7,3 2,2 6,3 0 4,3 3,2 0

D(4): 0 5,1 inf 0 inf 5,4 inf 1,4

3,1 2,2 0 3,2

7,3 6,3 4,3 0

```
To top