0% found this document useful (0 votes)
77 views7 pages

Big O Cheatsheet

The document summarizes the time and space complexities of various searching, sorting, and data structure algorithms. For searching, it lists the complexities of depth-first search, breadth-first search, binary search, linear search, and shortest path algorithms. For sorting it covers quicksort, mergesort, heapsort, insertion sort, bucket sort, and radix sort. It also provides complexity analyses for common data structures like arrays, linked lists, hash tables, binary search trees, heaps, and graphs.

Uploaded by

Dan-Cristian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views7 pages

Big O Cheatsheet

The document summarizes the time and space complexities of various searching, sorting, and data structure algorithms. For searching, it lists the complexities of depth-first search, breadth-first search, binary search, linear search, and shortest path algorithms. For sorting it covers quicksort, mergesort, heapsort, insertion sort, bucket sort, and radix sort. It also provides complexity analyses for common data structures like arrays, linked lists, hash tables, binary search trees, heaps, and graphs.

Uploaded by

Dan-Cristian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 7

source: http://bigocheatsheet.

com/
Searching
Algorithm Data Structure Time Complexity Space Complexity

Average Worst Worst


Graph of |V|
Depth First
Search (DFS) vertices and |E| - O(|E| + |V|) O(|V|)
edges
Graph of |V|
Breadth First
Search (BFS) vertices and |E| - O(|E| + |V|) O(|V|)
edges
Sorted array of
Binary search n elements O(log(n)) O(log(n)) O(1)

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

Best Average Worst Worst

Quicksort Array O(n log(n)) O(n log(n)) O(n^2) O(n)

Mergesort Array O(n log(n)) O(n log(n)) O(n log(n)) O(n)

Heapsort Array O(n log(n)) O(n log(n)) O(n log(n)) O(1)

Bubble Sort Array O(n) O(n^2) O(n^2) O(1)

Insertion Sort Array O(n) O(n^2) O(n^2) O(1)

Select Sort Array O(n^2) O(n^2) O(n^2) O(1)

Bucket Sort Array O(n+k) O(n+k) O(n^2) O(nk)


Radix Sort Array O(nk) O(nk) O(nk) O(n+k)

Data Structures
Time
Data Structure Complexity

Average Wo

Indexing Search Insertion Deletion Indexing

Basic Array O(1) O(n) - - O(1)

Dynamic Array O(1) O(n) O(n) O(n) O(1)

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)

Skip List O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

Hash Table - O(1) O(1) O(1) -

Binary Search
Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)

Cartresian Tree - O(log(n)) O(log(n)) O(log(n)) -

B-Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n))

Red-Black Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n))

Splay Tree - O(log(n)) O(log(n)) O(log(n)) -

AVL Tree O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n))

Heaps
Time
Heaps Complexity

Heapify Find Max Extract Max Increase Key Insert

Linked List
(sorted) - O(1) O(1) O(n) O(n)
Linked List
(unsorted) - O(n) O(n) O(1) O(1)

Binary Heap O(n) O(1) O(log(n)) O(log(n)) O(log(n))

Binomial Heap - O(log(n)) O(log(n)) O(log(n)) O(log(n))

Fibonacci Heap - O(1) O(log(n))* O(1)* O(1)

Graphs
Node / Edge Storage Add Vertex Remove Vertex
Management

Adjacency list O(|V|+|E|) O(1) O(1) O(|V| + |E|) O(|E|)

Incidence list O(|V|+|E|) O(1) O(1) O(|E|) O(|E|)

Adjacency matrix O(|V|^2) O(|V|^2) O(1) O(|V|^2) O(1)

Incidence matrix O(|V| |E|) O(|V| |E|) O(|V| |E|) O(|V| |E|) O(|V| |E|)
y Space Complexity
Space Complexity

Worst Worst

Search Insertion Deletion

O(n) - - O(n)

O(n) O(n) O(n) O(n)

O(n) O(1) O(1) O(n)

O(n) O(1) O(1) O(n)

O(n) O(n) O(n) O(n log(n))

O(n) O(n) O(n) O(n)

O(n) O(n) O(n) O(n)

O(n) O(n) O(n) O(n)

O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(n)) O(n)

O(log(n)) O(log(n)) O(log(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|)

You might also like