1. Floyd's algorithm uses dynamic programming to compute the All-Pairs Shortest-Paths of a directed graph. It is almost exactly like Warshall's algorithm since it grows the set of intermediate nodes on the path and generates a sequence of distance matrices D(0), D(1), ... , D(n). The D(k) matrix contains the shorted paths using only intermediate nodes from the set of vertices {1, 2, 3, ... , k}

ALGORITHM Floyd's ( A[1..n, 1..n])

// Implements Warshall's algorithm for computing the transitive closure

// Input: The adjacency matrix A of a digraph with n vertices

// Output: The transitive closure of the digraph

for to n do

for to n do

for to n do

, + }

return D (n)

(Note: We can actually get by with a single D matrix that is updated repeatedly.)

For the above graph, generates the sequence of distance matrices D(0), D(1), ... , D(n).

Keys: A B C D
Probabilities: 0.2 0.3 0.4 0.1

2. If the following BST is searched according to the above probabilities, what is the average number of comparisons of successful searches?

3. In a dynamic programming fashion we want to view the problem recursively, but solve the smallest problems to largest problem. To view the problem recursively, it is sometimes helpful to view the final solution. What would the optimal BST look like?

4. What dimensionality of array(s) do we need to store the answers to smaller problems?