Ads

Wednesday, 23 October 2019

Algo - Big O notation

Let's consider the Linear search. We have know that the complexity of the Linear search algorithm is O(n^m). 

Yes, what is this 'O' is doing there?

Actually the 'O' is the maximum notation of the algorithm. 

For example, if we have [1,3,7, 9, 0]
and we want to find the index of 0. The answer is 4. 
It takes 5 'for' loops to be executed to find the index of 0 in the given array.

Now take the array as below

[[1,3], [2,4], [7,9], [13,15]]

How many for loops we have to do now to find the index of 15?

we have 4 elements in the main array and each element has another 2 child elements. So the complexity takes 4^2.

And this 4^2 is the maximum and it cannot be more than that to find any other element in the given array.

So we denote it as O(4^2)

Finally, we can say that O is the maximum complexity of the algorithm.

-SnehaVIK

No comments:

Post a Comment

SOLID Principles

SOLID principles are the basic essential thing to know for every developer before he/she starts coding in any IDE. Here is the full form S ...