What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm

Q:

What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm ?
The exact complexity and why ??

 

A:

if we use 2 element as a pivot (suppose 1st and last element) then we partisan the array into three part and we use quick shot in every partisan

So the new recurrence relation became

T(n) = 3 x T(n/3) + O(n)
we assume the array partisan in equal parts and finding the exact position of pivot is O(n)
now applying master theorem f(n) = O(n); a=3; b=3; 
f(n) = O(n ^ (log a/log b))

so complexity is O(nlogn)

Now if we take k-1 pivot element the partisan the array in k part so
T()= k x T(n/k) + O(n)
which complexity is also O(n long)

so irrespective of how many partisan we do the complexity of quick sort remains same.

转载于:https://www.cnblogs.com/yayagamer/archive/2012/06/25/2560852.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值