AP Computer Science Principles Mid-Term Exam Review Binary Search

¡Supera tus tareas y exámenes ahora con Quizwiz!

The list listOne is a sorted list of numbers that contains 700 elements. The list listTwo is a sorted list of numbers that contains 900 elements. Let x represent the maximum number of list elements that will need to be examined when performing a binary search for a value in listOne, and let y represent the maximum number of list elements that will need to be examined when performing a binary search for a value in listTwo. Which of the following statements about x and y is true? A. The value of x is approximately equal to the value of y. B. The value of x is approximately 10 less than the value of y. C. The value of x is approximately 13 less than the value of y. D. The value of x is approximately 200 less than the value of y.

A. The value of x is approximately equal to the value of y.

A time stamp indicates the date and time that a measurement was taken. A data scientist has a list containing 10,000 time stamps, sorted in chronological order. Which of the following is closest to the maximum number of values that will need to be examined when performing a binary search for a value in the list? A. 10 B. 15 C. 5,000 D. 10,000

B. 15

A sorted list of numbers contains 200 elements. Which of the following is closest to the maximum number of list elements that will need to be examined when performing a binary search for a particular value in the list? A. 5 B. 8 C. 100 D. 200

B. 8

Suppose that a list of numbers contains values [-4, -1, 1, 5, 2, 10, 10, 15, 30]. Which of the following best explains why a binary search should NOT be used to search for an item in this list? A. The list contains both positive and negative elements. B. The elements of the list are not sorted. C. The list contains an odd number of elements. D. The list contains duplicate elements.

B. The elements of the list are not sorted.

A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in order for a researcher to obtain the correct result when using a binary search algorithm to determine if a given genetic code is in the list? A. The genetic codes must be converted from binary to decimal numbers. B. The list must be sorted based on the genetic code values. C. The number of genetic code values in the list must be a power of 2. D. The number of genetic code values in the list must be even.

B. The list must be sorted based on the genetic code values.

For which of the following lists can a binary search be used to search for an item in the list? ["blue", "green", "jade", "mauve", "pink"] [5, 5, 5, 5, 6, 7, 8, 8, 8] [10, 5, 3, 2, -4, -8, -9, -12] A. I only B. III only C. I and III only D. I, II, and III

D. I, II, and III


Conjuntos de estudio relacionados

Weather and the Atmosphere Final Exam

View Set

Week 2: Amino Acid and Protein Structure

View Set

American History - Unit 4 Lesson 4

View Set