0% found this document useful (0 votes)
22 views7 pages

Chapter 13 APCSA

Chapter 13 covers recursion, complexity analysis, and searching and sorting algorithms. It includes true/false questions, multiple choice, and completion exercises that test understanding of concepts such as big-O notation, recursive methods, and algorithm efficiency. The chapter emphasizes the importance of stopping states in recursion and the trade-offs between recursion and iteration.

Uploaded by

ethanrhafer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Chapter 13 APCSA

Chapter 13 covers recursion, complexity analysis, and searching and sorting algorithms. It includes true/false questions, multiple choice, and completion exercises that test understanding of concepts such as big-O notation, recursive methods, and algorithm efficiency. The chapter emphasizes the importance of stopping states in recursion and the trade-offs between recursion and iteration.

Uploaded by

ethanrhafer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 13: Recursion, Complexity, and Searching and Sorting

TRUE/FALSE

1. Complexity analysis is concerned with determining an algorithm’s efficiency.

ANS: T PTS: 1 REF: 489

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.

ANS: F PTS: 1 REF: 489

3. Given a recursive definition of some process, it is usually easy to write a recursive method that
implements it.

ANS: T PTS: 1 REF: 491

4. The call stack contains, among other things, the method’s local variables.

ANS: F PTS: 1 REF: 493

5. When a method returns, its activation record is removed from the top of the stack.

ANS: T PTS: 1 REF: 493

6. Recursion and iteration can never be used in place of each other.

ANS: F PTS: 1 REF: 494

7. Computer scientists use expressions such as O(n) to express the linear relationship between an array’s
length and the execution time.

ANS: T PTS: 1 REF: 502

8. Given two methods that perform the same task, the one that is quadratic is preferable to the one that is
linear.

ANS: F PTS: 1 REF: 506

9. In a linear equation, the best-, worst-, and average-case behaviors are O(1).

ANS: F PTS: 1 REF: 508

10. Using a binary search, finding a value from a list of a million entries involves at most 20 steps.

ANS: T PTS: 1 REF: 509

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, call stack

PTS: 1 REF: 493

3. The big-O value O(1) is named logarithmic. ____________________

ANS: F, constant

PTS: 1 REF: 505

4. Because the summation algorithm must visit each number in the array, no matter how the numbers are
ordered, the algorithm is always linear. ____________________

ANS: T PTS: 1 REF: 508

5. In order to use a(n) binary search, the list must be sorted in ascending order. ____________________

ANS: T PTS: 1 REF: 509

MULTIPLE CHOICE

1. A(n) ____ algorithm is one that refers to itself.


a. recursive c. complex
b. iterative d. infinite
ANS: A PTS: 1 REF: 489

2. sum(n) =1+2+3+...+n, where n>1 is an example of a(n) ____ algorithm.


a. recursive c. complex
b. iterative d. infinite
ANS: B PTS: 1 REF: 490

3. sum(n) =n+sum(n-1), where n>1 is an example of a(n) ____ algorithm.


a. recursive c. complex
b. iterative d. infinite
ANS: A PTS: 1 REF: 490

4. A recursive method must have a well-defined ____.


a. factorial c. stopping state
b. recursive step d. stack
ANS: C PTS: 1 REF: 492

5. A recursive step, in which the method calls itself, must ____.


a. include a call to the method c. include a binary search algorithm
b. be tail-recursive d. eventually lead to the stopping state
ANS: D PTS: 1 REF: 492
6. A stack overflow error occurs when ____.
a. a user terminates a program early c. an exception is thrown
b. the Java interpreter runs out of memory d. an algorithm reaches its stopping state
ANS: B PTS: 1 REF: 492

7. An algorithm is ____ if no work is done in the algorithm after a recursive call.


a. complex c. infinite
b. iterative d. tail-recursive
ANS: D PTS: 1 REF: 501

8. The constant big-O value is ____.


a. O(1) c. O(log n)
b. O(n) d. O(n log n)
ANS: A PTS: 1 REF: 505

9. The logarithmic big-O value is ____.


a. O(1) c. O(log n)
b. O(n) d. O(n log n)
ANS: C PTS: 1 REF: 505

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

11. The ____ search algorithm is O(log n).


a. binary c. recursive
b. linear d. iterative
ANS: A 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

15. ____ is an extra array used during the merge process.


a. mergeSortHelper c. copyBuffer
b. tempSpace d. mergeBuffer
ANS: C PTS: 1 REF: 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

17. A(n) ____ object uses a highly repetitive or recursive pattern.


a. Mondrian c. abstract
b. fractal d. Euclidean
ANS: B PTS: 1 REF: 528

18. mergeSortHelper is a private method that ___.


a. implements the merging process
b. is called by clients
c. hides the extra parameter required by recursive calls
d. all of the above.
ANS: C PTS: 1 REF: 517

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.

21. Leslie must do which of the following steps?


a. Determine if the length of the array is greater than 2.
b. Locate the middle of the array.
c. Tag the elements at the left and right ends of the array.
d. All of the above.
ANS: D PTS: 1 REF: 513 TOP: Critical Thinking

22. Leslie knows that the array will be sorted ____.


a. if the tag at the left end of the array is greater than the tag at the right end of the array.
b. when the pivot is 0
c. when all of the subparts contain a single value
d. all of the above.
ANS: C PTS: 1 REF: 512 TOP: Critical Thinking

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

PTS: 1 REF: 493

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

PTS: 1 REF: 502

3. execution time = O(n) is an example of big-O ____________________.

ANS: notation

PTS: 1 REF: 502

4. The big-O value O(n) is named ____________________.

ANS: linear

PTS: 1 REF: 505

5. In a quicksort algorithm, the middle of an array is called the ____________________.

ANS: pivot

PTS: 1 REF: 513

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

1. ANS: A PTS: 1 REF: 493


2. ANS: C PTS: 1 REF: 505
3. ANS: B PTS: 1 REF: 493
4. ANS: E PTS: 1 REF: 519
5. ANS: D PTS: 1 REF: 505

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.

Computers provide the following support:


* A call stack (storage area) created at startup.
* An activation record (space for parameters, local variables, and return value).
* When a method is returned, its activation record is removed from the call stack.

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.

PTS: 1 REF: 492-494 TOP: Critical Thinking

You might also like