Exam 16: Recursion
Exam 1: Introduction to Computers and Java51 Questions
Exam 2: Java Fundamentals61 Questions
Exam 3: Decision Structures64 Questions
Exam 4: Loops and Files57 Questions
Exam 5: Methods60 Questions
Exam 6: A First Look at Classes58 Questions
Exam 7: Arrays and the Arraylist Class64 Questions
Exam 8: A Second Look at Classes and Objects50 Questions
Exam 9: Text Processing and More About Wrapper Classes60 Questions
Exam 10: Inheritance70 Questions
Exam 11: Exceptions and Advanced File IO56 Questions
Exam 12: A First Look at GUI Applications60 Questions
Exam 13: Advanced GUI Applications58 Questions
Exam 14: Applets and More54 Questions
Exam 15: Creating GUI Applications With Javafx and Scene Builder40 Questions
Exam 16: Recursion42 Questions
Exam 17: Databases48 Questions
Select questions type
How many times will the following method call itself if the value 10 is passed as the argument?
Public static void message(int n)
{
If (n < 0)
{
System.out.println("Print this line.\n");
Message(n + 1);
}
}
Free
(Multiple Choice)
4.8/5
(39)
Correct Answer:
A
Look at the following method: public static int test2(int x, int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y, y + 5) + 6);
}
}
What is returned for test2(18,5)?
Free
(Multiple Choice)
4.9/5
(43)
Correct Answer:
C
Look at the following pseudocode algorithm: Algorithm gcd(x, y)
If (x < y)
Gcd (y, x)
Else
If (y = 0)
Return x
Else
Return gcd(y, x mod y)
End gcd
What is the base case for the algorithm gcd?
Free
(Multiple Choice)
4.9/5
(34)
Correct Answer:
B
A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
(True/False)
4.8/5
(38)
Look at the following pseudocode algorithm: algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8) + 8)
End Test14
What is the recursive case for the algorithm?
(Multiple Choice)
5.0/5
(46)
Look at the following pseudocode algorithm: algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8) + 8)
End Test14
What is the base case for the algorithm?
(Multiple Choice)
4.9/5
(35)
The number of times that a method calls itself is known as the:
(Multiple Choice)
4.8/5
(31)
Look at the following pseudocode algorithm: Algorithm gcd(x, y)
If (x < y)
Gcd (y, x)
Else
If (y = 0)
Return x
Else
Return gcd(y, x mod y)
End gcd
What is returned from gcd(60, 24)?
(Multiple Choice)
4.8/5
(37)
Any problem that can be solved recursively can also be solved iteratively.
(True/False)
4.8/5
(38)
Like ________, a recursive method must have some way to control the number of times it repeats.
(Multiple Choice)
4.9/5
(39)
This term is used for methods that directly call themselves.
(Multiple Choice)
4.8/5
(35)
Look at the following pseudocode algorithm: Algorithm Test3(int a, int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1, b)
End Test3
What is the base case for the algorithm?
(Multiple Choice)
4.7/5
(43)
Look at the following pseudocode algorithm: Algorithm Test3(int a, int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1, b)
End Test3
What is the recursive case for the algorithm?
(Multiple Choice)
4.8/5
(37)
Look at the following pseudocode algorithm: algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8) + 8)
End Test14
What is the depth of Test14(16)?
(Multiple Choice)
4.9/5
(44)
Look at the following method: public static int test2(int x, int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y, y + 5) + 6);
}
}
What is the depth of test2(18,5)?
(Multiple Choice)
4.9/5
(39)
Look at the following pseudocode algorithm: algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8) + 8)
End Test14
What is the depth of Test14(7)?
(Multiple Choice)
4.9/5
(34)
Unlike a loop, a recursive method does not require code to stop it from repeating.
(True/False)
4.9/5
(31)
Showing 1 - 20 of 42
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)