排序算法学习小结

参考 维基百科

0. 一些基本概念
--(体会)空间换时间是进一步提高算法速度的最终方法,比如希尔排序和基数排序就是通过占用额外空间来获得比快速排序更快的速度。当然,空间换不换的到时间,也是要看你写的算法的水平的。
--best, worst and average cases. In computer science, best, worst and average cases of a given algorithm express what the resource usage is at least, at most and on average, respectively. Usually the resource being considered is running time, but it could also be memory or other resources.
   1. example for best case: when doing a search, the first element is the one you look for.
   2. example for worst case: when doing a search, visiting every element to either find it in last position or not find it at all
   3. some algorithms like hash tables have very poor worst case behaviours, but a well written hash table of sufficient size will statistically never give the worst case
--Big O notation: In computer science, it is useful in the analysis of algorithms. If a function f( n) can be written as a finite sum of other functions, then the fastest growing one determines the order of f( n). For example
f(n) = 9 \log n + 5 (\log n)^3 + 3n^2 + 2n^3 \in O(n^3)\,\!.
NotationNameExample
O(1)\,constantDetermining if a number is even or odd; using a constant-size lookup table or hash table
O(\log n)\,logarithmicFinding an item in a sorted array with a binary search or a balanced search tree as well as all operations in a Binomial heap.
O(n^c),\;0<c<1fractional powerSearching in a kd-tree
O(n)\,linearFinding an item in an unsorted list or a malformed tree (worst case) or in an unsorted array; Adding two n-bit integers by ripple carry.
O(n\log n)=O(\log n!)\,linearithmic, loglinear, or quasilinearPerforming a Fast Fourier transform; heapsort, quicksort (best and average case), or merge sort
O(n^2)\,quadraticMultiplying two n-digit numbers by a simple algorithm; bubble sort (worst case or naive implementation), shell sort, quicksort (worst case), selection sort or insertion sort
O(n^c),\;c>1polynomial or algebraicTree-adjoining grammar parsing; maximum matching for bipartite graphs
L_n[\alpha,c],\;0 < \alpha < 1=\,
e^{(c+o(1)) (\ln n)^\alpha (\ln \ln n)^{1-\alpha}}
L-notation or sub-exponentialFactoring a number using the quadratic sieve or number field sieve
O(c^n),\;c>1exponentialFinding the (exact) solution to the traveling salesman problem using dynamic programming; determining if two logical statements are equivalent using brute-force search
O(n!)\,factorialSolving the traveling salesman problem via brute-force search; generating all unrestricted permutations of a poset; finding the determinant with expansion by minors.

1. 多种分类帮助理解排序基本概念
--内排序和外排序
--就地排序和非就地排序
--General method: insertion, exchange, selection, merging, etc.. Exchange sorts include bubble sort and quicksort. Selection sorts include shaker sort and heapsort.
2. 排序稳定性。注:不稳定的算法可以稍作修改考虑index来变成稳定的算法
3. 排序算法比较(关键是明白各个算法适用的场合)
n比较小时:选择排序
序列比较有序时:直接插入排序,冒泡排序
n比较大时:快速排序,堆排序,归并排序

(列表如下)

穩定的

不穩定

平均时间复杂度

平均时间复杂度由高到低为:

说明:虽然完全逆续的情况下,快速排序会降到选择排序的速度,不过从概率角度来说(参考信息学理论,和概率学),不对算法做编程上优化时,快速排序的平均速度比堆排序要快一些。

转载于:https://www.cnblogs.com/taoxu0903/archive/2011/04/08/2009225.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值