4

Stuck with some dumb question in complexity.

I have a loop that runs O(lg(n)) time. I have another loop inside that is also O(lg(n)) so the whole complexity is O(lg(n)) * O(lg(n)) or O(lg(n)2). Can I say that the final O is O(lg(n)) because since n is a degree of 2 then

O(lg(n)) * O(lg(n)) = O(lg(n2))=O(2lg(n))=O(lg(n))

or it can't be used this way?

Lrrr
  • 4,755
  • 5
  • 41
  • 63
Boltosaurus
  • 2,138
  • 3
  • 21
  • 33

1 Answers1

5

No you cant! because this:

O(lg(n)) * O(lg(n)) = O(lg(n2))

is not correct. Although the rest is correct. so your loop is still O(lg(n)2)

Lrrr
  • 4,755
  • 5
  • 41
  • 63