Question 13 public static int exampleRecursion (int n) { if (n == 0) return 0; e
ID: 3829733 • Letter: Q
Question
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 >= 1
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
Explanation / Answer
Question 13
public static int exampleRecursion (int n)
{
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
Ans) Returns the sum of the cubes of the numbers, 0 to n
____________
Question 14
What is the first step in the Tower of Hanoi recursive algorithm?
____________
Ans) Move disk number n from needle 1 to needle 3.
Question 15
If you are building a mission control system, ____.
____________
Ans) you should always use recursion
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));
Ans) 720
____________
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)?
Ans) 0
____________
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));
Ans)66
____________
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?
Ans) n >= 0
____________
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?
Ans) m >= 1 and n >= 0
____________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.