ChoralSoft Learn

Printable cheat sheets

One page each. Choose a sheet, then print it or save it as a PDF.

Big-O and data structures

Typical costs for the structures you reach for most often. n is the number of items.

Growth rates, slowest growth first

ClassNameTypical example
O(1)ConstantArray lookup by index, hash table lookup (average)
O(log n)LogarithmicBinary search, balanced tree lookup, heap insert
O(n)LinearScan a list, build a heap
O(n log n)LinearithmicMerge sort, heap sort, quicksort (average)
O(n²)QuadraticCompare every pair, simple sorts
O(2ⁿ)ExponentialTry every subset
O(n!)FactorialTry every ordering

Data structure operations

StructureAccess / searchInsertDeleteNotes
ArrayO(1) by index, O(n) searchO(n) in the middle, O(1) amortized at the endO(n)Contiguous memory, cache friendly
Linked listO(n)O(1) at a known nodeO(1) at a known nodeNo random access
Hash tableO(1) average, O(n) worstO(1) averageO(1) averageNo ordering of keys
Stack / queueO(n) searchO(1) push / enqueueO(1) pop / dequeueLIFO / FIFO
Binary heapO(1) peek min or maxO(log n)O(log n) for the rootBuild from a list in O(n)
Balanced BSTO(log n)O(log n)O(log n)Keeps keys sorted; unbalanced worst case is O(n)
TrieO(L) for a key of length LO(L)O(L)Great for prefixes

From ChoralSoft, choralsoft.com/learn/cheatsheets/. Free to print and share.