Binary Search Algorithm
- 20Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
20 questions
- 1Binary search requires the input array to be_____.
Hint
Think about the property that allows the algorithm to eliminate half the array each step.
Answer
sorted
- 2If the target value is found in the array, binary search returns its_____.
Hint
What does the algorithm return when it finds the target?
Answer
index
- 3If the remaining search range becomes empty, binary search returns_____as the answer.
Hint
What value is commonly used to indicate 'not found'?
Answer
-1
- 4The initial search range for an array of size n (0-indexed) is from L=0 to $R =_____.
Hint
What is the index of the last element?
Answer
n−1
- 5The correct formula to compute the middle index to avoid overflow is $M = L + \frac{_____}{2}$.
Hint
Think about a safe way to compute the average without adding L and R directly.
Answer
R−L
- 6The incorrect formula M=(L+R)/2 can cause an_____when L and R are large.
Hint
What happens when the sum of two large integers exceeds the maximum value that the data type can hold?
Answer
overflow
- 7In binary search, when a[mid]<target, the new search range becomes L=mid+1 and R remains the_____.
Hint
Which bound changes when we move to the right half?
Answer
same
- 8The time complexity of binary search in the worst case is_____.
Hint
How does the size of the search space change each step?
Answer
O(logN)
- 9To check if X is a perfect square without using the square root function, we can binary search the_____.
Hint
What value, when squared, should equal X?
Answer
square root
- 10In the lower bound problem, we use a variable_____to store the best answer found so far.
Hint
What is the common name for a variable that holds the candidate answer?
Answer
ans
- 11In lower bound, when a[mid]>=target, we set ans=mid and then search the_____part for a potentially better answer.
Hint
If the current element satisfies the condition, where might a smaller (better) element be?
Answer
left
- 12In lower bound, if no element satisfies the condition, the function returns_____(or some sentinel value).
Hint
What value is returned when no element meets the condition?
Answer
-1
- 13In the rotated array problem, we compare the middle element with the_____element to decide which half to search.
Hint
Which element helps determine if we are in the left (larger) or right (smaller) part?
Answer
last
- 14In the rotated array, if a[mid]>a[last], the minimum is in the_____half.
Hint
Which side contains elements smaller than a[mid]?
Answer
right
- 15For the peak element (mountain array) problem, the condition to check is whether $a[m] >_____$.
Hint
Comparing with which neighbor tells us if we are on the increasing slope?
Answer
a[m−1]
- 16In binary search on real numbers, we stop when the distance between L and R is less than a specified_____.
Hint
What term describes the allowed error tolerance?
Answer
epsilon
- 17When performing binary search on real values, we update L=m and R=m instead of using ±1 because_____.
Hint
Why can't we use integer-style updates with real numbers?
Answer
the values are continuous
- 18Many hard binary search problems can be solved by thinking in terms of a prefix of false and suffix of true, and finding the_____between them.
Hint
What do you look for when the array can be split into two regions based on a condition?
Answer
boundary
- 19The lower bound problem finds the_____element that is >= X.
Hint
Which occurrence of such an element is needed?
Answer
first
- 20In the standard binary search for a target value, if a[mid]>target, the new search range becomes L unchanged and $R =_____.
Hint
Which side do you discard when the middle element is too large?
Answer
mid−1

Ask anything
We've read this whole study set, so questions about it get the best answers.