1

I know that the time complexity of a recursive function dividing its input by /2 is log n base 2,I have come across some interesting scenarios on

https://stackoverflow.com/a/42038565/8169857

Kindly help me to understand the logic behind the scenarios in the answer regarding the derivation of the formula

1 Answers1

1

It's back to the recursion tree. Why for 1/2 is O(log2(n))? Because if n = 2^k, you should divide k times to reach to 1. Hence, the number of computation is k = log2(n) comparison at most. Now suppose it is (c-1)/c. Hence, if n = (c/(c-1))^k, we need log_{c/(c-1)}(n) operations to reach to 1.

Now as for any constant c > 1, limit log2(n)/log_{c/(c-1)}(n), n \to \infty is equal to a constant greater than zero, log_{c/(c-1)}(n) = \Theta(log2(n)). Indeed, you can say this for any constants a, b > 1, log_a(n) = \Theta(log_b(n)). Now, the proof is completed.

OmG
  • 18,337
  • 10
  • 57
  • 90