数据结构(十六)排序

排序算法

0. 前言

本来准备自己写,无意间看到一位大佬的博文…大家还是移步吧
推荐一套自己开发的算法演示工具

1. 总结

排序方法 平均时间复杂度 最坏时间复杂度 额外空间复杂度 稳定性
简单选择排序 O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <mn> 1 </mn> </mrow> <annotation encoding="application&#47;x&#45;tex"> 1 </annotation> </semantics> </math>1) 不稳定
冒泡排序 O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <mn> 1 </mn> </mrow> <annotation encoding="application&#47;x&#45;tex"> 1 </annotation> </semantics> </math>1) 稳定
直接插入排序 O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <mn> 1 </mn> </mrow> <annotation encoding="application&#47;x&#45;tex"> 1 </annotation> </semantics> </math>1) 稳定
希尔排序 O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mi> d </mi> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^d </annotation> </semantics> </math>Nd) O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <mn> 1 </mn> </mrow> <annotation encoding="application&#47;x&#45;tex"> 1 </annotation> </semantics> </math>1) 不稳定
堆排序 O( <math> <semantics> <mrow> <mi> N </mi> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> NlogN </annotation> </semantics> </math>NlogN) O( <math> <semantics> <mrow> <mi> N </mi> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> NlogN </annotation> </semantics> </math>NlogN) O( <math> <semantics> <mrow> <mn> 1 </mn> </mrow> <annotation encoding="application&#47;x&#45;tex"> 1 </annotation> </semantics> </math>1) 不稳定
快速排序 O( <math> <semantics> <mrow> <mi> N </mi> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> NlogN </annotation> </semantics> </math>NlogN) O( <math> <semantics> <mrow> <msup> <mi> N </mi> <mn> 2 </mn> </msup> </mrow> <annotation encoding="application&#47;x&#45;tex"> N^2 </annotation> </semantics> </math>N2) O( <math> <semantics> <mrow> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> logN </annotation> </semantics> </math>logN) 不稳定
归并排序 O( <math> <semantics> <mrow> <mi> N </mi> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> NlogN </annotation> </semantics> </math>NlogN) O( <math> <semantics> <mrow> <mi> N </mi> <mi> l </mi> <mi> o </mi> <mi> g </mi> <mi> N </mi> </mrow> <annotation encoding="application&#47;x&#45;tex"> NlogN </annotation> </semantics> </math>NlogN) O(N) 稳定
基数排序 O(P(N+B)) O(P(N+B)) O(N+B) 稳定

2. 各种排序算法比较

《数据结构》09-排序1 排序

全部评论

相关推荐

03-26 13:04
已编辑
电子科技大学 算法工程师
xiaowl:你这个简历“条目上”都比较有深度性,但是实际上面试官又没法很好的评估你是怎么达到很多看上去很厉害的结果的。要避免一些看上去很厉害的包装,比如高效的内存复用策略的表达,如果仅是简单的一些内存共享机制,而且面试上也没有深挖的空间,就不要这样表达。比如,工程化模式本质上可能就是定义了一些abstract class,那也就没特别多值得讲的内容。建议简历上应该侧重那些你花了大量时间和精力解决、研究的问题,不要过分追求“丰富”,而是关注在技术深入度、问题解决能力的表现上。
没有实习经历,还有机会进...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务