• 欢迎访问马东东的博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

每个程序员都应该收藏的算法复杂度速查表

算法 马 东东 来源:linux.cn 2年前 (2017-05-06) 1006次浏览 3个评论 扫描二维码

算法复杂度这件事

这篇文章覆盖了计算机科学里面常见算法的时间和空间的大 OBig-O 复杂度。我之前在参加面试前,经常需要花费很多时间从互联网上查找各种搜索和排序算法的优劣,以便我在面试时不会被问住。最近这几年,我面试了几家硅谷的初创企业和一些更大一些的公司,如 Yahoo、eBay、LinkedIn 和 Google,每次我都需要准备这个,我就在问自己,“为什么没有人创建一个漂亮的大 O 速查表呢?”所以,为了节省大家的时间,我就创建了这个,希望你喜欢!

— Eric

 

图例

绝佳不错一般不佳糟糕

 

数据结构操作

数据结构时间复杂度空间复杂度
 平均最差最差
 访问搜索插入删除访问搜索插入删除 
ArrayO(1)O(n)O(n)O(n)O(1)O(n)O(n)O(n)O(n)
StackO(n)O(n)O(1)O(1)O(n)O(n)O(1)O(1)O(n)
Singly-Linked ListO(n)O(n)O(1)O(1)O(n)O(n)O(1)O(1)O(n)
Doubly-Linked ListO(n)O(n)O(1)O(1)O(n)O(n)O(1)O(1)O(n)
Skip ListO(log(n))O(log(n))O(log(n))O(log(n))O(n)O(n)O(n)O(n)O(n log(n))
Hash TableO(1)O(1)O(1)O(n)O(n)O(n)O(n)
Binary Search TreeO(log(n))O(log(n))O(log(n))O(log(n))O(n)O(n)O(n)O(n)O(n)
Cartesian TreeO(log(n))O(log(n))O(log(n))O(n)O(n)O(n)O(n)
B-TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
Red-Black TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
Splay TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
AVL TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)

 

数组排序算法

算法时间复杂度空间复杂度
 最佳平均最差最差
QuicksortO(n log(n))O(n log(n))O(n^2)O(log(n))
MergesortO(n log(n))O(n log(n))O(n log(n))O(n)
TimsortO(n)O(n log(n))O(n log(n))O(n)
HeapsortO(n log(n))O(n log(n))O(n log(n))O(1)
Bubble SortO(n)O(n^2)O(n^2)O(1)
Insertion SortO(n)O(n^2)O(n^2)O(1)
Selection SortO(n^2)O(n^2)O(n^2)O(1)
Shell SortO(n)O((nlog(n))^2)O((nlog(n))^2)O(1)
Bucket SortO(n+k)O(n+k)O(n^2)O(n)
Radix SortO(nk)O(nk)O(nk)O(n+k)

 

图操作

节点 / 边界管理存储增加顶点增加边界移除顶点移除边界查询
Adjacency listO(|V|+|E|)O(1)O(1)O(|V| + |E|)O(|E|)O(|V|)
Incidence listO(|V|+|E|)O(1)O(1)O(|E|)O(|E|)O(|E|)
Adjacency matrixO(|V|^2)O(|V|^2)O(1)O(|V|^2)O(1)O(1)
Incidence matrixO(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|E|)

 

堆操作

类型时间复杂度
 Heapify查找最大值分离最大值提升键插入删除合并
Linked List (sorted)O(1)O(1)O(n)O(n)O(1)O(m+n)
Linked List (unsorted)O(n)O(n)O(1)O(1)O(1)O(1)
Binary HeapO(n)O(1)O(log(n))O(log(n))O(log(n))O(log(n))O(m+n)
Binomial HeapO(1)O(log(n))O(log(n))O(1)O(log(n))O(log(n))
Fibonacci HeapO(1)O(log(n))O(1)O(1)O(log(n))O(1)

 

大 O 复杂度图表

每个程序员都应该收藏的算法复杂度速查表

 

推荐阅读

 

贡献者

  1. Eric Rowell, creator of Concrete.js, an HTML5 Canvas Framework
  2. Quentin Pleple
  3. Michael Abed
  4. Nick Dizazzo
  5. Adam Forsyth
  6. David Dorfman
  7. Jay Engineer
  8. Jennifer Hamon
  9. Josh Davis
  10. Nodir Turakulov
  11. Bart Massey
  12. Vinnie Magro
  13. Miguel Amigot
  14. Drew Bailey
  15. Aneel Nazareth
  16. Rahul Chowdhury
  17. Robert Burke
  18. steven41292
  19. Brandon Amos
  20. Mike Davis
  21. Casper Van Gheluwe
  22. Joel Friedly
  23. Oleg
  24. Renfred Harper
  25. Piper Chester
  26. Eric Lefevre-Ardant
  27. Jonathan McElroy
  28. Si Pham
  29. mcverry
  30. Max Hoffmann
  31. Alejandro Ramirez
  32. Damon Davison
  33. Alvin Wan
  34. Alan Briolat
  35. Drew Hannay
  36. Andrew Rasmussen
  37. Dennis Tsang
  38. Bahador Saket

版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明文章地址:https://www.madongdong.me/technology/basic-computer/algorithm/2017/05/06/574/mdd/
喜欢 (0)
[821300079@qq.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到
(3)个小伙伴在吐槽
  1. Well I guess I don't have to spend the weekend fiigurng this one out!
    匿名2018-10-05 22:29 回复 Windows 7 | Firefox浏览器 41.0
  2. 马 东东
    签到成功!签到时间:2017-05-06 17:15:50,每日打卡,生活更精彩哦~
    马 东东2017-05-06 17:16 回复 Windows 10 | Chrome 58.0.3029.96
    • Going to put this aritlce to good use now.
      匿名2018-10-05 21:11 回复 Windows 7 | Chrome 40.0.2214.111