KEMBAR78
Algorithm Complexity Cheat Sheet | PDF | Combinatorics | Computer Data
0% found this document useful (0 votes)
68 views7 pages

Algorithm Complexity Cheat Sheet

This document summarizes the time and space complexities of various algorithms and data structures. It outlines the average and worst case time complexities for searching, sorting, and graph algorithms like depth-first search, binary search, quicksort, linked lists, hash tables, and more. It also provides the space complexity analysis for these common data structures and algorithms.

Uploaded by

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

Algorithm Complexity Cheat Sheet

This document summarizes the time and space complexities of various algorithms and data structures. It outlines the average and worst case time complexities for searching, sorting, and graph algorithms like depth-first search, binary search, quicksort, linked lists, hash tables, and more. It also provides the space complexity analysis for these common data structures and algorithms.

Uploaded by

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

Searching

Space
Algorithm Data Structure Time Complexity Complexity

Average Worst Worst

Depth First Search (DFS) Graph of |V| vertices and |E| - O(|E| + |V|) O(|V|)
edges

Breadth First Search (BFS) Graph of |V| vertices and |E| - O(|E| + |V|) O(|V|)
edges

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)

Shortest path by Dijkstra, Graph with |V| vertices and |E| O((|V| + |E|) log |V|) O((|V| + |E|) log |V|) O(|V|)
using a Min-heap as priority edges
queue

Shortest path by Dijkstra, Graph with |V| vertices and |E| O(|V|^2) O(|V|^2) O(|V|)
using an unsorted array as
Space
Algorithm Data Structure Time Complexity Complexity

Average Worst Worst

priority queue edges

Shortest path by Bellman-Ford Graph with |V| 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)


Algorithm Data Structure Time Complexity Worst Case Auxiliary Space Complexity

Best Average Worst Worst

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
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-Linked O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
List

Doubly-Linked O(n) O(n) O(1) O(1) O(n) O(n) O(1) O(1) O(n)
List

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

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


Data Structure Time Complexity Space Complexity

Average Worst Worst

Indexing Search Insertion Deletion Indexing Search Insertion Deletion

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

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

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

Heaps
Heaps Time Complexity

Heapify Find Max Extract Max Increase Key Insert Delete Merge

Linked List (sorted) - O(1) O(1) O(n) O(n) O(1) O(m+n)

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

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

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

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

Graphs

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)

Incidence matrix O(|V| ⋅ |E|) O(|V| ⋅ |E|) O(|V| ⋅ |E|) O(|V| ⋅ |E|) O(|V| ⋅ |E|) O(|E|)

Notation for asymptotic growth


letter bound growth

(theta) Θ upper and lower, tight[1] equal[2]

(big-oh) O upper, tightness unknown less than or equal[3]

(small-oh) o upper, not tight less than

(big omega) Ω lower, tightness unknown greater than or equal

(small omega) ω lower, not tight greater than

You might also like