ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
AkraBazzi.h

The recurrences of divide et impera with parts of different sizes, \( T( n ) = \sum_{i=1}^k a_i T( b_i n ) + g( n ) \), \( a_i > 0 \) and \( 0 < b_i < 1 \), which the master theorem does not cover when the \( b_i \) differ, e.g., \( T( n ) = T( n / 5 ) + T( 7 n / 10 ) + n \) of the selection in linear time. More...

Files

file  ADS/algorithm/AkraBazzi.h
 The recurrences of divide et impera with parts of different sizes, \( T( n ) = \sum_{i=1}^k a_i T( b_i n ) + g( n ) \), \( a_i > 0 \) and \( 0 < b_i < 1 \), which the master theorem [see MasterTheorem.h] does not cover when the \( b_i \) differ, e.g., \( T( n ) = T( n / 5 ) + T( 7 n / 10 ) + n \) of the selection in linear time.

Functions

double ADS::akraBazziExponent (const std::vector< std::pair< double, double > > &ab)
 the exponent \( p \) of Akra and Bazzi of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \), the root of \( \sum_i a_i b_i^p = 1 \), the terms given as \( ( a_i , b_i ) \)
Growth ADS::akraBazzi (const std::vector< std::pair< double, double > > &ab, double beta, double k=0)
 the order of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \) with \( g( n ) = \Theta( n^\beta \log^k n ) \)

Detailed description

The recurrences of divide et impera with parts of different sizes, \( T( n ) = \sum_{i=1}^k a_i T( b_i n ) + g( n ) \), \( a_i > 0 \) and \( 0 < b_i < 1 \), which the master theorem does not cover when the \( b_i \) differ, e.g., \( T( n ) = T( n / 5 ) + T( 7 n / 10 ) + n \) of the selection in linear time.

The definitions, the invariants and the costs of the area are in Theory of other algorithms.

Function documentation

◆ akraBazzi()

Growth ADS::akraBazzi ( const std::vector< std::pair< double, double > > & ab,
double beta,
double k = 0 )
inline

the order of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \) with \( g( n ) = \Theta( n^\beta \log^k n ) \)

In pseudocode (the theorem of Akra and Bazzi), the cases of master() with \( p \) in place of \( \log_b a \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{akraBazzi}( ( a_i , b_i )_{i=1}^k , \beta , k ) \cr 2 & \quad p \gets \mathrm{akraBazziExponent}( ( a_i , b_i )_{i=1}^k )\quad \triangleright\ \textstyle\sum_i a_i b_i^p = 1 \cr 3 & \quad \textbf{if}\ p > \beta\ \textbf{then return}\ \Theta( n^p ) \cr 4 & \quad \textbf{if}\ p < \beta\ \textbf{then return}\ \Theta( n^\beta \log^k n ) \cr 5 & \quad \textbf{if}\ k < -1\ \textbf{then return}\ \Theta( n^p )\quad \triangleright\ p = \beta \text{ from here on} \cr 6 & \quad \textbf{if}\ k = -1\ \textbf{then return}\ \Theta( n^p \log \log n ) \cr 7 & \quad \textbf{return}\ \Theta( n^p \log^{k+1} n ) \end{array}} \]

Precondition
at least one term, \( a_i > 0 \) and \( 0 < b_i < 1 \)

◆ akraBazziExponent()

double ADS::akraBazziExponent ( const std::vector< std::pair< double, double > > & ab)
inline

the exponent \( p \) of Akra and Bazzi of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \), the root of \( \sum_i a_i b_i^p = 1 \), the terms given as \( ( a_i , b_i ) \)

In pseudocode (the bisection, beyond the book), the function \( f( p ) = \sum_i a_i b_i^p \) being strictly decreasing:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{akraBazziExponent}( ( a_i , b_i )_{i=1}^k ) \cr 2 & \quad \mathit{lo} \gets -1;\ \textbf{while}\ f( \mathit{lo} ) < 1 \ \textbf{do}\ \mathit{lo} \gets 2 \mathit{lo} \cr 3 & \quad \mathit{hi} \gets 1;\ \textbf{while}\ f( \mathit{hi} ) > 1 \ \textbf{do}\ \mathit{hi} \gets 2 \mathit{hi} \cr 4 & \quad \textbf{repeat}\ 200 \text{ times} \cr 5 & \qquad m \gets ( \mathit{lo} + \mathit{hi} ) / 2 \cr 6 & \qquad \textbf{if}\ f( m ) > 1\ \textbf{then}\ \mathit{lo} \gets m \ \textbf{else}\ \mathit{hi} \gets m \cr 7 & \quad \textbf{return}\ \mathit{lo} \end{array}} \]

Precondition
at least one term, \( a_i > 0 \) and \( 0 < b_i < 1 \)
Postcondition
\( | \sum_i a_i b_i^p - 1 | < 10^{-9} \)