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

Big O Cheatsheet

The document contains tables summarizing the time and space complexities of various common algorithms and data structures, including search algorithms like depth-first search (DFS) and breadth-first search (BFS), sorting algorithms, graph representations, heaps, and tree and list-based data structures. For each it provides the worst-case time and space complexities for common operations like search, insertion, deletion, and more.

Uploaded by

Malena Maffei
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)
28 views6 pages

Big O Cheatsheet

The document contains tables summarizing the time and space complexities of various common algorithms and data structures, including search algorithms like depth-first search (DFS) and breadth-first search (BFS), sorting algorithms, graph representations, heaps, and tree and list-based data structures. For each it provides the worst-case time and space complexities for common operations like search, insertion, deletion, and more.

Uploaded by

Malena Maffei
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

Searching

Algorithm

Space
Complexity

Data Structure Time Complexity


Average

Worst

Worst

DFS

|V| vertices
and |E| edges

O(|E| + |V|)

O(|V|)

BFS

"

O(|E| + |V|)

O(|V|)

Binary search

Sorted array of
n elements

O(log(n))

O(log(n))

O(1)

Linear (Brute
Force)

Array

O(n)

O(n)

O(1)

Dijkstra, Min-heap

|V| vertices
and |E| edges O((|V| + |E|) log |V|) O((|V| + |E|) log |V|)

O(|V|)

Dijkstra, unsorted
array

"

O(|V|^2)

O(|V|^2)

O(|V|)

Bellman-Ford

"

O(|V||E|)

O(|V||E|)

O(|V|)

Heapify

Find Max

Extract Max

Increase Key

Insert

Delete

Merge

O(1)

O(1)

O(n)

O(n)

O(1)

O(m+n)

O(n)

O(n)

O(1)

O(1)

O(1)

O(1)

O(n)

O(1)

O(log(n))

O(log(n))

Heaps
Heaps

Linked List
(sorted)
Linked List
(unsorted)
Binary Heap

Time
Complexity

O(log(n)) O(log(n)) O(m+n)

Data Structures
Data Structure

Time
Complexity

Space
Complexity

Average

Worst

Worst

Indexing

Search

Insertion

Deletion

Indexing

Search

Insertion

Deletion

Basic Array

O(1)

O(n)

O(1)

O(n)

O(n)

Dynamic Array

O(1)

O(n)

O(n)

O(n)

O(1)

O(n)

O(n)

O(n)

O(n)

Singly & DoublyLinked List

O(n)

O(n)

O(1)

O(1)

O(n)

O(n)

O(1)

O(1)

O(n)

Hash Table

O(1)

O(1)

O(1)

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)

AVL Tree

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(log(n))

O(n)

Node / Edge
Management

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

Adjacency matrix

O(|V|^2)

O(|V|^2)

O(1)

O(|V|^2)

O(1)

O(1)

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

Graphs

Incidence matrix

O(|V| |E|)

O(|V| |E|)

O(|V| |E|)

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

O(|E|)

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)

You might also like