Professional Documents
Culture Documents
DataStructures
Sorting
Graphs
Heaps
Chart
Comments
Tweet
2.7k
12K
Like
KnowThyComplexities!
Hithere!ThiswebpagecoversthespaceandtimeBigOcomplexitiesofcommonalgorithmsusedinComputer
Science.Whenpreparingfortechnicalinterviewsinthepast,Ifoundmyselfspendinghourscrawlingthe
internetputtingtogetherthebest,average,andworstcasecomplexitiesforsearchandsortingalgorithmssothatI
wouldn'tbestumpedwhenaskedaboutthem.Overthelastfewyears,I'veinterviewedatseveralSiliconValley
startups,andalsosomebiggercompanies,likeYahoo,eBay,LinkedIn,andGoogle,andeachtimethatIprepared
foraninterview,Ithoughttomyself"Whyhasn'tsomeonecreatedaniceBigOcheatsheet?".So,tosaveallof
youfinefolksatonoftime,Iwentaheadandcreatedone.Enjoy!Eric
Legend
Excellent Good Fair Bad Horrible
DataStructureOperations
Data
Structure
TimeComplexity
Access
Array
Stack
Singly
Linked
List
Doubly
Linked
List
Average
Search Insertion Deletion
Access
Worst
Search Insertion Deletion
Space
Complexity
Worst
O(1)
O(n)
O(n)
O(n)
O(1)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(n)
O(n)
O(n
log(n))
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
Hash
Table
Binary
Search
Tree
O(1)
O(1)
O(1)
Tree
Cartesian
Tree
BTree
Red
Black
Tree
Splay
Tree
AVLTree
O(n)
O(n)
O(n)
O(n)
ArraySortingAlgorithms
Algorithm
Best
Quicksort
Mergesort
Timsort
Heapsort
BubbleSort
InsertionSort
SelectionSort
ShellSort
BucketSort
RadixSort
TimeComplexity
Average
Worst
SpaceComplexity
Worst
O(nlog(n)) O(nlog(n))
O(n^2)
O(log(n))
O(nlog(n)) O(nlog(n))
O(nlog(n))
O(n)
O(n)
O(nlog(n))
O(nlog(n))
O(n)
O(nlog(n)) O(nlog(n))
O(nlog(n))
O(1)
O(n)
O(n^2)
O(n^2)
O(1)
O(n)
O(n^2)
O(n^2)
O(1)
O(n^2)
O(n^2)
O(n^2)
O(1)
O(n)
O(n+k)
O(n+k)
O(n^2)
O(n)
O(nk)
O(nk)
O(nk)
O(n+k)
GraphOperations
Node/EdgeManagement
Adjacencylist
Incidencelist
Adjacencymatrix
Incidencematrix
Storage
O(|V|+|E|)
O(1)
O(1)
O(|V|+|E|)
O(|E|)
O(|V|)
O(|V|+|E|)
O(1)
O(1)
O(|E|)
O(|E|)
O(|E|)
O(|V|^2)
O(|V|^2)
O(1)
O(|V|^2)
O(1)
O(1)
O(|V||E|)
O(|E|)
HeapOperations
Type
TimeComplexity
Heapify FindMax ExtractMax IncreaseKey Insert
LinkedList(sorted)
LinkedList(unsorted)
BinaryHeap
O(n)
BinomialHeap
FibonacciHeap
Delete
Merge
O(1)
O(1)
O(n)
O(n)
O(1)
O(m+n)
O(n)
O(n)
O(1)
O(1)
O(1)
O(1)
O(1)
O(log(n))
O(log(n))
O(1)
O(log(n))
O(log(n))
O(1)
O(log(n)) O(log(n))
O(1)
O(log(n))
O(1)
O(1)
O(log(n)) O(1)
BigOComplexityChart
RecommendedReading
CrackingtheCodingInterview:150ProgrammingQuestionsandSolutions
IntroductiontoAlgorithms,3rdEdition
DataStructuresandAlgorithmsinJava(2ndEdition)
HighPerformanceJavaScript(BuildFasterWebApplicationInterfaces)
Contributors
1.EricRowell,founderofCoderLifestyle
2.QuentinPleple
3.MichaelAbed
4.NickDizazzo
5.AdamForsyth
6.DavidDorfman
7.JayEngineer
8.JenniferHamon
9.JoshDavis
10.NodirTurakulov
11.BartMassey
12.VinnieMagro
13.MiguelAmigot
14.DrewBailey
15.AneelNazareth
16.RahulChowdhury
17.RobertBurke
18.steven41292
19.BrandonAmos
20.MikeDavis
21.CasperVanGheluwe
22.JoelFriedly