Open In App

Akra-Bazzi method for finding the time complexities

Improve
Improve
Like Article
Like
Save
Share
Report

Master’s theorem is a popular method to solve time complexity recurrences of the form:

T(n) = aT(\frac{n}{b}) + f(n)

With constraints over a, b and f(n). The recurrence relation form limits the usability of the Master’s theorem. Following are three recurrences that cannot be solved directly using master’s theorem:

  1. \large{T(n) = 3T(\frac{n}{5}) + 2T(\frac{n}{5}) + \theta(n)}
  2. \large{T(n) = \frac{1}{3}T(\frac{n}{3}) + \theta(\frac{1}{n})}
  3. \large{T(n) = 9T(\frac{n}{3}+\log n) + \theta(n)}


Akra-Bazzi Method: This article explores another method for solving such recurrences that were developed by Mohammad Akra and Louay Bazzi in 1992. Akra–Bazzi method, or Akra–Bazzi theorem, is used to analyze the asymptotic behavior of the mathematical recurrences that appear in the analysis of divide and conquer algorithms where the sub-problems have substantially different sizes. It is a generalization of the master theorem for divide-and-conquer recurrences, which assumes that the sub-problems have equal size. It is named after mathematicians Mohamad Akra and Louay Bazzi.

T(n)=\sum_{i=1}^{k} a_{i} T(b_{i}n+h_{i}(n))+g(n)

 where,  a_{i}              and b_{i}              are constants such that:

  1. \ a_{i}>0
  2. \ 0<b_{i}<1 \textnormal{ i.e. in the range (0, 1)}
  3. \ g(n)\ \epsilon\ O(n^{c}) \textnormal{ i.e. }g(n) \textnormal{ must have a polynomial upperbound}
  4. \ h_{i}(x)\ \epsilon\ O(\large\frac{n}{(logn)^{2}}\normalsize)

Next, find p such that

\large{\sum_{i=1}^k a_ib_i^p=1}
 

Then

\large{T(n)\epsilon\ \theta(n^{p}(1+\int_{1}^{n}\frac{g(u)}{u^{p+1}}du))}

Examples
Let’s consider the three recurrences discussed above and solve them using the method:

Example 1. 

 \large{T(n) = 3T(\frac{n}{5}) + 2T(\frac{n}{5}) + \theta(n)}

Here 

  1. a1 = 3
  2. b1 \large \frac{1}{5}
  3. a2 = 2
  4. b2 \large \frac{1}{5}
  5. b1 and b2 are in the range (0, 1)
  6. g(n) = \theta(n) which is O(nc), here c can be 1.

In this problem h1(n) and h2(n) are not present.
Here p=1 satisfies

3*\large {\frac{1}{5}^p}\normalsize +2*\large {\frac{1}{5}^p}\normalsize=1.

 Finally,

=> n^{1}(1+\int_{1}^{n}\large\frac{u}{u^{1+1}}\normalsize du)

=> n(1+\log{n}-\log{1})

=>n+n\log{n}

=>\theta(n\log{n})

Example 2.  

\large{T(n) = \frac{1}{3}T(\frac{n}{3}) + \theta(\frac{1}{n^{2}})}

Here

  1. a = \large \frac{1}{3}
  2. b = \large \frac{1}{3}
  3. g(n) = \theta(n^2)
  4. b is in the range (0, 1)
  5. g(n) = \theta(n^2) which is in O(nc), here c can be 1.

In this problem h(n) is not present.
Here p= – 1 satisfies

\large\frac{1}{2}\normalsize*\large\frac{1}{2}^p\normalsize=1

Finally,  

=> n^{-1}(1+\int_{1}^{n}\large\frac{\frac{1}{u^{2}}}{u^{-1+1}}\normalsize du)

=> \large\frac{1}{n}\normalsize(1+\int_{1}^{n}\large\frac{1}{u^{2}}\normalsize du)

=> \large\frac{1}{n}\normalsize(1-[\large\frac{1}{u}]_{1}^{n})

=> \large\frac{1}{n}\normalsize(1-\large\frac{1}{n})

=> \theta(\large\frac{\ 1}{n}\normalsize)

Example 3.

 \large{T(n) = 9T(\frac{n}{3}+\log n) + \theta(n)}

Here 

  1. a = 9
  2. b = \large\frac{1}{3}
  3. g(n) = \theta(n)\theta(n)
  4. b is in the range(0, 1)
  5. g(n) =  \theta(n)              which is O(nc), here c can be 1.
  6. h(n) =  \log{n}              which is O(\large\frac{n}{(logn)^{2}}\normalsize)

Here p=2 satisfies 

9*\large\frac{1}{3}^p\normalsize=1

Finally,

=> n^{2}(1+\int_{1}^{n}\large\frac{u}{u^{2+1}}\normalsize du)

=> n^{2}(1+\int_{1}^{n}\large\frac{1}{u^{2}}\normalsize du)

=> n^{2}(1+[-\large\frac{1}{u}\normalsize]_{1}^{n})

=> n^{2}(2-\large\frac{1}{n}\normalsize)

=> 2n^{2}-n

=> \theta(n^{2})

Advantages:

  • Works for many divides and conquer algorithms.
  • Has a lesser constraint over the format of the recurrence than Master’s Theorem.
  • p can be calculated using numerical methods for complex recurrence relations.

Disadvantages:

  • Does not work when the growth of g(n) is not bounded polynomial. For Example g(N) = 2N.
  • Does not deal with ceil and floor functions.


Last Updated : 02 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads