# 算法导论课后习题解析 第四章 上

4.1-1

4.1-2

Maximun-Subarray(A)
max = -infinity
for i = 1 to A.length
sum = 0
for j = i to A.length
sum = sum + A[i]
if sum > max
max = sum
low = i
high = j
return (low, high, max)


4.1-3

4.1-4

4.1-5

Maximun-Subarray(A)
max = 0, sum = 0, cur_low = 1
for i = 1 to A.length
sum = sum + A[i]
if sum > max
max = sum
low = cur_low
high = i
else if sum < 0
cur_low = i + 1
sum = 0
if max > 0
return (low, high, max)
return NIL


4.2-1

4.2-2

Strassen-Method(A, B)
n = A.rows
let C be a new m*n matrix
if n == 1
c11 = a11 * b11
else
S1 = B12 - B22
S2 = A11 + A12
S3 = A21 + A22
S4 = B21 - B11
S5 = A11 + A22
S6 = B11 + B22
S7 = A12 - A22
S8 = B21 + B22
S9 = A11 - A21
S10 = B11 + B12
P1 = Strassen-Method(A11, S1)
P2 = Strassen-Method(S2, B22)
P3 = Strassen-Method(S3, B11)
P4 = Strassen-Method(A22, S4)
P5 = Strassen-Method(S5, S6)
P6 = Strassen-Method(S7, S8)
P7 = Strassen-Method(S9, S10)
C11 = P5 + P4 - P2 + P6
C12 = P1 + P2
C21 = P3 + P4
C22 = P5 + P1 - P3 - P7
return C


4.2-3

4.2-4

• 如果$\log_3 k =2 \ \Rightarrow \ k=9$，那么满足第2种情况，$T(n)=\Theta (n^2 \lg n)=o(n^{\lg 7})$
• 如果$\log_3 k < 2 \ \Rightarrow \ k < 9$，那么满足第1种情况，$T(n)=\Theta (n^2)=o(n^{\lg 7})$
• 如果$\log_3 k > 2 \ \Rightarrow \ k > 9$，那么满足第3种情况，这时$\log_3 k < \lg 7 \Rightarrow k < 3^{\lg 7} \approx 21$

4.2-5

• 第一种情况下的复杂度递推公式为$T(n)=132464 T(n/68) + \Theta (n^2)$，$\log_{68} {132464} \approx 2.79512849$
• 第二种情况下的复杂度递推公式为$T(n)=143640 T(n/70) + \Theta (n^2)$，$\log_{70} {143640} \approx 2.79512269$
• 第二种情况下的复杂度递推公式为$T(n)=155424 T(n/72) + \Theta (n^2)$，$\log_{72} {155424} \approx 2.79514739$

4.2-6

4.2-7

4.3-1

4.3-2

4.3-3

4.3-4

4.3-5

4.3-6

4.3-7

4.3-8

4.3-9

4.4-1

4.4-2

4.4-3

4.4-4

4.4-5

4.4-6

4.4-7

4.4-8

4.4-9

posted @ 2013-05-08 15:54  有来 有去  阅读(7994)  评论(5编辑  收藏