Search code examples
algorithmbig-odivide-and-conquermaster-theorem

Master's theorem with f(n)=log n


For master's theorem T(n) = a*T(n/b) + f(n) I am using 3 cases:

  1. If a*f(n/b) = c*f(n) for some constant c > 1 then T(n) = (n^log(b) a)
  2. If a*f(n/b) = f(n) then T(n) = (f(n) log(b) n)
  3. If a*f(n/b) = c*f(n) for some constant c < 1 then T(n) = (f(n))

But when f(n) = log n or n*log n, the value of c is dependent on value of n. How do I solve the recursive function using master's theorem?


Solution

  • You might find these three cases from the Wikipedia article on the Master theorem a bit more useful:

    • Case 1: f(n) = Θ(nc), where c < logb a
    • Case 2: f(n) = Θ(nc logk n), where c = logb a
    • Case 3: f(n) = Θ(nc), where c > logb a

    Now there is no direct dependence on the choice of n anymore - all that matters is the long-term growth rate of f and how it relates to the constants a and b. Without seeing more specifics of the particular recurrence you're trying to solve, I can't offer any more specific advice.

    Hope this helps!