100% found this document useful (1 vote)
497 views

Big O Algorithm Complexity Cheat Sheet

This document provides a summary of time and space complexities for common algorithms used in computer science. It includes tables summarizing the Big-O complexities of searching, sorting, data structures like trees and graphs, and other algorithms. The introduction explains that the author created this "Big-O cheat sheet" to help efficiently prepare for technical interviews.

Uploaded by

Shreyans Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
497 views

Big O Algorithm Complexity Cheat Sheet

This document provides a summary of time and space complexities for common algorithms used in computer science. It includes tables summarizing the Big-O complexities of searching, sorting, data structures like trees and graphs, and other algorithms. The introduction explains that the author created this "Big-O cheat sheet" to help efficiently prepare for technical interviews.

Uploaded by

Shreyans Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BigOCheatSheet

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(log(n)) O(log(n)) O(log(n)) O(n)

O(n)

O(n)

O(n)

O(nlog(n))

O(1)

O(n)

O(n)

O(n)

O(n)

O(log(n)) O(log(n)) O(log(n)) O(n)

O(n)

O(n)

O(n)

O(n)

O(log(n)) O(log(n)) O(log(n))

O(n)

O(n)

O(n)

O(n)

O(1)

O(1)

O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)


O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
O(log(n)) O(log(n)) O(log(n))

O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

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

AddEdge RemoveVertex RemoveEdge Query

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|)

O(|V||E|) O(|V||E|) O(|V||E|) O(|V||E|)

Notationforasymptoticgrowth
letter
(theta)

bound
upperandlower,tight[1]

growth

(bigoh)O
(smalloh)o

upper,tightnessunknown lessthanorequal[3]
upper,nottight
lessthan

equal[2]

(bigomega) lower,tightnessunknown greaterthanorequal


(smallomega) lower,nottight
greaterthan
[1]BigOistheupperbound,whileOmegaisthelowerbound.ThetarequiresbothBigOandOmega,sothat'swhyit'sreferredtoasa
tightbound(itmustbeboththeupperandlowerbound).Forexample,analgorithmtakingOmega(nlogn)takesatleastnlogntimebut
hasnoupperlimit.AnalgorithmtakingTheta(nlogn)isfarpreferentialsinceittakesATLEASTnlogn(Omeganlogn)andNOMORE
THANnlogn(BigOnlogn).SO
[2]f(x)=(g(n))meansf(therunningtimeofthealgorithm)growsexactlylikegwhenn(inputsize)getslarger.Inotherwords,the
growthrateoff(x)isasymptoticallyproportionaltog(n).
[3]Samething.Herethegrowthrateisnofasterthang(n).bigohisthemostusefulbecauserepresentstheworstcasebehavior.
Inshort,ifalgorithmis__thenitsperformanceis__
algorithm performance
o(n)
<n
O(n)
n
(n)
=n
(n)
n
(n)
>n

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

You might also like