DEV Community

Cover image for What is BIG O notation ?
Mayank Kumar
Mayank Kumar

Posted on

What is BIG O notation ?

What is Big O notation ?

Ans:
image

No No, I am not talking about this Big O πŸ˜‚πŸ˜‚

So in the field of programming, One of the most important things that you have to know is that how to make your code efficient, and by efficient I mean readable and scalable!

To measure how good a code is we use the BIG O NOTATION

What is Big O notation ?

image

Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. Big O is a member of a family of notations invented by Paul Bachmann, Edmund Landau, and others collectively called Bachmann–Landau notation or asymptotic notation.

As in the given figure, there are a total of 7 types of Big O notations:

1) O(1) Constant- no loops

2) O(log N) Logarithmic- usually searching algorithms have log n
if they are sorted (Binary Search)

3) O(n) Linear- for loops, while loops through n items

4) O(n log(n)) Log-Linear- usually sorting operations

5) O(n^2) Quadratic- every element in a collection needs to be compared to every other element. Two
nested loops

6) O(2^n) Exponential- recursive algorithms that solve a problem of size N

7) O(n!) Factorial- you are adding a loop for every element

As given in the graph the best notation to use is the O(1) or O(log n) and on the other hand the worst one to use is O(n!)

As a Developer, you need to be able to find which notation will save you the best amount of time as well as be readable to other developers. If you are able to do this you will be a superstar at your company !!!!

Happy Coding πŸš€

Top comments (0)