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?