Algorithm Part I:Quick Sort

1.快速排序的基本思想

2.快速排序的实现

3.快速排序的改进

(1)当递归到子集元素小于一定数目(如10)时,直接进行插入排序。

(2)每次取轴点时,尽量保证其靠近median。

4.快速排序的应用

(1)找集合中的第K小数。

5.集合中有很多元素时的快速排序

当集合中有很多元素时,快速排序的效率会急剧下降,接近O(N*N)。

解决思路:

代码实现:

时间: 2024-12-27 16:19:24

Algorithm Part I:Quick Sort的相关文章

Collection of algorithm for sorting. 常见排序算法集(三) —— Quick Sort

Quick Sort 快排,一个排序方法能直接享受这样的名称殊荣,呵呵,可见其威力与重要性. 其中最重要的思想就是 "分治"-- divide and conquer ! 这里排序用到的思想极其简单,却是很实用的!小孩子都会的简单想法. 先把所有数据分成三个部分. 在所有数据中选取某一元素X,比X小的放左边,比X大的放右边. 接着把这一思想同样分别施加在X元素的左边和右边部分,同样继续划分,选出一个元素X' 比X'小的放左边比X'大的放右边. 继续施加这种划分策略,直到划分的元素很少(

C++: quick sort(快排序)

到目前为止, 我们已经学习到了插入排序, 冒泡排序, 选择排序(selection). 这些排序算法都是comparision based sorting algorithms(即涉及到元素大小的比较来决定元素的先后顺序). 而且算法的时间复杂度上均为O(n^2).但是comparision based 的排序算法远非这几个算法. 而且可以通过利用其它的一些手段(例如divide and conquer technique, 分治法)实现对基于比较的排序算法的时间复杂度降低到O(nlogn).

Quick Sort

(referrence: GeeksforGeeks) Like Merge Sort, Quick Sort is also a divide & conquer problem. It picks an element as pivot and partitions the given array around the picked pivot. Different versions of Picking pivot 1. Always pick first element as pivot

1101. Quick Sort (25)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. G

pat1101. Quick Sort (25)

1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements

1101. Quick Sort (25)【快排】——PAT (Advanced Level) Practise

题目信息 1101. Quick Sort (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are

PAT 1101 Quick Sort[一般上]

1101 Quick Sort(25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the

1101 Quick Sort (25 分)递推

1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than th

1101 Quick Sort (25 分)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. G