V
ideo

Big O Notation - Video Tutorial

Time complexity is the amount of time taken by an algorithm to run, as a function of the length of the input. It is not going to examine the total execution time of an algorithm. Rather, it is going to give information about the variation in execution time when the number of operations increase or decrease in an algorithm. Time complexity measures the time taken to execute each statement of code in an algorithm. If a statement is set to execute repeatedly then the number of times that statement gets executed is equal to N multiplied by the time required to run that function each time.

Explanation
&
Example
1
O(1) - Constant Time
When an algorithm is not reliant on the input size n, it is said to have constant time that was written in O(1) notation. The runtime will always be the same, regardless of the input size n. For example, printing array at index x.
O(n) - Linear Time
When the runtime of an algorithm increases linearly with the length of the input, it is said to have linear time complexity. When a function checks all of the values in input data, it is said to have linear time that was written in O(n) notation. For example, looping (repetition).
2
3
O(log n) - Logarithmic Time
An algorithm is said to have a logarithmic time complexity when the running time increases slowly when the input size grows. The time complexity is proportional to the logarithm of input size n. For example, binary search.
O(n^2) - Quadratic Time
When the execution time of an algorithm increases non-linearly (n^2) with the length of the input, it is said to have a non-linear time complexity. In general, nested loops follow this quadratic time complexity as one loop takes O(n), and if the function includes a loop within a loop, it takes O(n) * O(n) = O(n^2). For example, nested loop.
4
5
O(2^n) - Exponential Time
In exponential time, with each addition to the n input, the growth rate doubles, and the algorithm iterates across all subsets of the input components. The amount of operations done by the time complexity doubles every time an input unit rises by one. For example, recursive Fibonacci.
O(n!) - Factorial Time
Factorial is the multiplication of all positive integer numbers less than itself. In factorial time, the n input is decreasing in each iteration. Then, each iteration loops as much as itself. Factorial Time grows quickly, thus stay away, if possible, from algorithms that have this time complexity. For example, factorial number of n.
6