The Wayback Machine - https://web.archive.org/web/20240708041048/https://www.geeksforgeeks.org/akra-bazzi-method-for-finding-the-time-complexities/
Open In App

Akra-Bazzi method for finding the time complexities

Last Updated : 19 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

[Tex]T(n) = aT(\frac{n}{b}) + f(n)  [/Tex]

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. [Tex]\large{T(n) = 3T(\frac{n}{5}) + 2T(\frac{n}{5}) + \theta(n)} [/Tex]
  2. [Tex]\large{T(n) = \frac{1}{3}T(\frac{n}{3}) + \theta(\frac{1}{n})} [/Tex]
  3. [Tex]\large{T(n) = 9T(\frac{n}{3}+\log n) + \theta(n)} [/Tex]


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.

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

 where,  [Tex]a_{i}         [/Tex] and [Tex]b_{i}         [/Tex] are constants such that:

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

Next, find p such that

[Tex]\large{\sum_{i=1}^k a_ib_i^p=1}         [/Tex]
 

Then

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

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

Example 1. 

 [Tex]\large{T(n) = 3T(\frac{n}{5}) + 2T(\frac{n}{5}) + \theta(n)} [/Tex]

Here 

  1. a1 = 3
  2. b1 = [Tex]\large \frac{1}{5} [/Tex]
  3. a2 = 2
  4. b2 = [Tex]\large \frac{1}{5} [/Tex]
  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

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

 Finally,

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

=> [Tex]n(1+\log{n}-\log{1}) [/Tex]

=>[Tex]n+n\log{n} [/Tex]

=>[Tex]\theta(n\log{n}) [/Tex]

Example 2.  

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

Here

  1. a = [Tex]\large \frac{1}{3}  [/Tex]
  2. b = [Tex]\large \frac{1}{3}         [/Tex]
  3. g(n) = [Tex]\theta(n^2)   [/Tex]
  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

[Tex]\large\frac{1}{2}\normalsize*\large\frac{1}{2}^p\normalsize=1 [/Tex]

Finally,  

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

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

=> [Tex]\large\frac{1}{n}\normalsize(1+(-\large\frac{1}{n})-(-\large\frac{1}{1}))[/Tex]

=> [Tex]\large\frac{1}{n}\normalsize(1-\large\frac{1}{n}+1))[/Tex]

=> [Tex]\large\frac{2}{n}\normalsize-(\large\frac{1}{n^2})[/Tex]

=> [Tex]\theta(\large\frac{1}{n}) [/Tex]

Example 3.

 [Tex]\large{T(n) = 9T(\frac{n}{3}+\log n) + \theta(n)} [/Tex]

Here 

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

Here p=2 satisfies 

[Tex]9*\large\frac{1}{3}^p\normalsize=1 [/Tex]

Finally,

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

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

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

=> [Tex]n^{2}(2-\large\frac{1}{n}\normalsize) [/Tex]

=> [Tex]2n^{2}-n [/Tex]

=> [Tex]\theta(n^{2}) [/Tex]

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.


Previous Article
Next Article

Similar Reads

Time complexities of different data structures
Time Complexity is a concept in computer science that deals with the quantification of the amount of time taken by a set of code or algorithm to process or run as a function of the amount of input. In other words, the time complexity is how long a program takes to process a given input. The efficiency of an algorithm depends on two parameters: Time
2 min read
Time Complexities of all Sorting Algorithms
The efficiency of an algorithm depends on two parameters: Time ComplexitySpace ComplexityTime Complexity:Time Complexity is defined as the number of times a particular instruction set is executed rather than the total time taken. It is because the total time taken also depends on some external factors like the compiler used, the processor's speed,
2 min read
Difference Between Exponential and Polynomial Complexities
Understanding the computational complexity of algorithms is essential in computer science, as it helps determine the feasibility and efficiency of solutions to problems. Two of the most common types of complexities are exponential and polynomial complexities. This article will provided the differences between these two, explaining their characteris
4 min read
Time difference between expected time and given time
Given the initial clock time h1:m1 and the present clock time h2:m2, denoting hour and minutes in 24-hours clock format. The present clock time h2:m2 may or may not be correct. Also given a variable K which denotes the number of hours passed. The task is to calculate the delay in seconds i.e. time difference between expected time and given time. Ex
5 min read
Finding the probability of a state at a given time in a Markov chain | Set 2
Given a Markov chain G, we have the find the probability of reaching the state F at time t = T if we start from state S at time t = 0.A Markov chain is a random process consisting of various states and the probabilities of moving from one state to another. We can represent it using a directed graph where the nodes represent the states and the edges
11 min read
Finding Minimum travel time to Nearest city from Current location
Given an integer N representing the number of cities near you along with two arrays pos[] representing the position of the city and time[] representing the time required to move 1 unit of distance for a particular city, the task is to find the minimum time required to visit any city where you are currently at cur position. Examples: Input: N = 3, c
6 min read
Finding Minimum Time for Workers to Meet at a Point
Given N workers standing on a road of infinite length and two arrays point[] and time[] each of size N, such that point[i] is point where the ith worker is standing and time[i] is time needed for the ith worker to finish his task, find the minimum time when all the workers can finish their tasks and meet at a point. Consider that all the workers mo
8 min read
Maximum removal from array when removal time &gt;= waiting time
Given there are N elements in an array. The task is to remove elements from the array from left to right. However, some time is required to remove an element from the array(let us call it removal time). The time to remove an element is equal to the value of that element in seconds.An element can only be removed when the time required to remove it(r
6 min read
Maximize time by replacing '_' in a given 24 Hour format time
Given a string S representing a time in 24 hours format, with '_' placed at positions of some digits, the task is to find the maximum time possible by replacing the characters '_' with any digit. Examples: Input: S = “0_:4_”Output: 09:39Explanation: Replacing the characters S[1] and S[4] with '9' modifies the string to "09:49", which is the maximum
7 min read
Total time to pick elements with given time interval
Given an array arr[] of size N that denotes the type of an element, and another time array time[] of size N where time[i] denotes the time interval between picking two elements of the ith type. The task is to find the time taken to pick all the elements while traversing from left to right of the array. Note: Moving between adjacent positions takes
6 min read
Practice Tags :
three90RightbarBannerImg