0% found this document useful (0 votes)
46 views6 pages

Big O Cheatsheet

This document provides a summary of common algorithms and data structures, including their time and space complexities. It covers searching and sorting algorithms like depth-first search, breadth-first search, binary search, and quicksort. It also covers data structures like arrays, linked lists, hash tables, binary search trees, and graphs. For each algorithm or data structure, it lists the associated data structure, time complexity, space complexity, and other relevant details.

Uploaded by

sgtb3
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)
46 views6 pages

Big O Cheatsheet

This document provides a summary of common algorithms and data structures, including their time and space complexities. It covers searching and sorting algorithms like depth-first search, breadth-first search, binary search, and quicksort. It also covers data structures like arrays, linked lists, hash tables, binary search trees, and graphs. For each algorithm or data structure, it lists the associated data structure, time complexity, space complexity, and other relevant details.

Uploaded by

sgtb3
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/ 6

source: http://bigocheatsheet.

com/
Searching
Algorithm

Data Structure
Depth First Search (DFS)
Breadth First Search (BFS)
Binary search
Linear (Brute Force)

Shortest path by Dijkstra,using a Min-heap as priority queue


Shortest path by Dijkstra,using an unsorted array as priority queue
Shortest path by Bellman-Ford

Sorting
Algorithm

Graph of |V| vertices


and |E| edges
Graph of |V| vertices
and |E| edges
Sorted array of n
elements
Array
Graph with |V|
vertices and |E|
edges
Graph
with |V|
vertices and |E|
edges
Graph
with |V|
vertices and |E|
edges
Data Structure

Quicksort
Mergesort
Heapsort
Bubble Sort
Insertion Sort
Select Sort
Bucket Sort
Radix Sort

Array
Array
Array
Array
Array
Array
Array
Array

Data Structures
Data Structure

Time Complexity
Indexing
Basic Array
Dynamic Array
Singly-Linked List
Doubly-Linked List
Skip List
Hash Table
Binary Search Tree
Cartresian Tree
B-Tree
Red-Black Tree
Splay Tree
AVL Tree

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

Heaps
Heaps

Time Complexity
Heapify
Linked List (sorted)
Linked List (unsorted)
Binary Heap
Binomial Heap
Fibonacci Heap

O(n)
-

Graphs
Node / Edge Management

Storage
Adjacency list
Incidence list
Adjacency matrix
Incidence matrix

O(|V|+|E|)
O(|V|+|E|)
O(|V|^2)
O(|V| |E|)

Time Complexity
Average

Worst

Space Complexity
Worst

O(|E| + |V|)

O(|V|)

O(|E| + |V|)

O(|V|)

O(log(n))

O(log(n))

O(1)

O(n)

O(n)

O(1)

O((|V| + |E|) log |V|)O((|V| + |E|) log |V|)

O(|V|)

O(|V|^2)

O(|V|^2)

O(|V|)

O(|V||E|)

O(|V||E|)

O(|V|)

Time Complexity
Best

O(n log(n))
O(n log(n))
O(n log(n))
O(n)
O(n)
O(n^2)
O(n+k)
O(nk)

Average
Search

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

Average

O(n log(n))
O(n log(n))
O(n log(n))
O(n^2)
O(n^2)
O(n^2)
O(n+k)
O(nk)

Worst Case Auxiliary Space Complex


Worst
Worst

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

O(n)
O(n)
O(1)
O(1)
O(1)
O(1)
O(nk)
O(n+k)

Insertion

Deletion

Indexing

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

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

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

Worst
Search Insertion

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

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

Find Max

Extract Max

Increase Key

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

O(1)
O(n)
O(log(n))
O(log(n))
O(log(n))*

O(n)
O(1)
O(log(n))
O(log(n))
O(1)*

Add Vertex

O(1)
O(1)
O(|V|^2)
O(|V| |E|)

Insert

Delete

O(n)
O(1)
O(m+n)
O(1)
O(1)
O(1)
O(log(n)) O(log(n)) O(m+n)
O(log(n)) O(log(n)) O(log(n))
O(1)
O(log(n))* O(1)

Remove Vertex

O(1)
O(1)
O(1)
O(|V| |E|)

Merge

O(|V| + |E|)
O(|E|)
O(|E|)
O(|E|)
O(|V|^2)
O(1)
O(|V| |E|) O(|V| |E|)

O(|V|)
O(|E|)
O(1)
O(|E|)

Space Complexity
Worst

st
Deletion

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

You might also like