0% found this document useful (0 votes)
287 views

Know Thy Complexities!: Big-O Complexity Chart

The document provides a summary of time and space complexities for common data structures and algorithms. It includes big-O complexities for operations on arrays, stacks, queues, linked lists, trees, graphs, and sorting algorithms like quicksort, heapsort, and mergesort. The complexities range from O(1) and O(log n) for efficient operations to O(n^2) for less efficient algorithms. It serves as a reference sheet for understanding how algorithms scale with input size.

Uploaded by

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

Know Thy Complexities!: Big-O Complexity Chart

The document provides a summary of time and space complexities for common data structures and algorithms. It includes big-O complexities for operations on arrays, stacks, queues, linked lists, trees, graphs, and sorting algorithms like quicksort, heapsort, and mergesort. The complexities range from O(1) and O(log n) for efficient operations to O(n^2) for less efficient algorithms. It serves as a reference sheet for understanding how algorithms scale with input size.

Uploaded by

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

Know Thy Complexities!

www.bigocheatsheet.com

Big-O Complexity Chart


Excellent

O(n!) O(2^n)

Good

Fair

Bad

Horrible

O(n^2)

Operations

O(n log n)

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

Elements

Common Data Structure Operations


Data Structure

Space
Complexity

Time Complexity
Average
Access

Worst
Search

Insertion

Deletion

Worst

Access

Search

Insertion

Deletion

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)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

O(n)

O(n)

O(n)

O(n log(n))

Skip List
Hash Table

N/A

O(1)

O(1)

O(1)

N/A

O(n)

O(n)

O(n)

O(n)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

O(n)

O(n)

O(n)

O(n)

N/A

O(log(n))

O(log(n))

O(log(n))

N/A

O(n)

O(n)

O(n)

O(n)

B-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)

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)

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)

Binary Search Tree


Cartesian Tree

Splay Tree

Array Sorting Algorithms


Algorithm

Time Complexity
Best

Space Complexity

Average

Worst

Worst

Quicksort

O(n log(n))

O(n log(n))

O(n^2)

O(log(n))

Mergesort

O(n log(n))

O(n log(n))

O(n log(n))

O(n)

Timsort

O(n)

O(n log(n))

O(n log(n))

O(n)

O(n log(n))

O(n log(n))

O(n log(n))

O(1)

Bubble Sort

O(n)

O(n^2)

O(n^2)

O(1)

Insertion Sort

O(n)

O(n^2)

O(n^2)

O(1)

O(n^2)

O(n^2)

O(n^2)

O(1)

O(n log(n))

O(n log(n))

O(n^2)

O(n)

Heapsort

Selection Sort
Tree Sort
Shell Sort

Shell Sort
Bucket Sort

O(n log(n))

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

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

O(n+k)

O(n+k)

O(n^2)

O(n)

O(nk)

O(nk)

O(nk)

O(n+k)

Radix Sort
Counting Sort

O(1)

O(n+k)

O(n+k)

O(n+k)

O(k)

O(n)

O(n log(n))

O(n log(n))

O(n)

Cubesort

Graph Data Structure Operations


Data Structure

Time Complexity
Storage

Add Vertex

Add Edge

Remove Vertex Remove Edge Query

Adjacency list

O(|V|+|E|)

O(1)

O(1)

O(|V| + |E|)

O(|E|)

O(|V|)

Incidence list

O(|V|+|E|)

O(1)

O(1)

O(|E|)

O(|E|)

O(|E|)

O(|V|^2)

O(|V|^2)

O(1)

O(|V|^2)

O(1)

O(1)

O(|V| |E|)

O(|V| |E|)

O(|V| |E|)

O(|V| |E|)

O(|V| |E|)

O(|E|)

Adjacency matrix
Incidence matrix

Heap Data Structure Operations


Data Structure Time Complexity
Find Max

Extract Max

Increase Key Insert

Delete

Merge

Binary Heap

O(1)

O(log(n))

O(log(n))

O(log(n))

O(log(n))

Pairing Heap

O(1)

O(log(n))

O(log(n))

O(1)

O(log(n))

O(1)

Binomial Heap

O(1)

O(log(n))

O(log(n))

O(1)

O(log(n))

O(log(n))

Fibonacci Heap

O(1)

O(log(n))

O(1)

O(1)

O(log(n))

O(1)

Graph Algorithms
Algorithm

Time Complexity
Average

Space Complexity

Worst

Worst

Dijkstra's algorithm

O(|E| log |V|)

O(|V|^2)

A* search algorithm

O(|E|)

O(b^d)

O(b^d)

O(|E| log |V|)

O(|V|^2)

O(|V| + |E|)

O(|E| |V|)

O(|E| |V|)

O(|V|)

O(|V|^3)

O(|V|^3)

O(|V|^2)

O(|V| + |E|)

O(|V| + |E|)

O(|V| + |E|)

Prim's algorithm
BellmanFord algorithm
Floyd-Warshall algorithm
Topological sort

O(|V| + |E|)

O(m+n)

You might also like