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

Know Thy Complexities!: Big-O Complexity Chart

This document provides a Big-O cheat sheet with the time and space complexities of common algorithms and data structures. It includes tables summarizing the average, best, and worst case time complexities for operations on arrays, stacks, queues, linked lists, hash tables, trees, and graphs. It also includes tables showing the time and space complexities of common sorting algorithms.

Uploaded by

Rzr hellboy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Know Thy Complexities!: Big-O Complexity Chart

This document provides a Big-O cheat sheet with the time and space complexities of common algorithms and data structures. It includes tables summarizing the average, best, and worst case time complexities for operations on arrays, stacks, queues, linked lists, hash tables, trees, and graphs. It also includes tables showing the time and space complexities of common sorting algorithms.

Uploaded by

Rzr hellboy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Big-O Cheat Sheet Download PDF

SHARES  Share  Tweet  Share  Share  Submit

Know Thy Complexities!


Hi there! This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science. When preparing for technical interviews in the past, I found myself
spending hours crawling the internet putting together the best, average, and worst case complexities for search and sorting algorithms so that I wouldn't be stumped when asked about them.
Over the last few years, I've interviewed at several Silicon Valley startups, and also some bigger companies, like Google, Facebook, Yahoo, LinkedIn, and eBay, and each time that I prepared for
an interview, I thought to myself "Why hasn't someone created a nice Big-O cheat sheet?". So, to save all of you fine folks a ton of time, I went ahead and created one. Enjoy! - Eric

If you're trying to catch them all, you might also check out the Pokemon Go Evolution Chart.

Big-O Complexity Chart


Excellent Good Fair Bad Horrible

O(n!) O(2^n)
O(n^2)

O(n log n)
Operations

O(n)

O(1), O(log n)

Elements

Common Data Structure Operations


Data Structure Time Complexity Space Complexity
Average Worst Worst
Access Search Insertion Deletion 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)

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 N/A O(1) O(1) O(1) N/A 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)

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

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

Array Sorting Algorithms


Algorithm Time Complexity Space Complexity
Best 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)

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

Selection Sort O(n^2) O(n^2) O(n^2) O(1)

Tree Sort O(n log(n)) O(n log(n)) O(n^2) O(n)

Shell Sort O(n log(n)) O(n(log(n))^2) O(n(log(n))^2) O(1)

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

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

Counting Sort O(n+k) O(n+k) O(n+k) O(k)

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

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

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

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)) O(m+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 Space Complexity
Average Worst Worst
Dijkstra's algorithm O(|E| log |V|) O(|V|^2) O(|V| + |E|)

A* search algorithm O(|E|) O(b^d) O(b^d)

Prim's algorithm O(|E| log |V|) O(|V|^2) O(|V| + |E|)

Bellman–Ford algorithm O(|E| ⋅ |V|) O(|E| ⋅ |V|) O(|V|)

Floyd-Warshall algorithm O(|V|^3) O(|V|^3) O(|V|^2)

Topological sort O(|V| + |E|) O(|V| + |E|) O(|V| + |E|)

Learn More
Cracking the Coding Interview: 150 Programming Questions and Solutions
Introduction to Algorithms, 3rd Edition
Data Structures and Algorithms in Java (2nd Edition)
High Performance JavaScript (Build Faster Web Application Interfaces)

Contributors
Eric Rowell Quentin Pleple Michael Abed Nick Dizazzo Adam Forsyth Felix Zhu Jay Engineer Josh Davis Nodir Turakulov Jennifer Hamon David Dorfman Bart Massey
Ray Pereda Si Pham Mike Davis mcverry Max Hoffmann Bahador Saket Damon Davison Alvin Wan Alan Briolat Drew Hannay Andrew Rasmussen Dennis Tsang
Vinnie Magro Adam Arold Alejandro Ramirez Aneel Nazareth Rahul Chowdhury Jonathan McElroy steven41292 Brandon Amos Joel Friedly Casper Van Gheluwe
Eric Lefevre-Ardant Oleg Renfred Harper Piper Chester Miguel Amigot Apurva K Matthew Daronco Yun-Cheng Lin Clay Tyler Orhan Can Ozalp Ayman Singh
David Morton Aurelien Ooms Sebastian Paaske Torholm Koushik Krishnan Drew Bailey Robert Burke

Make this Page Better


Edit these tables!

You might also like