How to answer the following question Assuming values is a full array of int, what does the following recursive method return (assume it is passed a legal argument, a value between 0 and values.length)? int mystery(int n) { if (n == -1) return 0; else return (values[n] + mystery(n - 1)); } A. The sum of the values in the array between index n and the end of the array B. the number of values in the array between index n and the end of the array C. the number of values in the array between index n and the start of the array D. the sum of the values in the array between index n and the start of the array The following code is supposed to return the sum of the numbers between 1 and n inclusive, for positive n. An analysis of the code using our "Three Question" approach reveals that: int sum(int n){ if (n == 1) return 0; else return (n + sum(n - 1)); } A. it fails the smaller-caller question. B. it passes on all three questions and is a valid algorithm. C. it fails the base-case question. D. it fails the general-case question. The following code is supposed to return n!, for positive n. An analysis of the code using our "Three Question" approach reveals that: int factorial(int n){ if (n == 0) return 1; else return (n * factorial(n – 1)); } A. it fails the general-case question. B. it fails the base-case question. C. it fails the smaller-caller question. D. it passes on all three questions and is a valid algorithm.
How to answer the following question
Assuming values is a full array of int, what does the following recursive method return (assume it is passed a legal argument, a value between 0 and values.length)?
int mystery(int n)
{
if (n == -1)
return 0;
else
return (values[n] + mystery(n - 1));
}
The following code is supposed to return the sum of the numbers between 1 and n inclusive, for positive n. An analysis of the code using our "Three Question" approach reveals that:
int sum(int n){
if (n == 1)
return 0;
else
return (n + sum(n - 1));
}
The following code is supposed to return n!, for positive n. An analysis of the code using our "Three Question" approach reveals that:
int factorial(int n){
if (n == 0)
return 1;
else
return (n * factorial(n – 1));
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images