Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Big-O Cheat Sheet: A Comprehensive Guide to Algorithm Complexity, Cheat Sheet of Data Structures and Algorithms

This cheat sheet presents the big-O notation for the insert, delete, and search operations of the data structures:

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

ekaashaah
ekaashaah 🇺🇸

4.4

(40)

274 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Big-O Cheat Sheet
Generated December 10, 2013.
Brandon Amos <http://bamos.github.io>
1 Searching
Algorithm Data Structure Time Complexity Space Complexity
Average Worst
Depth First Search (DFS) Graph of |V|vertices and
|E|edges
-O(|E|+|V|)O(|V|)
Breadth First Search
(BFS) Graph of |V|vertices and
|E|edges
-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)
Shortest path by Dijkstra,
using a Min-heap as prior-
ity queue
Graph with |V|vertices
and |E|edges
O((|V|+|E|) log |V|)O((|V|+|E|) log |V|)O(|V|)
Shortest path by Dijkstra,
using an unsorted array as
priority queue
Graph with |V|vertices
and |E|edges
O|V|2O|V|2O(|V|)
Shortest path by Bellman-
Ford Graph with |V|vertices
and |E|edges
O(|V||E|)O(|V||E|)O(|V|)
1
pf2

Partial preview of the text

Download Big-O Cheat Sheet: A Comprehensive Guide to Algorithm Complexity and more Cheat Sheet Data Structures and Algorithms in PDF only on Docsity!

Big-O Cheat Sheet

Generated December 10, 2013. Brandon Amos http://bamos.github.io

1 Searching

Algorithm Data Structure Time Complexity Space Complexity Average Worst Depth First Search (DFS) Graph of |V | vertices and |E| edges

- O (|E| + |V |) O (|V |)

Breadth First Search (BFS) Graph of^ |V^ |^ vertices and |E| edges

- 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) Shortest path by Dijkstra, using a Min-heap as prior- ity queue

Graph with |V | vertices and |E| edges

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

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

Graph with |V | vertices and |E| edges

O

( |V |^2

) O

( |V |^2

) O (|V |)

Shortest path by Bellman- Ford

Graph with |V | vertices and |E| edges

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

2 Sorting

Algorithm Data Structure Time Complexity Worst Case Auxiliary Space Complexity Best Average 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)

3 Data Structures

Data Structure Time Complexity^ Space Complex- ity Average 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 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 -^ 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) 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)