Skip to content

Algorithms Reference

Published: at 12:00 AM

Sorting / Searching

AlgorithmTime(Best)Time(Average)Time(Worst)Space(Worst)
Linear SearchΩ(1)Θ(n)O(n)O(1)
Binary SearchΩ(1)Θ(log(n))O(log(n))O(1)
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)

Data Structures

AverageWorst
StructureAccessSearchInsertDeleteAccessSearchInsert/Delete
ArrayO(1)O(n)O(n)O(n)O(1)O(n)O(n)
StackO(n)O(n)O(1)O(1)O(n)O(n)O(1)
QueueO(n)O(n)O(1)O(1)O(n)O(n)O(1)
Singly-Linked ListO(n)O(n)O(1)O(1)O(n)O(n)O(1)
Doubly-Linked ListO(n)O(n)O(1)O(1)O(n)O(n)O(1)
Skip ListO(log(n))O(log(n))O(log(n))O(log(n))O(n)O(n)O(n)
Hash TableO(1)O(1)O(1)O(n)O(n)
BSTO(log(n))O(log(n))O(log(n))O(log(n))O(n)O(n)O(n)
Cartesian TreeO(log(n))O(log(n))O(log(n))O(n)O(n)
B-TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))
Red-Black TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))
Splay TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))
AVL TreeO(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))O(log(n))
KD TreeO(log(n))O(log(n))O(log(n))O(log(n))O(n)O(n)O(n)