xtaci / algorithms

Algorithms & Data structures in C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

快速排序枢纽值pivot的选择不是最高效的.

solome opened this issue · comments

In https://github.com/xtaci/algorithms/blob/master/include/quick_sort.h

在目前(2013年10月21日 16时12分55秒)快速排序算法的实现中,枢纽值pivot是通过随机数选取的,即int pivot_idx = RANDOM(begin,end);但这不是最高效的枢纽选择策略。
对快速排序效率影响最大的是枢纽值pivot的选择,建议采取首值、中间值和末尾值进行比较,选择中间大小的那个值作为枢纽值pivot策略。这样在数据量大的情况下,排序效果会更加高效。

可以详见博客描述:http://blog.csdn.net/nwpu_kexie/article/details/7538673

yes, a good pivot is important to the whole algorithm.
i'll be appreciate if you can "push request" some code.

还是这个头文件,最后面。swap(list[begin + 1], list[end]);是不是该改为list[begin]?

回滚到之前的更易读的版本了