Time Complexity of Randomized Quick Sort

本文探讨了随机化快速排序算法中元素间比较的期望次数。通过数学推导,得出每对元素比较的概率,并计算总的期望比较次数为O(nlogn),揭示了随机化快速排序效率高的原因。

Consider the randomized quick sort (i.e. the pivot is randomly chosen).

Let the sorted array \(A = [b_1, \dots, b_n]\). Put \(A_{ij} = \{b_i \text{ is compared to } b_j\}\).

Since \(b_i\) is compared to \(b_j\) iff \(b_i\) or \(b_j\) is first pivot chosen from \([b_i, \dots, b_j]\), thus each pair is compared at most once, and we have
\[ \mathbb P(A_{ij}) = \frac{2}{j-i+1}, \]

and the total number of comparisions performed
\[ X = \sum_{i=1}^{n-1}\sum_{j=i+1}^{n}1_{A_{ij}}. \]

Therefore,
\[ \mathbb EX < \sum_{i=1}^{n-1}\sum_{k=1}^n \frac{2}{k}=O(n\log n). \]

转载于:https://www.cnblogs.com/shiina922/p/11130524.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值