1. Floyd's algorithm uses dynamic programming to compute the All-Pairs Shortest-Paths of a directed graph. 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}

void floyd ( int n, const number W[ ][ ], number D[ ][ ])

// Implements Floyd's algorithm for computing all-pairs shortest-paths of a directed graph

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

// Output: The matrix D containing the shortest distances between pairs of vertices

for to n do

for to n do

for to n do

, + }

D 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 for successful searches?

3. For the above probabilities, what would be the optimal BST?

4. Consider developing an algorithm for finding an optimal BST for keys: Key1 < Key2 < ... < Keyk < ... < Keyn given known search probabilities of p1, p2, ... , pn, respectively. 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. Suppose the following is an optimal BST, answer the following questions:

a) What keys are in TA?

b) What properties must TA possess?

c) If x is the average number of comparisons to search TA, how does this average change when TA is made a subtree of root Keyk?

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