《算法导论》第四章-思考题(参考答案)

算法导论(第三版)参考答案:思考题4.1,思考题4.2,思考题4.3,思考题4.4,思考题4.5,思考题4.6

Problem 4.1 (Recurrence examples)

Give asymptotic upper and lower bound for T(n) in each of the following recurrences. Assume that T(n) is constant for n2 . Make your bounds as tight as possible, and justify your answers.

  1. T(n)=2T(n/2)+n4
  2. T(n)=T(7n/10)+n
  3. T(n)=16T(n/4)+n2
  4. T(n)=7T(n/3)+n2
  5. T(n)=7T(n/2)+n2
  6. T(n)=2T(n/4)+n
  7. T(n)=T(n2)+n2
  1. 主方法情况三, T(n)=Θ(n4)
  2. 主方法情况三, T(n)=Θ(n)
  3. 主方法情况二, T(n)=Θ(n2lgn)
  4. 主方法情况一, T(n)=Θ(n2)
  5. 主方法情况一, T(n)=Θ(nlg27)
  6. 主方法情况二, T(n)=Θ(nlgn)
  7. 递归树法,假设n为偶数, T(n)=n2+(n2)2+(n4)2++T(2)=n21i=0(n2i)2+T(2)=Θ(n3)

Problem 4.2 (Parameter-passing costs)

Throughout this book, we assume that parameter passing during procedure calls takes constant time, even if an N-element array is being passed. This assumption is valid in most systems because a pointer to the array is passed, not the array itself. This problem examines the implications of three parameter-passing strategies:

  1. An array is passed by pointer. Time =Θ(1)
  2. An array is passed by copying. Time =Θ(N) , where N is the size of the array.
  3. An array is passed by copying only the subrage that might be accessed by the called procedure. Time =Θ(qp+1) if the subarray A[pq] is passed.

So:

  1. Consider the recursive binary search algorithm for finding a number in a sorted array (see Exercise 2.3-5). Give recurrences for the worst-case running times of binary search when arrays are passed using each of the three methods above, and give good upper bounds on the solutions of the recurrences. Let N be the size of the original problems and n be the size of a subproblem.
  2. Redo part (a) for the MERGE-SORT algorithm from Section 2.3.1.
  1. 二分查找

    a.

    T(n)=T(n/2)+c=Θ(lgn)

    b.

    T(n)=T(n/2)+cN=2cN+T(n/4)=3cN+T(n/8)=lgn1i=0(2icN/2i)=cNlgn=Θ(nlgn) c.

    T(n)=T(n/2)+cn=Θ(n)

  2. 归并排序

    a.

    T(n)=2T(n/2)+cn=Θ(nlgn)

    b.

    T(n)=2T(n/2)+cn+2N=i=0lgn1(cn+2iN)=i=0lgn1cn+Ni=0lgn12i=cnlgn+N2lgn121=cnlgn+nNN=Θ(nN)=Θ(n2)

    c.

    T(n)=2T(n/2)+cn+2n/2=2T(n/2)+(c+1)n=Θ(nlgn)

Problem 4.3 (More recurrence examples)

Give asymptotic upper and lower bounds for T(n) in each of the following recurrences. Assume that T(n) is constant for sufficiently small n. Make your bounds as tight as possible, and justify your answers.

  1. T(n)=4T(n/3)+nlgn
  2. T(n)=3T(n/3)+n/lgn
  3. T(n)=4T(n/2)+n2n
  4. T(n)=3T(n/32)+n/2
  5. T(n)=2T(n/2)+n/lgn
  6. T(n)=T(n/2)+T(n/4)+T(n/8)+n
  7. T(n)=
  • 12
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值