Recall & Review
beginner
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
In the recursive binary search, what are the base cases?
The base cases are when the search range is empty (start > end), meaning the target is not found, or when the middle element equals the target, meaning the search is successful.
Click to reveal answer
beginner
Why must the input list be sorted for binary search to work?
Because binary search decides which half to search based on comparisons, the list must be sorted to ensure that all smaller elements are on one side and larger on the other.
Click to reveal answer
intermediate
What is the time complexity of binary search and why?
The time complexity is O(log n) because each step cuts the search space in half, quickly reducing the number of elements to check.
Click to reveal answer
intermediate
How does recursion help in implementing binary search?
Recursion simplifies the code by letting the function call itself with a smaller search range until it finds the target or the range is empty.
Click to reveal answer
What should happen if the middle element is equal to the target in recursive binary search?
✗ Incorrect
If the middle element matches the target, the search is successful and the middle index is returned.
What condition ends the recursive binary search when the target is not found?
✗ Incorrect
When the start index becomes greater than the end index, it means the search range is empty and the target is not in the list.
Which of these is required for binary search to work correctly?
✗ Incorrect
Binary search requires a sorted list to decide which half to search next.
What is the time complexity of binary search?
✗ Incorrect
Binary search cuts the search space in half each step, leading to O(log n) time complexity.
In recursive binary search, what parameters typically change with each recursive call?
✗ Incorrect
Each recursive call narrows the search range by updating the start or end index.
Explain how recursive binary search works step-by-step on a sorted list.
Think about how the list is split and how the function calls itself.
You got /4 concepts.
Describe why the list must be sorted for binary search and what happens if it is not.
Consider how binary search decides which half to search next.
You got /3 concepts.