techStackGuru

Time complexity cheat sheet


Defination

In computer science, the phrase "time complexity" is used to define how long it takes to run an algorithm in relation to the size of the input. It gives an estimate of the maximum time an algorithm will require to execute on a specific size of input and serves as a metric of an algorithms efficiency.

OComplexityGrowth
O(1)Constantfast
O(log n)logarithmic
O(n)linear
O(n * log n)log linear
O(n^2)quadratic
O(n^3)cubic
O(2^n)exponential
O(n!)factorialslow

Big-O Complexity Chart

time-complexity-1

Common Data Structure Operations

time-complexity-2

Array Sorting Algorithms

time-complexity-3

Time Complexity vs. Space Complexity

Time ComplexitySpace Complexity
Complexity is a measure of how long an algorithm takes in relation to how much input the algorithm receives.This is a measure of how much memory (space) an algorithm requires compared to the amount of input it requires.
Counts the time for each statement.All variables, including inputs and outputs, are counted.
Merge sort has an O(nlogn) time complexity.Merge sort has an O(n) space complexity.