-3

Are these two equal? I read somewhere that O(2lg n) = O(n). Going by this observation, I'm guessing the answer would be no, but I'm not entirely sure. I'd appreciate any help.

kurikuone
  • 17
  • 1
  • 2

1 Answers1

2

Firstly, O(2log(n)) isn't equal to O(n).

To use big O notation, you would find a function that represents the complexity of your algorithm, then you would find the term in that function with the largest growth rate. Finally, you would eliminate any constant factors you could.

e.g. say your algorithm iterates 4n^2 + 5n + 1 times, where n is the size of the input. First, you would take the term with the highest growth rate, in this case 4n^2, then remove any constant factors, leaving O(n^2) complexity.

In your example, O(2log(n)) can be simplified to O(log(n))

Now on to your question.

In computer science, unless specified otherwise, you can generally assume that log(n) actually means the log of n, base 2.

This means, using log laws, 2^log(n) can be simplified to O(n)

Proof:

y = 2^log(n)
log(y) = log(2^log(n))
log(y) = log(n) * log(2) [Log(2) = 1 since we are talking about base 2 here]
log(y) = log(n)
y = n
Matt
  • 968
  • 2
  • 13
  • 22