{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chap15-solutions

# chap15-solutions - Selected Solutions for Chapter 15...

This preview shows pages 1–3. Sign up to view the full content.

Selected Solutions for Chapter 15: Dynamic Programming Solution to Exercise 15.2-5 Each time the l -loop executes, the i -loop executes n N l C 1 times. Each time the i -loop executes, the k -loop executes j N i D l N 1 times, each time referencing m twice. Thus the total number of times that an entry of m is referenced while computing other entries is P n l D 2 .n N l C 1/.l N 1/2 . Thus, n X i D 1 n X j D i R.i; j/ D n X l D 2 .n N l C 1/.l N 1/2 D 2 n N 1 X l D 1 .n N l/l D 2 n N 1 X l D 1 nl N 2 n N 1 X l D 1 l 2 D 2 n.n N 1/n 2 N 2 .n N 1/n.2n N 1/ 6 D n 3 N n 2 N 2n 3 N 3n 2 C n 3 D n 3 N n 3 : Solution to Exercise 15.3-1 Running RECURSIVE-MATRIX-CHAIN is asymptotically more efficient than enu- merating all the ways of parenthesizing the product and computing the number of multiplications for each. Consider the treatment of subproblems by the two approaches. ± For each possible place to split the matrix chain, the enumeration approach finds all ways to parenthesize the left half, finds all ways to parenthesize the right half, and looks at all possible combinations of the left half with the right half. The amount of work to look at each combination of left- and right-half

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
15-2 Selected Solutions for Chapter 15: Dynamic Programming subproblem results is thus the product of the number of ways to do the left half and the number of ways to do the right half. ± For each possible place to split the matrix chain, RECURSIVE-MATRIX-CHAIN finds the best way to parenthesize the left half, finds the best way to parenthesize the right half, and combines just those two results. Thus the amount of work to combine the left- and right-half subproblem results is O.1/ . Section 15.2 argued that the running time for enumeration is .4 n =n 3=2 / . We will show that the running time for RECURSIVE-MATRIX-CHAIN is O.n3 n N 1 / . To get an upper bound on the running time of RECURSIVE-MATRIX-CHAIN, we’ll use the same approach used in Section 15.2 to get a lower bound: Derive a recur- rence of the form T.n/ ± : : : and solve it by substitution. For the lower-bound recurrence, the book assumed that the execution of lines 1–2 and 6–7 each take at least unit time. For the upper-bound recurrence, we’ll assume those pairs of lines each take at most constant time c . Thus, we have the recurrence T .n/ ± ± c if n D 1 ; c C n N 1 X k D 1 .T.k/ C T.n N k/ C c/ if n ² 2 : This is just like the book’s ² recurrence except that it has c instead of 1, and so we can be rewrite it as T .n/ ± 2 n N 1 X i D 1 T.i/ C cn : We shall prove that T.n/ D O.n3 n N 1 / using the substitution method. (Note: Any upper bound on T.n/ that is o.4 n =n 3=2 / will suffice. You might prefer to prove one that is easier to think up, such as T.n/ D O.3:5 n / .) Specifically, we shall show that T .n/ ± cn3 n N 1 for all n ² 1 . The basis is easy, since T .1/ ± c D c ³ 1 ³ 3 1 N 1 .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

chap15-solutions - Selected Solutions for Chapter 15...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online