Big O

23 Dec 2019

Different data structures and algorithms provide varying inherent performance characteristics which will result in a downstream performance outcome on the systems which use them.

Selection of the best possible data structures and sorting algorithms, will aid fast application performance, by avoiding slow alternatives.

Data Structures

Legend

Data Structure Legend

Type Seek
(average)
Search
(average)
Insert
(average)
Delete
(average)
Seek
(worst)
Search
(worst)
Insert
(worst)
Delete
(worst)
Space Complexity
(worst)
Array O(1) O(n) O(n) O(n) O(1) O(n) O(n) O(n) O(n)
Stack O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
Queue O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
Singly Linked List O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
Doubly Linked List O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
Skip List O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(n) O(n) O(n) O(n log(n))
Hash Table N/A O(1) O(1) O(1) N/A O(n) O(n) O(n) O(n)
Binary Search Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(n) O(n) O(n) O(n)
Cartesian Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) N/A O(n) O(n) O(n) O(n)
B-Tree N/A O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Red-Black Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Splay Tree N/A O(log(n)) O(log(n)) O(log(n)) N/A O(log(n)) O(log(n)) O(log(n)) O(n)
AVL Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
KD Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n) O(n) O(n) O(n) O(n)

Array Sorting

Legend

Data Structure Legend

Type Time
(best)
Time
(average)
Time
(worst)
Space Complexity
worst
Quicksort O(n log(n)) O(n log(n)) O(n<sup>2</sup>) O(n log(n))
Merge sort O(n log(n)) O(n log(n)) O(n log(n)) O(n log(n))
Timsort O(n) O(n log(n)) O(n log(n)) O(n)
Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(n log(n))
Bubble Sort O(n) O(n<sup>2</sup>) O(n<sup>2</sup>) O(n)
Insertion Sort O(n) O(n<sup>2</sup>) O(n<sup>2</sup>) O(n)
Selection Sort O(n<sup>2</sup>) O(n<sup>2</sup>) O(n<sup>2</sup>) O(n<sup>2</sup>)
Tree Sort O(n log(n)) O(n log(n)) O(n<sup>2</sup>) O(n log(n))
Shell Sort O(n log(n)) O(n<sup>2</sup>) O(n<sup>2</sup>) O(n log(n))
Bucket Sort O(n + k) O(n + k) O(n<sup>2</sup>) O(n + k)
Radix Sort O(n + k) O(n + k) O(n + k) O(n + k)
Counting Sort O(n + k) O(n + k) O(n + k) O(n + k)
Cubesort O(n) O(n log(n)) O(n log(n)) O(n log(n))