Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the complexity of 3 logn and 2logn same?

DOes it have same complexity since they vary by constant multiplier, or should it be made n^3 and n^2 and be compared?

like image 830
Varun Subramanian Avatar asked Sep 13 '25 12:09

Varun Subramanian


2 Answers

For 'BigOh' notation, the constant multiplier really doesn't matter. All that it does is, it gives the order of the running time complexity. You can consider this small example: Say you have 3 * 100 = 300 apples and 2 * 100 = 200 apples. Surely, 300 != 200, but the order of both are same, that is in order of hundreds.

So by the same means, 3(log n) != 2(log n), but both 3(log n) and 2(log n) are in the order of log n, that is O(log n).

like image 115
insanegupta Avatar answered Sep 15 '25 03:09

insanegupta


Yes. Multiplying by a constant doesn't matter. The are both just O(log n).

In fact, this is part of the definition of big-o notation. If a function may be bounded by a polynomial in n, then as n tends to infinity, you may disregard lower-order terms of the polynomial.

like image 45
harry Avatar answered Sep 15 '25 01:09

harry