Problem Set #2

CS 155 -- due October 11, 1999

Each problem is worth 10 points
  1. Trace the dynamic programming algorithm for the chained matrix multiplication problem to find the most efficient way to multiply a chain of matrices of respective sizes 10x5, 5x20, 20x10, 10x10, 10x30, and 30x10.

  2. Construct a dynamic programming algorithm for the chained matrix multiplication problem that finds the least efficient way to multiply a chain of matrices. Trace your algorithm on the instance above.

  3. Consider the greedy algorithm for the chained matrix multiplication problem of size n that works by first performing the multiplication that correpsonds to the largest value of di, and continues by calling itself on the resulting problem of size n-1. So in the example of Problem 1, the values of di used would be first d5=30, then d2=20, then (say) d3=10, then d4=10, and finally d1=5, giving M1 x (((M2 x M3) x M4) x (M5 x M6)).
    Find a problem instance for which n=4, the optimal solution is a balanced tree, and the given algorithm fails to find the optimal solution.

  4. As discussed briefly in class, an instance of the Optimal Binary Search Tree problem consists of an integer n, a sequence of n weights (pi)i=1n corresponding to probabilities of successful searches for data items (Pi)i=1n, and another sequence (qi)i=0n corresponding to probabilities of unsuccessful searches corresponding to data intervals (Qi)i=1n.

    The goal is to find the binary tree with the cheapest cost, where the cost is the sum from 1 to n of (1+li )*pi, plus the sum from 0 to n of mi*qi , where li is the level of the item Pi and mi the level of the external node corresponding to Qi.

    Let Cj,k be the cost of the cheapest binary search tree for the subproblem consisting of the data items (Pi)i=j+1k and data intervals (Qi)i=jk, so that the cost of the optimal tree for the original instance is C0,n. If r ranges over the set of possible roots of the binary search tree for the subproblem, then

    Cj,k = Sj,k + minj<=r<k {Cj,r + Cr+1,k},
    where the term Sj,k accounts for the fact that one extra comparison is required to reach every node in the new tree. This means that Sj,k equals the sum from j+1 to k of pi plus the sum from j to k of qi. Note that the term Sj,k appears outside the braces, since it is independent of r.

    Based on this recurrence (and appropriate initial conditions), find the cost of the optimal binary search tree for the instance where n=5, (pi ) = (30 10 5 10 10), and (qi) = (5 10 5 5 5 5). Also sketch the optimal tree.