AP Computer Science A Quiz
7 questions · no time limit
0:00
DATA COLLECTIONS
Question 1 of 7
No time limit
Current
Answered
Flagged
Not seen
PASSAGE
public class SearchAnalyzer {
private static int comparisons = 0;
public static boolean mysterySearch(int[] arr, int target) {
comparisons = 0;
return search(arr, target, 0, arr.length - 1);
}
private static boolean search(int[] arr, int target, int low, int high) {
if (low > high) return false;
int mid = (low + high) / 2;
comparisons++;
if (arr[mid] == target) return true;
boolean leftResult = search(arr, target, low, mid - 1);
boolean rightResult = search(arr, target, mid + 1, high);
return leftResult || rightResult;
}
public static int getComparisons() { return comparisons; }
}
What type of search algorithm does the
mysterySearch method implement, and how many comparisons will be made when searching for a value that exists at the last position of a sorted array with 15 elements? YOUR PROGRESS
7
QUESTIONS
Ready when you are
Answer in any order. Your progress shows here as you go.
QUESTIONS
KEYBOARD
Pick an answer ABCD
Next question ↵→
Previous ←
Flag for review F
Answers save as you go · flagged questions come back at the end