算法导论(第三版)参考答案:练习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
Exercise 4.4-1
Use a reccursion tree to determine a good asymptotic upper bound on the recurrence T(n)=3T(⌊n/2⌋)+n. Use the substitution method to verify your answer.
假设 n是2的幂(忍受不精确),则递归树为
注:请看更正版,一个更好的渐进紧确界。
树高
代入法证明 T(n)≤cn2+2n:
O(n2)为 T(n)的一个渐进上界。
更正:
代入法证明 T(n)≤cnlg3+2n:
O(nlg3)为 T(n)的一个渐进上界。
Exercise 4.4-2
Use a reccursion tree to determine a good asymptotic upper bound on the recurrence T(n)=T(n/2)+n2. Use the substitution method to verify your answer.
树高 lgn,叶节点数量为 1,整棵树的代价:
证明 T(n)≤cn2
得证。
Exercise 4.4-3
Use a reccursion tree to determine a good asymptotic upper bound on the recurrence T(n)=4T(n/2+2)+n. Use the substitution method to verify your answer.
树高 lgn,叶节点数量为 4lgn=n2,整棵树的代价:
注:以下递归树求解有误,请略过。看更正版(上图递归树形状不变,其中常数项代价需更改)
更正:
证明 T(n)≤cn2+2n
得证 T(n)=O(n2)。
Exercise 4.4-4
Use a reccursion tree to determine a good asymptotic upper bound on the recurrence T(n)=2T(n−1)+1. Use the substitution method to verify your answer.
树高 n−1,叶节点数量为 2n−1,整棵树的代价:
证明 T(n)<c2n+n
得证 T(n)=O(2n)。
Exercise 4.4-5
Use a reccursion tree to determine a good asymptotic upper bound on the recurrence T(n)=T(n−1)+T(n/2)+n. Use the substitution method to verify your answer.
画图可知递归树不是完全二叉树,从 lgn到 n−1层为非完全的。求整棵树代价中,可以推测 T(n)=O(2n)
证明 T(n)≤c2n−4n
得证 T(n)=O(2n)
Exercise 4.4-6
Argue that the solution to the recurrence T(n)=T(n/3)+T(2n/3)+cn, where c is a constant, is Ω(nlgn)by appealing to the recurrsion tree.
递归树直到 log3n后才开始变得不完全,加上每层代价都为 cn,所以 T(n)≥Ω(nlog3n)=Ω(nlgn)。
Exercise 4.4-7
Draw the recursion tree for T(n)=4T(⌊n/2⌋)+cn, where cis a constant, and provide a tight asymptotic bound on its solution. Verify your answer with the substitution method.
树高
证明 T(n)≤cn2+2cn
证明 T(n)≥cn2+2cn
得证 T(n)=Θ(n2)。
Exercise 4.4-8
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n)=T(n−a)+T(a)+cn, where a≥1and c>0are constants.
树高 n/a(假设 n能被
尝试用代入法,证明 T(n)≤cn2
证明 T(n)≥c(n+1)2(这部分有trick)
决策树给出了精确值,可是代入法证明失败了。
Exercise 4.4-9
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n)=T(αn)+T((1−α)n)+cn, where α is a constant in the range 0<α<1, and c>0is also a constant.
类似练习4.4-6。假设 α更大,则树高
即 T(n)=Ω(nlgn)
代入法证明 T(n)≤dnlgn
只要 d≥−cαlgα+(1−α)lg(1−α), T(n)=O(nlgn)。
所以 T(n)=Θ(nlgn)。