Question 7 Assume there are four methods A, B, C, and D. If method A calls metho
ID: 3829696 • Letter: Q
Question
Question 7
Assume there are four methods A, B, C, and D. If method A calls method B, method B calls method C, method C calls method D, and method D calls method A, which of the following methods is indirectly recursive?
A
B
C
D
1 points
Question 8
Using a recursive algorithm to solve the Tower of Hanoi problem, a computer that can generate one billion moves per second would take ____ years to solve the problem.
39
400
500
10,000
1 points
Question 9
public static int exampleRecursion (int n)
{
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
How many base cases are in the code in the accompanying figure?
zero
one
two
three
1 points
Question 10
public static int func1(int m, int n)
{
if (m == n || n == 1)
return 1;
else
return func1(m - 1, n - 1) + n * func1(m - 1, n);
}
Given the code in the accompanying figure, which of the following method calls would result in the value 1 being returned?
func1(1, 0)
func1(1, 1)
func1(1, 2)
func1(2, 0)
1 points
Question 11
____ is NOT an iterative control structure.
A while loop
A for loop
Recursion
A do...while loop
1 points
Question 12
public static int exampleRecursion (int n)
{
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
What is the limiting condition of the code in the accompanying figure?
n >= 0
n > 0
n > 1
n >= 1
1 points
Question 13
public static int exampleRecursion (int n)
{
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
What does the code in the accompanying figure do?
Returns the cube of the number n
Returns the sum of the cubes of the numbers, 0 to n
Returns three times the number n
Returns the next number in a Fibonacci sequence
1 points
Question 14
What is the first step in the Tower of Hanoi recursive algorithm?
Move the top n disks from needle 1 to needle 2, using needle 3 as the intermediate needle.
Move disk number n from needle 1 to needle 3.
Move the top n - 1 disks from needle 2 to needle 3, using needle 1 as the intermediate needle.
Move the top n - 1 disks from needle 1 to needle 2, using needle 3 as the intermediate needle.
1 points
Question 15
If you are building a mission control system, ____.
you should always use iteration
you should always use recursion
use the most efficient solution
use the solution that makes the most intuitive sense
1 points
Question 16
Consider the following definition of a recursive method.
public static int recFunc(int num)
{
if (num >= 10)
return 10;
else
return num * recFunc(num + 1);
}
What is the output of the following statement?
System.out.println(recFunc(8));
8
72
720
None of these
1 points
Question 17
public static int exampleRecursion (int n)
{
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
What is the output of exampleRecursion(0)?
0
3
9
27
1 points
Question 18
Consider the following definition of a recursive method.
public static int strange(int[] list, int first, int last)
{
if (first == last)
return list[first];
else
return list[first] + strange(list, first + 1, last);
}
Given the declaration
int[] beta = {2, 5, 8, 9, 13, 15, 18, 20, 23, 25};
What is the output of the following statement?
System.out.println(strange(beta, 4, 7));
27
33
55
66
1 points
Question 19
public static int func2(int m, int n)
{
if (n == 0)
return 0;
else
return m + func2(m, n - 1);
}
What is the limiting condition of the code in the accompanying figure?
n >= 0
m > n
m >= 0
n > m
1 points
Question 20
public static int func1(int m, int n)
{
if (m == n || n == 1)
return 1;
else
return func1(m - 1, n - 1) + n * func1(m - 1, n);
}
What precondition must exist in order to prevent the code in the accompanying figure from infinite recursion?
m >= 0 and n >= 0
m >= 0 and n >= 1
m >= 1 and n >= 0
m >= 1 and n >=
A
B
C
D
Explanation / Answer
Hi, I have answered last 4 Questions.
Please repost others in separate post.
Please let me know in case of any issue in last 4 questions.
Q20)
We are calling func1 recursively with lower m and n:
func1(m - 1, n - 1) + n * func1(m - 1, n)
So, we should have check : m>=0 && n >= 1
Ans: m >= 0 and n >= 1
Q19)
We are calling func2 recursively with lower n:
func2(m, n - 1)
So, it should check : n >=0 instead of n == 0
Ans: n >= 0
Q18)
So, we are summing up the values in list in range : first to last:
list[first] + strange(list, first + 1, last);
So, {2, 5, 8, 9, 13, 15, 18, 20, 23, 25}
and: (strange(beta, 4, 7))
Ans: 13+ 15+ 18+ 20 = 66
Q17)
exampleRecursion(0):
As we have: n == 0 in base condition,it returns 0
Ans: 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.