Run Time Analysis Provide the tightest big-Oh bound on the run time for each of the following methods. int pow(double x, int n) { if( n==0 ) return 1; else { double halfpower = pow(x,n/2); if( n % 2 == 0 ) {
- Run Time Analysis
Provide the tightest big-Oh bound on the run time for each of the following methods.
int pow(double x, int n)
{
if( n==0 )
return 1;
else
{
double halfpower = pow(x,n/2);
if( n % 2 == 0 )
{
return halfpower*halfpower;
}
else
{
return halfpower*halfpower*x;
}
}
}
- Run Time Analysis
Provide the tightest big-Oh bound on the run time for each of the following methods.
int pow(double x, int n)
{
if( n==0 )
return 1;
else
{
double halfpower = pow(x,n/2);
if( n % 2 == 0 )
{
return halfpower*halfpower;
}
else
{
return halfpower*halfpower*x;
}
}
}
Step by step
Solved in 2 steps with 1 images