ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MasterTheorem.h File Reference

The solutions of the recurrences of section 2.9, as orders of growth \( \Theta( c^n n^p \log^q n ( \log \log n )^r ) \) [see Growth]: More...

#include "ADS/Contract.h"
#include <cmath>
#include <compare>
#include <utility>
#include "ADS/algorithm/impl/MasterTheorem.tpp"

Go to the source code of this file.

Classes

struct  ADS::Growth
 the order \( c^n n^p \log^q n ( \log \log n )^r \), and whether it is only an upper bound More...

Namespaces

namespace  ADS

Functions

Growth ADS::master (double a, double b, double beta, double k=0)
 the order of \( T( n ) = a T( n / b ) + \Theta( n^\beta \log^k n ) \); \( \log_b a \) within \( 10^{-12} \) of an integer is taken as that integer (\( \log_{10} 1000 \) is 3, not 2.9999999999999996), and with \( \beta = \log_b a \) the power is \( \beta \)
Growth ADS::linear (double a, double beta)
 the order of \( T( n ) = \sum_i a_i T( n - i ) + \Theta( n^\beta ) \), \( a = \sum_i a_i \)

Detailed description

The solutions of the recurrences of section 2.9, as orders of growth \( \Theta( c^n n^p \log^q n ( \log \log n )^r ) \) [see Growth]:

  • master( a , b , beta , k ) solves \( T( n ) = a T( n / b ) + \Theta( n^\beta \log^k n ) \), \( a \ge 1 \), \( b > 1 \), by Theorem 2.4: with \( \alpha = \log_b a \), it is \( \Theta( n^\alpha ) \) if \( \beta < \alpha \), \( \Theta( n^\beta \log^k n ) \) if \( \beta > \alpha \), and for \( \beta = \alpha \) \( \Theta( n^\alpha \log^{k+1} n ) \) if \( k > -1 \), \( \Theta( n^\alpha \log \log n ) \) if \( k = -1 \), \( \Theta( n^\alpha ) \) if \( k < -1 \); with \( k = 0 \) it is Theorem 2.2;
  • linear( a , beta ) solves \( T( n ) = \sum_{i=1}^h a_i T( n - i ) + \Theta( n^\beta ) \) with \( a = \sum_i a_i \) by Theorem 2.5: \( \Theta( n^{\beta+1} ) \) if \( a = 1 \), and the upper bound \( O( a^n n^\beta ) \) if \( a \ge 2 \), which is not always tight (Fibonacci is \( \Theta( \phi^n ) \)); the theorem has integer \( a_i \), and for real \( a_i \) with \( 1 < a < 2 \) (e.g., \( T( n ) = 1.5 T( n - 1 ) + 1 \), \( \Theta( 1.5^n ) \)) the recurrence is exponential as well, and linear() gives the same upper bound.

Two orders of growth compare as their functions do for \( n \) large: first by the base \( c \) of the exponential, then by the power \( p \) of \( n \), then by the powers \( q \) and \( r \) of the logarithms, which gives the hierarchy \( O( 1 ) \subset O( \log n ) \subset O( n ) \subset O( n \log n ) \subset O( n^2 ) \subset O( n^3 ) \subset O( 2^n ) \); note that \( 2^{\log_2 n} = n \) is a polynomial, not an exponential, and that \( n^{\log n} \) grows faster than every polynomial and slower than every \( c^n \) with \( c > 1 \), so that it has no place in this family.

The contracts [see Contract.h]: \( a \ge 1 \) and \( b > 1 \) for master(), \( a \ge 1 \) for linear(). The functions are defined in MasterTheorem.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 2.9, https://algoritmicamente.it/materiali/libro/capitoli/cap02.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa