Exam 13: Recursion
Exam 1: An Overview of Computers and Programming Languages50 Questions
Exam 2: Basic Elements of Java50 Questions
Exam 3: Introduction to Objects and Input/output50 Questions
Exam 4: Control Structures I: Selection50 Questions
Exam 5: Control Structures II: Repetition50 Questions
Exam 6: Graphical User Interface GUI and Object-Oriented Design OOD50 Questions
Exam 7: User-Defined Methods50 Questions
Exam 8: User-Defined Classes50 Questions
Exam 9: Arrays46 Questions
Exam 10: Inheritance and Polymorphism50 Questions
Exam 11: Handling Exceptions and Events50 Questions
Exam 12: Advanced Guis and Graphics48 Questions
Exam 13: Recursion50 Questions
Exam 14: Applications of Arrays Searching and Sorting and Strings50 Questions
Select questions type
In reality, if you execute an infinite recursive method on a computer, it will execute forever.
Free
(True/False)
4.8/5
(42)
Correct Answer:
False
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 declarationint[] 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));
Free
(Multiple Choice)
4.8/5
(34)
Correct Answer:
D
The general case of a recursive solution is the case for which the solution is obtained directly.
Free
(True/False)
4.9/5
(28)
Correct Answer:
False
A method is called directly recursive if it calls another recursive method.
(True/False)
4.8/5
(35)
Consider the following definition of a recursive method.public static int mystery(int[] list, int first, int last)
{
If (first == last)
Return list[first];
Else
Return list[first] + mystery(list, first + 1, last);
}Given the declarationint[] alpha = {1, 4, 5, 8, 9};What is the output of the following statement?System.out.println(mystery(alpha, 0, 4));
(Multiple Choice)
4.8/5
(31)
A general case to a recursive algorithm must eventually reduce to a base case.
(True/False)
4.9/5
(36)
The limiting condition for a recursive method using a list might be the number of elements in the list.
(True/False)
4.9/5
(37)
The overhead associated with iterative methods is greater in terms of both memory space and computer time compared to the overhead associated with executing recursive methods.
(True/False)
4.8/5
(32)
The following is a valid recursive definition to determine the factorial of a non-negative integer.0! = 1
1! = 1
n! = n * (n - 1)! if n > 0
(True/False)
4.8/5
(41)
In the recursive algorithm for the nth Fibonacci number, there are ____ base case(s).
(Multiple Choice)
4.9/5
(34)
Consider the following definition of a recursive method. public static int foo(int n) //Line 1
{ //Line 2
If (n == 0) //Line 3
Return 0; //Line 4
Else //Line 5
Return n + foo(n - 1); //Line 6
}Which of the statements represent the base case?
(Multiple Choice)
4.8/5
(30)
public static int func2(int m, int n)
{
If (n == 0)
Return 0;
Else
Return m + func2(m, n - 1);
}What is the output of func2(2, 3)?
(Multiple Choice)
4.9/5
(46)
The process of solving a problem by reducing it to smaller versions of itself is called recursion.
(True/False)
4.8/5
(41)
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?
(Multiple Choice)
4.9/5
(38)
There are two base cases in the recursive implementation of generating a Fibonacci sequence.
(True/False)
4.8/5
(33)
A recursive method in which the first statement executed is a recursive call is called a tail recursive method.
(True/False)
4.7/5
(33)
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.
(Multiple Choice)
4.7/5
(41)
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(3)?
(Multiple Choice)
4.7/5
(40)
Showing 1 - 20 of 50
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)