ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MasterTheorem.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File MasterTheorem.h --------------------------*/
3/*--------------------------------------------------------------------------*/
53/*--------------------------------------------------------------------------*/
54/*----------------------------- DEFINITIONS --------------------------------*/
55/*--------------------------------------------------------------------------*/
56
57#ifndef __ADS_MasterTheorem
58 #define __ADS_MasterTheorem
59/* self-identification: #endif constant */
60
61/*--------------------------------------------------------------------------*/
62/*------------------------------ INCLUDES ----------------------------------*/
63/*--------------------------------------------------------------------------*/
64
65#include "ADS/Contract.h"
66
67#include <cmath>
68#include <compare>
69#include <utility>
70
71/*--------------------------------------------------------------------------*/
72/*--------------------------- NAMESPACE ------------------------------------*/
73/*--------------------------------------------------------------------------*/
74
75namespace ADS
76{
77
80struct Growth
81{
82 double c = 1;
83 double p = 0;
84 double q = 0;
85 double r = 0;
86 bool upper = false;
87
89 [[nodiscard]] double at( double n ) const {
90 return( std::pow( c , n ) * std::pow( n , p ) * std::pow( std::log( n ) ,
91 q ) *
92 std::pow( std::log( std::log( n ) ) , r ) );
93 }
94
97 friend std::partial_ordering operator<=>( const Growth & a ,
98 const Growth & b ) {
99 for( auto [ x , y ] : { std::pair( a.c , b.c ) , std::pair( a.p , b.p ) ,
100 std::pair( a.q , b.q ) , std::pair( a.r , b.r ) } )
101 if( x != y )
102 return( x <=> y );
103 return( std::partial_ordering::equivalent );
104 }
105
108 friend bool operator==( const Growth & a , const Growth & b ) {
109 return( ( a <=> b ) == 0 );
110 }
111 };
112
137inline Growth master( double a , double b , double beta , double k = 0 );
138
154inline Growth linear( double a , double beta );
155
156/*--------------------------------------------------------------------------*/
157
158} // end( namespace ADS )
159
160/*--------------------------------------------------------------------------*/
161/*-------------------------- IMPLEMENTATION --------------------------------*/
162/*--------------------------------------------------------------------------*/
163
164#include "ADS/algorithm/impl/MasterTheorem.tpp"
165
166/*--------------------------------------------------------------------------*/
167
168#endif /* MasterTheorem.h included */
169
170/*--------------------------------------------------------------------------*/
171/*------------------------ End File MasterTheorem.h ------------------------*/
172/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Growth linear(double a, double beta)
the order of ,
Growth master(double a, double b, double beta, double k=0)
the order of ; within of an integer is taken as that integer ( is 3, not 2.9999999999999996),...
Definition ADT.h:96
the order , and whether it is only an upper bound
Definition MasterTheorem.h:81
double r
the power of
Definition MasterTheorem.h:85
friend std::partial_ordering operator<=>(const Growth &a, const Growth &b)
the order of the two functions for large: lexicographic on , , and (upper is not compared)
Definition MasterTheorem.h:97
double c
the base of the exponential
Definition MasterTheorem.h:82
bool upper
rather than
Definition MasterTheorem.h:86
double q
the power of
Definition MasterTheorem.h:84
double at(double n) const
the value of the order at , for
Definition MasterTheorem.h:89
friend bool operator==(const Growth &a, const Growth &b)
true if the two orders are the same, i.e., if operator<=> finds them equivalent
Definition MasterTheorem.h:108
double p
the power of
Definition MasterTheorem.h:83