

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Big-O Cheat Sheet: Searching, Sorting, Data Structures
Typology: Cheat Sheet
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Generated December 10, 2013. Brandon Amos http://bamos.github.io
Algorithm Data Structure Time Complexity Space Complexity Average Worst Depth First Search (DFS) Graph of |V | vertices and |E| edges
Breadth First Search (BFS) Graph of^ |V^ |^ vertices and |E| 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, 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
( |V |^2
) O
( |V |^2
) O (|V |)
Shortest path by Bellman- Ford
Graph with |V | vertices and |E| edges
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)
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)