What is the main idea behind the binary search algorithm?
Binary search works by repeatedly dividing a sorted list in half to find a target value quickly. It compares the target with the middle element and decides which half to search next.
Click to reveal answer
beginner
What is the base case in a recursive binary search?
The base case occurs when the search range is empty (start index > end index), meaning the target is not found, or when the middle element equals the target.
Click to reveal answer
beginner
How does the recursive call change the search range in binary search?
If the target is less than the middle element, the search continues on the left half (start to mid - 1). If greater, it continues on the right half (mid + 1 to end).
Click to reveal answer
beginner
Why must the input array be sorted for binary search to work?
Binary search relies on the order of elements to decide which half to search next. Without sorting, it cannot correctly eliminate half the elements each step.
Click to reveal answer
beginner
What is the time complexity of binary search and why?
The time complexity is O(log n) because the search space halves with each recursive call, quickly narrowing down to the target or concluding it is absent.
Click to reveal answer
In recursive binary search, what happens if the target is equal to the middle element?
AReturn -1 indicating not found
BSearch the left half of the array
CSearch the right half of the array
DReturn the middle index as the found position
✗ Incorrect
If the target equals the middle element, the search is successful and the middle index is returned.
What condition ends the recursion in binary search when the target is not found?
AMiddle index equals start index
BStart index becomes greater than end index
CTarget is less than middle element
DTarget is greater than middle element
✗ Incorrect
When the start index is greater than the end index, it means the search range is empty and the target is not present.
Which of these is required for binary search to work correctly?
AArray must be reversed
BArray must be unsorted
CArray must be sorted
DArray must contain only unique elements
✗ Incorrect
Binary search requires a sorted array to correctly decide which half to search next.
What is the time complexity of binary search?
AO(log n)
BO(n log n)
CO(n)
DO(1)
✗ Incorrect
Binary search halves the search space each step, resulting in O(log n) time complexity.
In recursive binary search, if the target is less than the middle element, what is the next step?
ASearch the left half (start to mid - 1)
BSearch the right half (mid + 1 to end)
CReturn the middle index
DReturn -1
✗ Incorrect
If the target is less than the middle element, the search continues on the left half.
Explain how recursive binary search works step-by-step on a sorted array.
Think about dividing the array and calling the function again with smaller ranges.
You got /6 concepts.
Describe why the array must be sorted for binary search and what happens if it is not.
Consider how you decide which half to search next.
You got /3 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. Use a queue to store elements and search iteratively.
B. Check every element one by one from start to end.
C. Sort the array first and then search linearly.
D. Divide the array into halves and search recursively in the half where the value can be.
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 the middle element.
Step 2: Recognize recursive approach
The recursive approach calls the same search function 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 D