O(N) vs O(2N): Are They Same? If yes then How?

exploreIT
3 min readAug 18, 2021

Umm… Yes! Both are same.

If you are getting confused with O(N) and O(2N) and thinking they are different then it is because while calculating Big-O you are focusing on ‘Number Of Operations’ that a function have instead of ‘how quickly the runtime grows depending on the size of the input’.

Confused? Well, let me explain it!

When we talk about Big-O and scalability of code, we simply mean- when we grow bigger and bigger with our input, how much does the algorithm or function slows down. The less it slows down or the slower it slows down, the better it is.

Let’s have a look on the below diagrams-

Fig-1: Graphical Representation Of O(N)
Fig-2: Graphical Representation Of O(2N)

You can see in both the cases our ‘No Of Operations’ is increasing linearly depending on the ‘Input Size’. But yes, practically O(N) will definitely have a shorter running time than O(2N), but not significant. When N value increases O(N) will dominate the growth and coefficient 2 becomes insignificant. So eventually when our N will be very large, the running time of both will be the identical.

Let’s take an example:

T(N) = 4N² + 3N + 9999

For n= 1 or 2, the constant 9999 seems to be the dominant part of the function but for larger values of N, we can ignore the constants and 3N and can just concentrate on 4N² as it will contribute more to the growth, If the N value still increases the coefficient 4 also seems insignificant and we can say complexity is O(N²).

Now you may think why will I take the larger values?

Well, that is because when inputs are small the Big-O notations don’t matter that much and if we come to the Scalability of a code we have to think outside of just the small, so that when things grow we don’t have to fix things again and again.

So, if you compare O(N) and O(2N) in terms of asymptotic complexity then they are equal, because they represent the same growth rate (what we know as ‘linear’).

Reference StackOveflow and Others

Hey, did you like the explanation?

If yes then don’t forget to follow exploreIT as I regularly come up with interesting topics related to programming. And of course, if you have any difficulty understanding the concepts or find anything wrong in the article please feel free to comment below!

Feet free to connect — https://www.linkedin.com/in/salman-shaikh-82989b1b9/

See you in the next article, Bye Bye!

Related Article(s)

--

--

exploreIT

This is Salman, a Software Developer. Here in exploreIT, I come up with interesting concepts related to programming that you may like. Do check & have fun:)