Chapter 13 APCSA
Chapter 13 APCSA
TRUE/FALSE
2. Recursion is measured by looking at how the run time and memory usage of an algorithm vary as a
function of the quantity of data processed.
3. Given a recursive definition of some process, it is usually easy to write a recursive method that
implements it.
4. The call stack contains, among other things, the method’s local variables.
5. When a method returns, its activation record is removed from the top of the stack.
7. Computer scientists use expressions such as O(n) to express the linear relationship between an array’s
length and the execution time.
8. Given two methods that perform the same task, the one that is quadratic is preferable to the one that is
linear.
9. In a linear equation, the best-, worst-, and average-case behaviors are O(1).
10. Using a binary search, finding a value from a list of a million entries involves at most 20 steps.
MODIFIED TRUE/FALSE
1. In a(n) infinite recursion, the algorithm never reaches its stopping state. ____________________
ANS: T PTS: 1 REF: 492
2. A large storage area known as a(n) activation record is created at program startup.
____________________
ANS: F, constant
4. Because the summation algorithm must visit each number in the array, no matter how the numbers are
ordered, the algorithm is always linear. ____________________
5. In order to use a(n) binary search, the list must be sorted in ascending order. ____________________
MULTIPLE CHOICE
10. A(n) ____ search starts at the beginning of an array and looks at consecutive elements until the search
value is located or the end of the array is reached.
a. binary c. recursive
b. linear d. iterative
ANS: B PTS: 1 REF: 509
12. The general idea behind a ____ algorithm is to break an array into two parts, then rearrange the
elements so the larger values are at one end and the smaller values at the other, then repeat until the
subparts contain a single value.
a. linear c. binary
b. complex d. quicksort
ANS: D PTS: 1 REF: 512
13. In a quicksort algorithm, the iterative approach requires a data structure called a(n) ____.
a. stack c. activation record
b. merge d. big-O
ANS: A PTS: 1 REF: 516
14. A ____ sort algorithm computes the middle position of an array and recursively sorts its left and right
subarrays, merges to two sorted subarrays into a single sorted array, then stops when the subarrays can
no longer be subdivided.
a. stack c. quick
b. merge d. recursive
ANS: B PTS: 1 REF: 516 | 517
16. A(n) ____ is a GUI control that allows the user to select a value within a range of values.
a. buffer c. degree
b. slider d. option button
ANS: B PTS: 1 REF: 523
FIGURE 13-1
19. Figure 13-1 above shows an example of ____.
a. the trace of an iterative method c. activation records on the call stack
b. a big-O notation d. infinite recursion
ANS: C PTS: 1 REF: 493
FIGURE 13-2
20. Figure 13-2 above shows subarrays generated during calls of ____.
a. quickSort c. mergeSort
b. binarySort d. bubbleSort
ANS: C PTS: 1 REF: 518
Case 13-1
Leslie is using Java to write a quicksort algorithm.
Case 13-2
Jarrod is using Java to write binary search algorithms.
23. Jarrod knows that if the length of his list is ____, the maximum number of steps needed to do a binary
search is 1.
a. less than 0 c. 1
b. 0 d. 2
ANS: C PTS: 1 REF: 510 TOP: Critical Thinking
24. Jarrod knows that if the length of his list is 4 to 7, the maximum number of steps needed to do a binary
search is ____.
a. 1 c. 4
b. 3 d. 7
ANS: B PTS: 1 REF: 510 TOP: Critical Thinking
COMPLETION
1. When a method is called, an activation ____________________ is added to the top of the call stack.
ANS: record
2. ____________________ analysis is used to answer the question: what is the effect on the method of
increasing the quantity of data processed?
ANS:
Complexity
Complex
ANS: notation
ANS: linear
ANS: pivot
MATCHING
Identify the letter of the choice that best matches the phrase or definition.
a. Activation record
b. Stack
c. Quadratic
d. Exponential
e. copyBuffer
1. Contains, among other things, the value returned by the method.
2. The name of the big-O value O(n squared).
3. When a method returns, its activation record is removed from the top of the ____.
4. During the merge sort process, smaller items are copied to here.
5. The name of the big-O value O(2 to the nth power).
ESSAY
1. What is a stopping state? What is a recursive step? What are the ways in which the computer provides
run-time support for recursive methods? Why do some programmers feel that recursion should be
avoided?
ANS:
In a recursive method, the stopping state is a well-defined termination point. Each method must have a
recursive step, in which the methods calls itself, and which must lead to the stopping state.
Naive programmers feel that because recursion repeatedly calls itself, and therefore takes longer and
ties up memory, it should not be used. But it is a powerful programming technique.