Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Perform a full analysis of both the power() and factorial() function .That is for each function, find T(n) which represents the worst case complexity for
- Perform a full analysis of both the power() and factorial() function .That is for each function, find T(n) which represents the worst case complexity for these two functions. State their upper bounds. Please see https://catherine-leung.gitbook.io/data-strutures-and-algorithms/recursion/analysis-of-a-recursive-function on how to do a recursive analysis.
unsigned int factorial (unsigned int n){
if (n == 0)
return 1;
return n * factorial(n - 1);
}
double power (double base, unsigned int n){
if (n == 0)
return 1;
if (n & 1)
return base * power(base, n / 2) * power(base, n / 2);
return power(base, n / 2) * power(base, n / 2);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started