PrepGo

AP Computer Science A Practice Quiz: Searching Algorithms

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

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

Question 1 of 9

What is the fundamental process of a linear search algorithm?

All Questions (9)

What is the fundamental process of a linear search algorithm?

A) It repeatedly divides the search interval in half.

B) It checks each element of a collection in sequential order.

C) It requires the collection to be sorted before searching.

D) It randomly accesses elements until the target is found.

Correct Answer: B

The provided content states that linear search algorithms are standard algorithms that 'check each element in order until the desired value is found'.

A linear search is performed on an array. Under which condition will the algorithm have to check every single element in the array?

A) When the desired value is the first element.

B) When the desired value is the last element or not in the array at all.

C) When the array is sorted in descending order.

D) When the desired value is located in the middle of the array.

Correct Answer: B

The algorithm stops when the value is found or all elements have been checked. If the value is the very last element, or if it is not present, the search must proceed through all elements to confirm.

According to the provided text, which of the following is a valid implementation of a linear search?

A) A search that begins at the first element and moves towards the last.

B) A search that begins at the last element and moves towards the first.

C) A search that begins at the middle element.

D) Both A and B are valid implementations.

Correct Answer: D

The content explicitly states that 'Linear search algorithms can begin the search process from either end of the array or ArrayList,' which includes starting from the beginning (A) or the end (B).

How is a linear search algorithm applied to a 2D array to find a specific value?

A) The 2D array is converted to a 1D array, and then a single linear search is performed.

B) A linear search is performed only on the diagonal elements of the 2D array.

C) Each row is accessed, and then a linear search is individually applied to each of these rows.

D) A linear search is performed on the first row and the first column only.

Correct Answer: C

The provided text specifies the procedure for 2D arrays: 'each row must be accessed then linear search applied to each row of the 2D array.'

Consider the array `[4, 8, 1, 9, 5]`. A linear search starting from the first element is executed to find the value 9. How many elements are checked before the search successfully terminates?

A) 1

B) 3

C) 4

D) 5

Correct Answer: C

The algorithm checks each element in order. It will check 4 (1st), 8 (2nd), 1 (3rd), and finally 9 (4th). The search stops after checking 4 elements.

A developer writes code to search for a value in an ArrayList. The code implements a loop that iterates from the first index to the last, comparing the element at each index to the target value. What algorithm is being developed?

A) Binary search

B) Selection sort

C) Merge sort

D) Linear search

Correct Answer: D

The description of checking each element in order from beginning to end matches the definition of a linear search algorithm provided in the content.

A program searches for the number 15 in the 2D array `[[5, 10], [15, 20], [25, 30]]`. Using the specified linear search method for 2D arrays, what is the sequence of events?

A) The program checks 5, then 15, and terminates.

B) The program checks all elements in the first row (5, 10), then checks the first element of the second row (15), and terminates.

C) The program checks the first element of each row (5, 15, 25) and terminates after finding 15.

D) The program checks all elements in the entire 2D array before determining the location of 15.

Correct Answer: B

The algorithm for 2D arrays requires accessing each row and applying a linear search. It would access the first row `[5, 10]` and check both elements. Then it would access the second row `[15, 20]` and check the first element, 15, at which point the search would find the value and terminate.

When does a linear search algorithm stop executing?

A) Only after the desired value is found.

B) Only after all elements in the collection have been checked.

C) When either the desired value is found or all elements have been checked.

D) When the collection is determined to be unsorted.

Correct Answer: C

The text states the search continues 'until the desired value is found or all elements in the array or ArrayList have been checked.' This covers both the success and failure cases.

Which statement accurately reflects a key aspect of linear search based on the provided content?

A) Linear search is only applicable to 1D arrays and not 2D arrays.

B) The search process must always begin from the first element at index 0.

C) Linear search can be used to find information in a collection by checking elements sequentially.

D) For a linear search to work, the data in the collection must be numeric.

Correct Answer: C

The core purpose described is to 'search for specific information in a collection' by 'check[ing] each element in order.' The other options are incorrect as the text mentions its use on 2D arrays and that it can start from either end.