What is the main idea behind the binary search algorithm?
Binary search finds an item in a sorted list by repeatedly dividing the search interval in half, checking the middle element, and deciding which half to search next.
Click to reveal answer
beginner
In the recursive binary search, what are the base cases?
The base cases are when the search interval is empty (start index > end index), meaning the item is not found, or when the middle element equals the target, meaning the item is found.
Click to reveal answer
beginner
Why must the input array be sorted for binary search to work?
Because binary search decides which half to search based on comparisons, the array must be sorted to guarantee that all smaller elements are on one side and larger on the other.
Click to reveal answer
intermediate
What parameters are typically passed in a recursive binary search function?
The function usually takes the array, the target value, the start index, and the end index to define the current search interval.
Click to reveal answer
intermediate
How does the recursive binary search reduce the problem size at each step?
It calculates the middle index and then calls itself on either the left half or the right half of the array, effectively halving the search space each time.
Click to reveal answer
What is the time complexity of binary search in the worst case?
AO(n log n)
BO(n)
CO(log n)
DO(1)
✗ Incorrect
Binary search divides the search space in half each time, leading to a logarithmic time complexity O(log n).
In recursive binary search, what happens if the target is less than the middle element?
ASearch the left half
BSearch the right half
CReturn -1 immediately
DReturn the middle index
✗ Incorrect
If the target is less than the middle element, the search continues recursively on the left half.
Which of these is NOT a parameter in a typical recursive binary search function?
AStart and end indices of the search range
BTarget value
CArray to search
DCurrent index of the target
✗ Incorrect
The current index of the target is not known beforehand; the function uses start and end indices to narrow the search.
What should the recursive binary search function return if the target is not found?
AThe middle index
B-1 or a sentinel value
C0
DThe start index
✗ Incorrect
Returning -1 or a sentinel value indicates the target is not present in the array.
Why is recursion useful in binary search?
AIt makes the code shorter and easier to understand by breaking the problem into smaller parts.
BIt makes the search faster than iterative methods.
CIt avoids the need for a sorted array.
DIt uses more memory but less CPU.
✗ Incorrect
Recursion simplifies the code by handling smaller subproblems, though iterative binary search can be equally efficient.
Explain how recursive binary search works step-by-step on a sorted array.
Think about how the problem size reduces each time.
You got /4 concepts.
Describe the base cases in recursive binary search and why they are important.
Base cases stop the recursion and give the answer.
You got /4 concepts.
Practice
(1/5)
1. What is the main idea behind the binary search recursive approach when searching for a value in a sorted array?
easy
A. Divide the array into halves and search recursively in the half where the value can be.
B. Check every element one by one from start to end.
C. Sort the array first and then search linearly.
D. Use a loop to check elements until the value is found.
Solution
Step 1: Understand binary search logic
Binary search works by dividing the sorted array into two halves and deciding which half to search next based on comparison.
Step 2: Recognize recursive approach
In recursion, the function calls itself on the half where the target value may exist, reducing the search space each time.
Final Answer:
Divide the array into halves and search recursively in the half where the value can be. -> Option A