Sei sulla pagina 1di 2

Know Thy Complexities!

www.bigocheatsheet.com

Big-O Complexity Chart


Horrible Bad Fair Good Excellent

O(n^2)

O(n log n)

Operations

O(n!) O(2^n)

O(n)
O(log n), O(1)

Elements

Common Data Structure Operations


Data Structure

Time Complexity

Space Complexity

Average

Worst

Worst

Access Search Insertion Deletion Access Search Insertion Deletion


Array
Stack
Queue
Singly-Linked List
Doubly-Linked List
Skip List
Hash Table
Binary Search Tree
Cartesian Tree
B-Tree
Red-Black Tree
Splay Tree
AVL Tree
KD Tree

(1)

(n)

(n)

(n)

O(1)

O(n)

O(n)

O(n)

O(n)

(n)

(n)

(1)

(1)

O(n)

O(n)

O(1)

O(1)

O(n)

(n)

(n)

(1)

(1)

O(n)

O(n)

O(1)

O(1)

O(n)

(n)

(n)

(1)

(1)

O(n)

O(n)

O(1)

O(1)

O(n)

(n)

(n)

(1)

(1)

O(n)

O(n)

O(1)

O(1)

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(n)

O(n)

O(n)

O(n)

O(n log(n))

N/A

(1)

(1)

(1)

N/A

O(n)

O(n)

O(n)

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(n)

O(n)

O(n)

O(n)

O(n)

N/A

(log(n))

(log(n))

(log(n))

N/A

O(n)

O(n)

O(n)

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

N/A

(log(n))

(log(n))

(log(n))

N/A

O(log(n))

O(log(n))

O(log(n))

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

(log(n))

(log(n))

(log(n))

(log(n))

O(n)

O(n)

O(n)

O(n)

O(n)

Array Sorting Algorithms


Algorithm

Time Complexity
Best

Quicksort
Mergesort
Timsort
Heapsort
Bubble Sort
Insertion Sort
Selection Sort
Tree Sort
Shell Sort
Bucket Sort
Radix Sort
Counting Sort
Cubesort

Average

Space Complexity
Worst

Worst

(n log(n))

(n log(n))

O(n^2)

O(log(n))

(n log(n))

(n log(n))

O(n log(n))

O(n)

(n)

(n log(n))

O(n log(n))

O(n)

(n log(n))

(n log(n))

O(n log(n))

O(1)

(n)

(n^2)

O(n^2)

O(1)

(n)

(n^2)

O(n^2)

O(1)

(n^2)

(n^2)

O(n^2)

O(1)

(n log(n))

(n log(n))

O(n^2)

O(n)

(n log(n)) (n(log(n))^2) O(n(log(n))^2)

O(1)

(n+k)

(n+k)

O(n^2)

O(n)

(nk)

(nk)

O(nk)

O(n+k)

(n+k)

(n+k)

O(n+k)

O(k)

(n)

(n log(n))

O(n log(n))

O(n)