When using its associated dynamic-programming recurrence to compute the entries of wac(i, j), how many times is entry wac(25, 32) used in order to compute other entries of wac that represent larger subproblems, assuming n = 76 keys? Explain and show work.
5b. The general form of a divide-and-conquer recurrence may be expressed as
T(n) = Xr i=1 T(n/bi) + f(n),
for some integer r ≥ 1 and real constants bi > 1, i = 1, . . . , r. Assuming T(n) is an increasing function of n, and f(n) = n α for some α > 0, prove that T(n) has growth that is O(n k ) for some integer k ≥ 1. Hint: Show that T(n) ≤ T 0 (n), for some T 0 (n) that satisfies a uniform recurrence
T 0 (n) = aT0 (n/b) + n α .
Obtain T 0 by using the fact that, since T(n) is increasing, T(n/b1) < T(n/b2) when b1 > b2. (20 points)
A
Investigating the optimal substructure of a problem by iterating on subproblem instances is a good way to infer a suitable space of subproblems for dynamic programming.
For example, after looking at the structure of an optimal solution to a matrix-chain problem, we might iterate and look at the structure of optimal solutions to subproblems, subsubproblems, and so forth. We discover that all subproblems consist of subchains of Al, A2, . . . , An. Thus, the set of chains of the form Ai, Aj+l, . . . , Aj.for 1 i j n makes a natural and reasonable space of subproblems to use.
1 if i = j
2 then return 0
3 m[i, j]
4 for k i to j - 1
5 do q RECURSIVE-MATRIX-CHAIN(p, i, k)
+ RECURSIE-MATRIX-CHAIN(p, k + 1, j) + pi-1pkpj
6 if q < m[i, j]
7 then m[i, j] q
8 return m[i, j]
B.
function multiply(x, y)
Input: Positive integers x and y, in binary
Output: Their product
n = max(size of x, size of y)
if n = 1: return xy xL,
xR = leftmost dn/2e, rightmost bn/2c bits of x yL,
yR = leftmost dn/2e, rightmost bn/2c bits of y
P1 = multiply(xL, yL)
P2 = multiply(xR, yR)
P3 = multiply(xL + xR, yL + yR)
return P1 × 2 n + (P3 − P1 − P2) × 2 n/2 + P2
Get Answers For Free
Most questions answered within 1 hours.