DSA Recursion
1. If the user enters 10 in the triangle.java program (Listing 6.1), what is the maximum
number of "copies" of the triangle() method (actually just copies of its argument) that
exist at any one time? - answer10
2. Where are the copies of the argument, mentioned in question 1, stored?
a. in a variable in the triangle() method
b. in a field of the TriangleApp class
c. in a variable of the getString() method
d. on a stack - answerD
3. Assume the user enters 10 as in question 1. What is the value of n when the
triangle() method first returns a value other than 1? - answer2
4. Assume the same situation as in question 1. What is the value of n when the
triangle() method is about to return to main()? - answer10
5. True or false: In the triangle() method, the return values are stored on the stack. -
answerFalse
6. In the anagram.java program (Listing 6.2), at a certain depth of recursion, a version of
the doAnagram() method is working with the string "led". When this method calls a new
version of itself, what letters will the new version be working with? - answer"ed"
7. We've seen that recursion can take the place of a loop, as in the loop-oriented
orderedArray.java program (Listing 2.4) and the recursive binarySearch.java program
(Listing 6.3). Which of the following is not true?
a. Both programs divide the range repeatedly in half.
b. If the key is not found, the loop version returns because the range bounds cross, but
the recursive version occurs because it reaches the bottom recursion level.
c. If the key is found, the loop version returns from the - answerB
8. In the recFind() method in the binarySearch.java program (Listing 6.3), what takes
the place of the loop in the non-recursive version?
a. the recFind() method
b. arguments to recFind()
c. recursive calls to recFind()
d. the call from main() to recFind() - answerC
9. The binarySearch.java program is an example of the _________ approach to solving
a problem. - answerdivide-and conquer
1. If the user enters 10 in the triangle.java program (Listing 6.1), what is the maximum
number of "copies" of the triangle() method (actually just copies of its argument) that
exist at any one time? - answer10
2. Where are the copies of the argument, mentioned in question 1, stored?
a. in a variable in the triangle() method
b. in a field of the TriangleApp class
c. in a variable of the getString() method
d. on a stack - answerD
3. Assume the user enters 10 as in question 1. What is the value of n when the
triangle() method first returns a value other than 1? - answer2
4. Assume the same situation as in question 1. What is the value of n when the
triangle() method is about to return to main()? - answer10
5. True or false: In the triangle() method, the return values are stored on the stack. -
answerFalse
6. In the anagram.java program (Listing 6.2), at a certain depth of recursion, a version of
the doAnagram() method is working with the string "led". When this method calls a new
version of itself, what letters will the new version be working with? - answer"ed"
7. We've seen that recursion can take the place of a loop, as in the loop-oriented
orderedArray.java program (Listing 2.4) and the recursive binarySearch.java program
(Listing 6.3). Which of the following is not true?
a. Both programs divide the range repeatedly in half.
b. If the key is not found, the loop version returns because the range bounds cross, but
the recursive version occurs because it reaches the bottom recursion level.
c. If the key is found, the loop version returns from the - answerB
8. In the recFind() method in the binarySearch.java program (Listing 6.3), what takes
the place of the loop in the non-recursive version?
a. the recFind() method
b. arguments to recFind()
c. recursive calls to recFind()
d. the call from main() to recFind() - answerC
9. The binarySearch.java program is an example of the _________ approach to solving
a problem. - answerdivide-and conquer