Chapter 9 Exercises and Problems

Exercises
9.3-6 The k-th quantiles of an n-element set are the k-1 order statistics that divide the sorted set into k equal-sized sets (to within 1). Give an O(nlogk)-time algorithm to list the k-th quantiles of a set.
Use divide-and-conquer strategy and O(n) selection algorithm, we can conclude the complexity is T(n,k) = 2*T(n/2,k/2) + O(n)
Note that each level in the recursion tree is O(n), and there are O(logk) levels(since k<=n)
Thus T(n,k) = O(nlogk)

Problems
9-2 Weighted median
For n distinct elemennts x1~xn with positive weights w1~wn such that sigma(i=1~n,wi)=1, the weighted(lower) median is the element xk satisfying:
sigma(xi sigma(xi>xk,wi) <= 1/2
c. Show how to compute the weighted median in Θ(n) worst-case time using a linear-time median algorithm such as SELECT from Section 9.3
SELECT the median-of-median, partition the array, and then sum up the lower part partitioned to decide which branch to enter.
The recurrence is identical to that of SELECT's. Thus the worst-case time is also Θ(n).

转载于:https://www.cnblogs.com/FancyMouse/articles/1055088.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值