Complexities Table

Know Thy Complexities!

Hi there!  This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science.  When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting together the best, average, and worst case complexities for search and sorting algorithms so that I wouldn't be stumped when asked about them.  Over the last few years, I've interviewed at several Silicon Valley startups, and also some bigger companies, like Google, Facebook, Yahoo, LinkedIn, and eBay, and each time that I prepared for an interview, I thought to myself "Why hasn't someone created a nice Big-O cheat sheet?".  So, to save all of you fine folks a ton of time, I went ahead and created one.  Enjoy! - Eric

If you're trying to catch them all, you might also check out the Pokemon Go Evolution Chart.

Big-O Complexity Chart

HorribleBadFairGoodExcellent
O(log n), O(1)O(n)O(n log n)O(n^2)O(2^n)O(n!)OperationsElements

Common Data Structure Operations

Data Structure Time Complexity Space Complexity
  Average Worst Worst
  Access Search Insertion Deletion Access Search Insertion Deletion  
ArrayΘ(1)Θ(n)Θ(n)Θ(n)O(1)O(n)O(n)O(n)O(n)
StackΘ(n)Θ(n)Θ(1)Θ(1)O(n)O(n)O(1)O(1)O(n)
QueueΘ(n)Θ(n)Θ(1)Θ(1)O(n)O(n)O(1)O(1)O(n)
Singly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)O(n)O(1)O(1)O(n)
Doubly-Linked ListΘ(n)Θ(n)Θ(1)Θ(1)O(n)O(n)O(1)O(1)O(n)
Skip ListΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)O(n)O(n)O(n)O(n log(n))
Hash TableN/AΘ(1)Θ(1)Θ(1)N/AO(n)O(n)O(n)O(n)
Binary Search TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)O(n)O(n)O(n)O(n)
Cartesian TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))N/AO(n)O(n)O(n)O(n)
B-TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
Red-Black TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
Splay TreeN/AΘ(log(n))Θ(log(n))Θ(log(n))N/AO(log(n))O(log(n))O(log(n))O(n)
AVL TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(n)
KD TreeΘ(log(n))Θ(log(n))Θ(log(n))Θ(log(n))O(n)O(n)O(n)O(n)O(n)

Array Sorting Algorithms

Algorithm Time Complexity Space Complexity
  Best Average Worst Worst
QuicksortΩ(n log(n))Θ(n log(n))O(n^2)O(log(n))
MergesortΩ(n log(n))Θ(n log(n))O(n log(n))O(n)
TimsortΩ(n)Θ(n log(n))O(n log(n))O(n)
HeapsortΩ(n log(n))Θ(n log(n))O(n log(n))O(1)
Bubble SortΩ(n)Θ(n^2)O(n^2)O(1)
Insertion SortΩ(n)Θ(n^2)O(n^2)O(1)
Selection SortΩ(n^2)Θ(n^2)O(n^2)O(1)
Tree SortΩ(n log(n))Θ(n log(n))O(n^2)O(n)
Shell SortΩ(n log(n))Θ(n(log(n))^2)O(n(log(n))^2)O(1)
Bucket SortΩ(n+k)Θ(n+k)O(n^2)O(n)
Radix SortΩ(nk)Θ(nk)O(nk)O(n+k)
Counting SortΩ(n+k)Θ(n+k)O(n+k)O(k)
CubesortΩ(n)Θ(n log(n))O(n log(n))O(n)



Learn More

Get the Official Big-O Cheat Sheet Poster

Contributors

  1. Eric Rowell 
  2. Quentin Pleple 
  3. Michael Abed 
  4. Nick Dizazzo 
  5. Adam Forsyth 
  6. Felix Zhu 
  7. Jay Engineer 
  8. Josh Davis 
  9. Nodir Turakulov 
  10. Jennifer Hamon
  11. David Dorfman 
  12. Bart Massey 
  13. Ray Pereda 
  14. Si Pham 
  15. Mike Davis 
  16. mcverry 
  17. Max Hoffmann 
  18. Bahador Saket 
  19. Damon Davison 
  20. Alvin Wan 
  21. Alan Briolat
  22. Drew Hannay 
  23. Andrew Rasmussen 
  24. Dennis Tsang 
  25. Vinnie Magro 
  26. Adam Arold 
  27. Alejandro Ramirez 
  28. Aneel Nazareth 
  29. Rahul Chowdhury
  30. Jonathan McElroy 
  31. steven41292 
  32. Brandon Amos 
  33. Joel Friedly 
  34. Casper Van Gheluwe 
  35. Eric Lefevre-Ardant 
  36. Oleg 
  37. Renfred Harper 
  38. Piper Chester
  39. Miguel Amigot 
  40. Apurva K 
  41. Matthew Daronco 
  42. Yun-Cheng Lin 
  43. Clay Tyler 
  44. Orhan Can Ozalp 
  45. Ayman Singh 
  46. David Morton 
  47. Aurelien Ooms
  48. Sebastian Paaske Torholm 
  49. Koushik Krishnan 
  50. Drew Bailey 
  51. Robert Burke

Make this Page Better

Edit these tables!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值