In Computer Science, BigO is a standard mathematical notation that is used to measure the efficiency of an algorithm relative to its input size in the worstcase scenario. In other words, BigO notation is a language that we used to measure the time or space complexity of an algorithm. To measure the efficiency of an algorithm, we need to measure the two things.

Time complexity:How much time is needed to run an algorithm.

Space Complexity:How much space is needed to run an algorithm.
BigO notation represents the upper bound of running algorithms relative to the input size. As it represents the upper bound so it will always give you the worstcase complexity of an algorithm. It is represented as:
f(n) = O(inputSize)
How to calculate the Complexity
You need to follow below 3 steps to calculate the complexity of any program.

Write down each step with their execution count

Make an equation by summing all the step count in terms of n.
We are taking an example to understand more.
function example() { var sum = 0; for(var a=0; a<10; a++) { sum = sum + a; } console.log(sum); }
Step 1: List all the steps with their count.
Operations / Steps  Num of Executions 

var sum = 0 
1 
for (int a=0;a<10;a++) 
11 
sum = sum+a 
10 
console.log(sum); 
1 
Step 2: Sum all the steps
=> 1 + 11 + 10 + 1
Now generalize the above equation in terms of n (input size).
=> 1 + (n + 1) + n + 1
=> 3 + 2n
Now remove contents and ignore lower order terms to get the BigO Notation.
=> n =>O(n)
Examples of BigO Notation
1. Constant Time O(1): O(1) describes the complexity of the function which always executes a single time irrespective of input data set.
function constant(n) { console.log('O1'); }
2. Linear Time O(N):O(N) describes the complexity of the function which always executes n number of times where n is the number of elements in the array. If the number of elements in the array grows then the time will also grow linearly. If the value of n is 10 then the function will prints “On” 10 times.
function linear(n) { for(var a=0; a<n; a++) { console.log('On'); } }
3. Quadratic Time O(N^{2}):O(N^{2}) describes the complexity of the function which always executes (n*n) number of times where n is the number of elements in the array. If the number of elements in the array grows then the time will also grow quadratically.If the value of n is 10 then the function will prints “On” 100 times.
function quadratic(n) { for(var a=0; a<10; a++) { for(var a=0; a<10; a++) { console.log('On^{2}'); } } }
Below is a rough graph of different functions to visualize their Bigo notation.
Rules of BigO notation
We will understand the rules of BigO notation by taking an example. Suppose we have an algorithm complexity as f(n) where n represents the number of inputs, f(n)_{time} represents time complexing and f(n)_{space} represents the space complexity.
Coefficient Rule: “Get Rid ofConstants”
According to this rule, we canignore any noninputsizerelated constants. All the coefficients will be ignored for the large input value. So the BigO notation of f(n) and kf(n) will be the same for any constant k > 0.
Sum Rule: “Add BigOs Up”
The Sum rule rules stated that, If some algorithm(A) depends on two other algorithms (B+C) then the BigO notation of algorithm (A) should be the sum of BigO notation of Algorithm B and C.
If f(n) is O(h(n)) and g(n) is O(p(n)), then f(n)+g(n) is O(h(n)+p(n)).
Product Rule: “Multiply BigOs”
Similar to Sum Rule, Product rule stated that BigO notation is multiplied if the time complexity of algorithms is multiplied.
If f(n) is O(h(n)) and g(n) is O(p(n)), then f(n)g(n) is O(h(n)p(n)).
Polynomial Rule: “BigO tothePower ofk”
The polynomial rule stated that the BigO notation of polynomial time complexity has the same degree that of the polynomial.
If f(n) is a polynomial of degree k, then f(n) is O(n^{k}).
Log of a power rule:
Similar to coefficients rule, constants within the log function also ignored in BigO notation.
log(nk) is O(log(n)) for any constant k > 0.
Transitive rule:
If f(n) is O(g(n)) and g(n) is O(h(n)), then f(n) is O(h(n)).