Questions Chapter 6 Flashcards

1
Q

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?

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where are the copies of the argument in the triangle.java program stored?

a. in a variable in the triange( ) method
b. in a field of the TriangleApp class
c. in a variable of the getString( ) method
d. on a stack

A

d. on a stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Assume the user enters10 in the triangle.java program. What is the value of n when the triangle ( ) method first returns a value other than 1?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Assume the user enters 10 in the triangle. java program. What is the value of n when the triangle method is about to return to main( )?

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A

ed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: In the triangle ( ) method, the return values are store on the stack.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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 entire method, whereas the recursive version returns from only one level of recursion.
d. in the recursive version, the range to be searched must be specified in the arguments, while in the loop version it need not be.

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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( )

A

c. recursive calls to recFind( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The binarySearch.java program is an example of the _______________ approach to solving a problem.

A

divide and conquer approach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What gets smaller as you make repeated recursive calls in the towers.java program (Listing 6.4)?

A

top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What becomes smaller as you make repeated recursive calls in the recFind( ) method?

A

range to search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The algorithm in the towers.java program involves:

a. “trees” that are data storage devices
b. secretly putting small disks under large disks
c. changing which columns are the source and destination
d. moving one small disk and then a stack of larger disks

A

c. changing which columns are the source and destination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which is NOT true about the merge( ) method in the merge.java program (Listing 6.5)?

a. its algorithm can handle arrays of different sizes
b. it must search the target array to find where to put the next item
c. it is not recursive
d. it continuously takes the smallest item irrespective of what array it’s in.

A

b. it must search the target array to find where to put the next item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The disadvantage of mergesort is that:

a. it is not recursive
b. it uses more memory
c. although faster than the insertion sort, it is much slower than quicksort
d. it is complicated to implement

A

b. it uses more memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Besides a loop, a ________ can often be used instead of recursion.

A

stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A __________ method calls itself repeatedly, with different values each time

A

recursive

17
Q

Some value of its arguments causes a recursive method to return without calling itself. This is called the _______ ______.

A

base case

18
Q

A ____________ ________ is the sum of itself and all numbers smaller than itself.

A

triangular number

19
Q

The anagram of a word (all possible combinations of its n letters) can be found recursively by repeatedly ________ all its letters and anagramming the __________ of them.

A

repeatedly rotating all its letters, anagramming the rightmost n-1 of them.

20
Q

A ________ search can be carried out recursively by checking which half of a sorted range the search key is in, and then doing the same thing with that half.

A

binary search

21
Q

The __________ can be solved recursively by moving all but the ________ disk of a subtree to a(n) __________ tower, moving the ________ disk to the ________ tower, and finally moving the subtree to the _________.

A

The Towers of Hanoi puzzle can be solved recursively by moving all but the bottom disk of a subtree to an intermediate tower, moving the bottom disk to the destination tower, and finally moving the subtree to the destination.

22
Q

In _________, 1-element subarrays of a larger array are merged into 2-element subarrays, 2-element subarrays are merged into 4-element subarrays, and so on until the entire array is sorted

A

mergesort

23
Q

mergesort requires _______ time.

A

O(N*logN) time

24
Q

Any operation that can be carried out with recursion can be carried out with _________.

A

a stack.