0

This is about analysis of algorithms: Say, the running time of a problem is:

T(n) = { 1, for n == 1 | T(n/3) + THETA(1), for n > 1}

Now, this is THETA(log base3 n)

But, if I use Master Method, I evaluate to THETA(log base2 n), using Case II

How am I supposed to get the correct answer from master method?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
nimbudew
  • 958
  • 11
  • 28
  • 1
    THETA(log base3 n) is equal to THETA(log base2 n) – fgb Oct 17 '12 at 03:27
  • How is that possible? An algorithm dividing problem into one-third of the original problem is faster that the one dividing into half. So, THETA(log base2 n) is slower that THETA(log base3 n). – nimbudew Oct 17 '12 at 03:30
  • @jaskirat: Yes, but only by a constant factor. THETA doesn't care about those. – hammar Oct 17 '12 at 03:34
  • Okay, so for big enough n, THETA(log base3 n) boils down to THETA(log base2 n). Is this right? – nimbudew Oct 17 '12 at 03:37
  • Not just for big enough n. For all n, log base 3 n = k * (log base 2 n) where k = 1 / log base 2 3 which is constant with respect to n. – hammar Oct 17 '12 at 03:41
  • So that implies THETA( log base(any number) n) is equal to (log base2 n) (For this problem statement). Meaning even if the original problem is halved or one-third or even one-tenth, the running time remains THETA(log base2 n). Great. Thanks. – nimbudew Oct 17 '12 at 03:52
  • @jaskirat: Yes, the base doesn't matter, so we usually just say THETA(log n). – hammar Oct 17 '12 at 03:53
  • But for these questions, is saying Big-oh(log base3 n) correct? That is a loose bound. – nimbudew Oct 17 '12 at 03:55

1 Answers1

1

They're the same. For any two bases a and b, Θ(loga n) = Θ(logb n), so we usually don't mention the base at all and just say Θ(log n).

This is because loga n = (1 / logb a) * logb n, so they differ by a factor of 1 / logb a which is constant with respect to n.

hammar
  • 138,522
  • 17
  • 304
  • 385
  • But we do use bases in Big-oh, right? So, Big-oh(log base2 n) is different from Big-oh(log base3 n)? – nimbudew Oct 17 '12 at 03:58
  • The same argument works for `O(log n)`. It's still a constant factor and those disappear with Big-O as well. – hammar Oct 17 '12 at 04:01