PrepGo

AP Computer Science Principles Practice Quiz: Binary Search

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 10 questions to check your progress.

Question 1 of 10

What is the most fundamental requirement for a data set before a binary search algorithm can be correctly applied?

All Questions (10)

What is the most fundamental requirement for a data set before a binary search algorithm can be correctly applied?

A) The data set must contain only positive numbers.

B) The data set must have an even number of elements.

C) The data set must be in sorted order.

D) The data set must be stored in an array.

Correct Answer: C

The provided content explicitly states, 'Data must be in sorted order to use the binary search algorithm.' This is a non-negotiable prerequisite for the algorithm to function as intended.

According to the description, where does the binary search algorithm begin its process within a data set?

A) At the first element.

B) At the middle of the data set.

C) At the last element.

D) At a randomly chosen element.

Correct Answer: B

The content specifies that 'The binary search algorithm starts at the middle of a sorted data set of numbers...'

In each iteration of a binary search, what happens to the portion of the data set being considered?

A) A single element is eliminated.

B) The order of the elements is reversed.

C) It is combined with another data set.

D) Half of the data is eliminated.

Correct Answer: D

The provided text states that the algorithm 'eliminates half of the data; this process repeats until the desired value is found.'

When is a binary search considered to be more efficient than a sequential/linear search?

A) When the data is unsorted.

B) When the target value is the very first element in the list.

C) When the data is sorted.

D) They are always equally efficient.

Correct Answer: C

The content makes a direct comparison: 'Binary search is often more efficient than sequential/linear search when applied to sorted data.'

A binary search process continues until one of two conditions is met. What are these two conditions?

A) The first element is checked and the last element is checked.

B) The data is sorted and the middle is found.

C) The desired value is found or all elements have been eliminated.

D) The list is split in half and then re-sorted.

Correct Answer: C

The description of the algorithm's process concludes that 'this process repeats until the desired value is found or all elements have been eliminated.'

A programmer attempts to use a binary search on a list of numbers that is not sorted. What is a likely consequence?

A) The algorithm will automatically sort the list before searching.

B) The search will be more efficient than if the list were sorted.

C) The algorithm may incorrectly report that a value is not in the list, even when it is.

D) The algorithm will function correctly but will take as long as a linear search.

Correct Answer: C

The algorithm's logic of eliminating half the data depends entirely on the 'Data must be in sorted order' requirement. If this requirement is not met, the elimination process is flawed and can lead to discarding the half of the list that actually contains the target value.

Consider a sorted data set of 16 elements. What is the maximum number of iterations a binary search would take to find a value or determine it's not present?

A) 16

B) 8

C) 4

D) 1

Correct Answer: C

Based on the principle of eliminating half the data in each step: After 1 iteration, 8 elements remain. After 2 iterations, 4 elements remain. After 3 iterations, 2 elements remain. After 4 iterations, 1 element remains, which is the final comparison. This aligns with the task to 'Determine the number of iterations required'.

Which statement best summarizes the core principle that makes binary search efficient?

A) It checks every item to guarantee accuracy.

B) It dramatically reduces the search area with each step.

C) It works well with small, unsorted data sets.

D) It uses a random-access approach to find the value instantly.

Correct Answer: B

The efficiency comes from the fact that it 'eliminates half of the data' in each step. This rapid reduction of the search area is why it is 'often more efficient than sequential/linear search.'

A binary search is performed on the sorted list [2, 5, 8, 12, 16, 23, 38, 56]. The first step in the search for the value 23 would be to compare 23 to which number?

A) 2

B) 56

C) 12

D) 16

Correct Answer: D

The algorithm 'starts at the middle of a sorted data set'. In a list of 8 elements, the middle can be considered the 4th or 5th element. In most implementations, it would be the 4th element (index 3), which is 12, or the 5th element (index 4), which is 16. The search compares the target to the middle value. If the target is greater, it eliminates the first half. If the list has an even number of elements, there are two 'middle' elements; standard implementations will pick one (e.g., the lower-indexed one, 12, or higher-indexed one, 16). After comparing to 16, the algorithm would eliminate 16 and everything before it.

If performing a binary search on a sorted data set of size N requires a maximum of K iterations, what is the approximate maximum number of iterations required for a sorted data set of size 2N?

A) 2K

B) K + 1

C) K * K

D) K

Correct Answer: B

Because the algorithm 'eliminates half of the data' with each iteration, doubling the total number of elements only adds one more step of division to the process. For example, if 8 elements take 3 iterations, doubling to 16 elements will only require one additional iteration (4 total). This demonstrates the logarithmic efficiency implied by the search method.