Q1:
Thefollowing 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));
}
Answer Choices :
it fails the smaller-caller question.
it passes on all three questions and is a valid algorithm.
it fails the base-case question.
it fails the general-case question.
Q2:
Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)?
void mystery(LLNode<Integer> list)
{
if (list != null)
{
mystery(list.getLink());
System.out.println(list.getInfo());
}
}
Answer Choices:
prints the first element on the list
prints the list from start to end
prints the list in reverse order
prints the last element on the list
Q3:
The order of growth for the depth of recursion associated with the text's recursive factorial (returns N!) method is:
Answer Choices :
O(N)
O(log2N).
O(1).
O(N^2)
Q4:
. The sorted values array contains the sixteen integers 1, 2, 3, 13, 13, 20, 24, 25, 30, 32, 40, 45, 50, 52, 57, 60. How many recursive calls are made by our binarySearch method given an initial invocation of binarySearch(45, 0, 15)?
Answer Choices :
2
0
3
4
1
Based on the above Questions
Solution.
1.
it fails the base-case question. Because there is no check if n is 0 or n is 1
Options C
2.
prints the list in reverse order
3.
O(N)
I have tried
my best to resolve it.
If you have any Queries please comment here.
If you like my answer Please Upvote / Like it.
Thank you
Get Answers For Free
Most questions answered within 1 hours.