Chapter3 - Test Bank
Chapter3 - Test Bank
1. Describe an algorithm that takes a list of n integers a1 , a2 , . . . , an and finds the number of integers each
greater than five in the list.
2. Describe an algorithm that takes a list of integers a1 , a2 , . . . , an (n ≥ 2 ) and finds the second-largest integer in
the sequence by going through the list and keeping track of the largest and second-largest integer encountered.
3. Describe an algorithm that takes a list of n integers ( n ≥ 1 ) and finds the location of the last even integer
in the list, and returns 0 if there are no even integers in the list.
4. Describe an algorithm that takes a list of n integers ( n ≥ 1 ) and finds the average of the largest and smallest
integers in the list.
5. Express a brute-force algorithm that finds the second largest element in a list a1 , a2 , . . . , an ( n ≥ 2 ) of
distinct integers by finding the largest element, placing it at the beginning of the sequence, then finding the
largest element of the remaining sequence.
6. Express a brute-force algorithm that finds the largest product of two numbers in a list a1 , a2 , . . . , an ( n ≥ 2 )
that is less than a threshold N .
7. Describe in words how the binary search works.
8. List all the steps the binary search algorithm uses to search for 27 in the following list: 5, 6, 8, 12, 15, 21, 25, 31 .
Chapter 3 Test Bank 495