Advanced master theorem for divide and conquer recurrences

CServer Side ProgrammingProgramming

Divide and conquer is an algorithm that works on the paradigm based on recursively branching problem into multiple sub-problems of similar type that can be solved easily.


Let’s take an example to learn more about the divide and conquer technique −

function recursive(input x size n)
   if(n < k)
      Divide the input into m subproblems of size n/p.
      and call f recursively of each sub problem
      Solve x and return

Combine the results of all subproblems and return the solution to the original problem.

Explanation − In the above problem, the problem set is to be subdivided into smaller subproblems that can be solved easily.

Masters Theorem for divide and conquer is an analysis theorem that can be used to determine a big-0 value for recursive relation algorithms. It is used to find the time required by the algorithm and represent it in asymptotic notation form.

Example of runtime value of the problem in the above example −

T(n) = f(n) + m.T(n/p)

For most of the recursive algorithm, you will be able to find the Time complexity For the algorithm using the master's theorem, but there are some cases master's theorem may not be applicable. These are the cases in which the master's theorem is not applicable. When the problem T(n) is not monotone, for example, T(n) = sin n. Problem function f(n) is not a polynomial.

As the master theorem to find time complexity is not hot efficient in these cases, and advanced master theorem for recursive recurrence was designed. It is design to handle recurrence problem of the form −

T(n) = aT(n/b) + ø((n^k)logpn)

Where n is the size of the problem.

a = number of subproblems in recursion, a > 0

n/b = size of each subproblem b > 1, k >= 0 and p is a real number.

For solving this type of problem, we will use the following solutions,

  • If a>bk, then T(n) = ∅ (nlogba)
  • If a = bk, then
    • If p> -1, then T(n) = ∅(nlogba logp+1n)
    • If p = -1, then T(n) = ∅(nlogba loglogn)
    • If p < -1, then T(n) = ∅(nlogba)
  • If a<bk , then
    • If p> = 0, then T(n)= ∅(nklogpn)
    • If p< 0, then T(n) = ∅(nk)

Using the advanced master algorithm, we will calculate the complexity of some algorithms −

Binary search − t(n) = θ(logn)

Merge sort − T(n) = θ(nlogn)

Updated on 08-Jun-2020 05:44:13