Question: The iterative implementation: int factorial ( int n ) { int res = 1 ; for ( int i = 1 ; i < =

The iterative implementation:
int factorial(int n){
int res =1;
for (int i =1; i <= n; i++){
res *= i;
}
return res;
}
The recursive implementation:
int factorial(int n){
if (n ==0){
return 1;
} else {
return n * factorial(n -1);
}
}
Which of the following statements is correct?
Note: Negative integers are not valid inputs, so the phrase "values of n" in the options below does not include these.
(a)
For most values of n, the iterative implementation will use at least twice as much memory as the recursive implementation
(b)
For most values of n, the recursive implementation will use at least twice as much memory as the iterative implementation
(c)
Neither of the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!