Chapter 2 Questions
d) a placeholder for the value returned by each recursive call from the current box
e) the value returned by the function itself
9. In the box trace for a recursive function, a new box is created each time ______.
a) the function is called
b) the function returns a value
c) an object is created
d) an object is initialized
10. What happens if a recursive function never reaches a base case?
a) the function returns the correct value
b) the function returns an incorrect value
c) the function terminates immediately
d) an infinite sequence of recursive calls occurs
11. In a recursive method that writes a string of characters in reverse order, the base case is ______.
a) a string with a length of 0
b) a string whose length is a negative number
c) a string with a length of 3
d) a string that is a palindrome
12. Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci
number?
a) n is a negative integer
b) n is a positive integer
c) n is greater than 1
d) n is an even integer
13. How many bases cases does a recursive binary search of a sorted array have?
a) 0
b) 1
c) 2
d) 3
14. The number of ways to choose k out of n things is ______.
a) the number of ways to choose k – 1 out of n – 1 things
b) the number of ways to choose k out of n – 1 things
c) the sum of the number of ways to choose k – 1 out of n – 1 things and the number of ways to choose k
out of n – 1 things
d) the product of the number of ways to choose k – 1 out of n – 1 things and the number of ways to
choose k out of n – 1 things
15. When you solve a problem by solving two or more smaller problems, each of the smaller problems must be
______ the base case than the original problem.
a) closer to
b) farther to
c) either closer to or the same “distance” from
d) either farther to or the same “distance” from