Big O Cheatsheet
Big O Cheatsheet
com/
Searching
Algorithm Data Structure Time Complexity Space Complexity
Linear (Brute
Force) Array O(n) O(n) O(1)
Shortest path by Graph with |V|
Dijkstra,using a
Min-heap as O((|V| + |E|) logO((|V|
vertices and |E| |V|) + |E|) log |V|) O(|V|)
Shortest edges
priority path
queueby Graph with |V|
Dijkstra,using an
unsorted array as vertices and |E| O(|V|^2) O(|V|^2) O(|V|)
edges
priority queue Graph with |V|
Shortest path by
Bellman-Ford vertices and |E| O(|V||E|) O(|V||E|) O(|V|)
edges
Sorting
Algorithm Data Structure Time Complexity Worst Case Auxiliary Space Complexity
Data Structures
Time
Data Structure Complexity
Average Wo
Singly-Linked
List O(n) O(n) O(1) O(1) O(n)
Doubly-Linked
List O(n) O(n) O(1) O(1) O(n)
Binary Search
Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Heaps
Time
Heaps Complexity
Linked List
(sorted) - O(1) O(1) O(n) O(n)
Linked List
(unsorted) - O(n) O(n) O(1) O(1)
Graphs
Node / Edge Storage Add Vertex Remove Vertex
Management
Incidence matrix O(|V| |E|) O(|V| |E|) O(|V| |E|) O(|V| |E|) O(|V| |E|)
y Space Complexity
Space Complexity
Worst Worst
O(n) - - O(n)
Delete Merge
O(1) O(m+n)
O(1) O(1)
O(log(n)) O(m+n)
O(log(n)) O(log(n))
O(log(n))* O(1)
O(|V|)
O(|E|)
O(1)
O(|E|)