Time Space Complexity Cheat Sheet



Time Space Complexity Cheat Sheet

  1. Time Cheat Sheet
  2. Time Space Complexity Cheat Sheet Pdf

Sorting algorithms are a fundamental part of computer science. Being able to sort through a large data set quickly and efficiently is a problem you will be likely to encounter on nearly a daily basis.

Time Cheat Sheet

Time complexity Cheat Sheet. BigO Graph.Correction:- Best time complexity for TIM SORT is O(nlogn) Tweet. Software Development Engineer at Amazon. AlgorithmicComplexity.com Cheat Sheet Algorithms Sorting Algorithms: 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) Merge Sort Array O(n log(n)) O(n log(n)) O(n log(n)) O(n) Heapsort. Big-O Cheat Sheet Generated December 10, 2013. Algorithm Data Structure Time Complexity Space Complexity Average Worst Depth First Search (DFS) Graph of jVj. Time Complexity of Algorithm De nition Time Complexity of Algorithmis the number of dominating operations executed by the algorithm as the function of data size. Time complexity measures the amount of work done by the algorithm during solving the problem in the way which is independent on the implementation and particular input data.

Here are the main sorting algorithms:

AlgorithmData StructureTime Complexity - BestTime Complexity - AverageTime Complexity - WorstWorst Case Auxiliary Space Complexity
QuicksortArrayO(n log(n))O(n log(n))O(n^2)O(n)
Merge SortArrayO(n log(n))O(n log(n))O(n log(n))O(n)
HeapsortArrayO(n log(n))O(n log(n))O(n log(n))O(1)
Bubble SortArrayO(n)O(n^2)O(n^2)O(1)
Insertion SortArrayO(n)O(n^2)O(n^2)O(1)
Select SortArrayO(n^2)O(n^2)O(n^2)O(1)
Bucket SortArrayO(n+k)O(n+k)O(n^2)O(nk)
Radix SortArrayO(nk)O(nk)O(nk)O(n+k)

Another crucial skill to master in the field of computer science is how to search for an item in a collection of data quickly. Here are the most common searching algorithms, their corresponding data structures, and time complexities.

Here are the main searching algorithms:

AlgorithmData StructureTime Complexity - AverageTime Complexity - WorstSpace Complexity - Worst
Depth First SearchGraph of |V| vertices and |E| edges-O(|E|+|V|)O(|V|)
Breadth First SearchGraph of |V| vertices and |E| edges-O(|E|+|V|)O(|V|)
Binary SearchSorted array of n elementsO(log(n))O(log(n))O(1)
Brute ForceArrayO(n)O(n)O(1)
Bellman-FordGraph of |V| vertices and |E| edgesO(|V||E|)O(|V||E|)O(|V|)

Graphs are an integral part of computer science. Mastering them is necessary to become an accomplished software developer. Here is the data structure analysis of graphs:

Cheat
Node/Edge ManagementStorageAdd VertexAdd EdgeRemove VertexRemove EdgeQuery
Adjacency ListO(|V|+|E|)O(1)O(1)O(|V| + |E|)O(|E|)O(|V|)
Incidence ListO(|V|+|E|)O(1)O(1)O(|E|)O(|E|)O(|E|)
Adjacency MatrixO(|V|^2)O(|V|^2)O(1)O(|V|^2)O(1)O(1)
Incidence MatrixO(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|V| ⋅ |E|)O(|E|)

Storing information in a way that is quick to retrieve, add, and search on, is a very important technique to master. Here is what you need to know about heap data structures:

HeapsHeapifyFind MaxExtract MaxIncrease KeyInsertDeleteMerge
Sorted Linked List-O(1)O(1)O(n)O(n)O(1)O(m+n)
Unsorted Linked List-O(n)O(n)O(1)O(1)O(1)O(1)
Binary HeapO(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)
Sorting Algorithms
Sorting Algorithms Space complexityTime complexity
Worst caseBest caseAverage caseWorst case
Insertion SortO(1)O(n)O(n2) O(n2)
Selection SortO(1)O(n2) O(n2) O(n2)
Smooth SortO(1)O(n)O(n log n)O(n log n)
Bubble SortO(1)O(n)O(n2) O(n2)
Shell SortO(1)O(n)O(n log n2) O(n log n2)
MergesortO(n)O(n log n)O(n log n)O(n log n)
QuicksortO(log n)O(n log n)O(n log n)O(n log n)
HeapsortO(1)O(n log n)O(n log n)O(n log n)
Data Structures Comparison
Data Structures Average CaseWorst Case
SearchInsertDeleteSearchInsertDelete
ArrayO(n)N/AN/AO(n)N/AN/A
Sorted ArrayO(log n)O(n)O(n)O(log n)O(n)O(n)
Linked ListO(n)O(1)O(1)O(n)O(1)O(1)
Doubly Linked ListO(n)O(1)O(1)O(n)O(1)O(1)
StackO(n)O(1)O(1)O(n)O(1)O(1)
Hash tableO(1)O(1)O(1)O(n)O(n)O(n)
Binary Search TreeO(log n)O(log n)O(log n)O(n)O(n)O(n)
B-TreeO(log n)O(log n)O(log n)O(log n)O(log n)O(log n)
Red-Black treeO(log n)O(log n)O(log n)O(log n)O(log n)O(log n)
AVL TreeO(log n)O(log n)O(log n)O(log n)O(log n)O(log n)

Time Space Complexity Cheat Sheet Pdf

Growth Rates
n f(n)log nnn log nn22nn!
100.003ns0.01ns0.033ns0.1ns1ns3.65ms
200.004ns0.02ns0.086ns0.4ns1ms77years
300.005ns0.03ns0.147ns0.9ns1sec8.4x1015yrs
400.005ns0.04ns0.213ns1.6ns18.3min--
500.006ns0.05ns0.282ns2.5ns13days--
1000.070.1ns0.644ns0.10ns4x1013yrs --
1,0000.010ns1.00ns9.966ns1ms----
10,0000.013ns10ns130ns100ms----
100,0000.017ns0.10ms1.67ms10sec----
1'000,0000.020ns1ms19.93ms16.7min----
10'000,0000.023ns0.01sec0.23ms1.16days----
100'000,0000.027ns0.10sec2.66sec115.7days----
1,000'000,0000.030ns1sec29.90sec31.7 years----