Big O Algorithm Complexity Cheat Sheet
Big O Algorithm Complexity Cheat Sheet
Searching
Sorting
DataStructures
Heaps
Graphs
Chart
Comments
KnowThyComplexities!
Hithere!ThiswebpagecoversthespaceandtimeBigOcomplexitiesofcommonalgorithmsusedinComputerScience.Whenpreparing
fortechnicalinterviewsinthepast,Ifoundmyselfspendinghourscrawlingtheinternetputtingtogetherthebest,average,andworstcase
complexitiesforsearchandsortingalgorithmssothatIwouldn'tbestumpedwhenaskedaboutthem.Overthelastfewyears,I've
interviewedatseveralSiliconValleystartups,andalsosomebiggercompanies,likeYahoo,eBay,LinkedIn,andGoogle,andeachtime
thatIpreparedforaninterview,Ithoughttomyself"Whyohwhyhasn'tsomeonecreatedaniceBigOcheatsheet?".So,tosaveallof
youfinefolksatonoftime,Iwentaheadandcreatedone.Enjoy!
Good Fair Poor
Searching
Algorithm
DataStructure
TimeComplexity
Average
DepthFirstSearch(DFS)
BreadthFirstSearch(BFS)
Binarysearch
Linear(BruteForce)
ShortestpathbyDijkstra,
usingaMinheapaspriorityqueue
ShortestpathbyDijkstra,
usinganunsortedarrayaspriority
queue
ShortestpathbyBellmanFord
Graphof|V|verticesand|E|
edges
Graphof|V|verticesand|E|
edges
Sortedarrayofnelements
Array
Graphwith|V|verticesand|E|
edges
Worst
Space
Complexity
Worst
O(|E|+|V|)
O(|V|)
O(|E|+|V|)
O(|V|)
O(log(n))
O(log(n))
O(1)
O(n)
O(n)
O(1)
O((|V|+|E|)log
|V|)
O((|V|+|E|)log
|V|)
O(|V|)
Graphwith|V|verticesand|E|
edges
O(|V|^2)
O(|V|^2)
O(|V|)
Graphwith|V|verticesand|E|
edges
O(|V||E|)
O(|V||E|)
O(|V|)
MoreCheatSheets
GameofThronesCheatSheet
HTML5CanvasCheatSheet
Sorting
HTML5CanvasCheatSheet
Algorithm
Data
Structure
TimeComplexity
Best
Average Worst
WorstCaseAuxiliarySpace
Complexity
Worst
Quicksort Array
O(n
log(n))
O(n
log(n))
O(n^2)
O(n)
Mergesort Array
O(n
log(n))
O(n
log(n))
O(n
log(n))
O(n)
O(n
O(n
O(n
Heapsort
Bubble
Sort
Insertion
Sort
SelectSort
Bucket
Sort
RadixSort
Array
log(n))
log(n))
log(n))
O(1)
Array
O(n)
O(n^2)
O(n^2)
O(1)
Array
O(n)
O(n^2)
O(n^2)
O(1)
Array
O(n^2)
O(n^2)
O(n^2)
O(1)
Array
O(n+k)
O(n+k)
O(n^2)
O(nk)
Array
O(nk)
O(nk)
O(nk)
O(n+k)
DataStructures
DataStructure
TimeComplexity
Indexing
BasicArray
O(1)
DynamicArray
O(1)
SinglyLinkedList O(n)
DoublyLinkedList O(n)
SkipList
O(log(n))
HashTable
BinarySearchTree O(log(n))
CartresianTree
BTree
O(log(n))
RedBlackTree
O(log(n))
SplayTree
AVLTree
O(log(n))
Average
Search Insertion Deletion Indexing
Worst
Search Insertion Deletion
SpaceComplexity
Worst
O(n)
O(1)
O(n)
O(n)
O(n)
O(n)
O(n)
O(1)
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(1)
O(1)
O(n)
O(n)
O(1)
O(1)
O(n)
O(n)
O(n)
O(n)
O(nlog(n))
O(1)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(n)
O(1)
O(1)
Heaps
Heaps
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(log(n)) O(log(n))
O(m+n)
O(log(n)) O(log(n))
O(log(n))
O(log(n)) O(log(n))
O(log(n))
O(1)
O(log(n))*
O(1)*
O(1)
Storage
AddVertex
O(log(n))* O(1)
Graphs
Node/EdgeManagement
Adjacencylist
Incidencelist
Adjacencymatrix
Incidencematrix
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|)
Notationforasymptoticgrowth
letter
(theta)
bound
upperandlower,tight[1]
growth
(bigoh)O
(smalloh)o
upper,tightnessunknown lessthanorequal[3]
upper,nottight
lessthan
equal[2]
BigOComplexityChart
Thisinteractivechart,createdbyourfriendsoveratMeteorCharts,showsthenumberofoperations(yaxis)requiredtoobtainaresultas
thenumberofelements(xaxis)increase.O(n!)istheworstcomplexitywhichrequires720operationsforjust6elements,whileO(1)is
thebestcomplexity,whichonlyrequiresaconstantnumberofoperationsforanynumberofelements.
Contributors
Editthesetables!
1. EricRowell
2. QuentinPleple
3. NickDizazzo
4. MichaelAbed
5. AdamForsyth
6. JayEngineer
7. JoshDavis