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 index > end index), 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 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 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, reducing the problem size exponentially until the target is found or the search space is empty.
Click to reveal answer
intermediate
How does recursion help in implementing binary search?
Recursion allows the function to call itself with a smaller search range, simplifying the code by handling the search in smaller parts until the base case is reached.
Click to reveal answer
What should happen if the middle element equals the target in recursive binary search?
✗ Incorrect
If the middle element matches the target, the search is successful and the function returns the middle index.
What is the first step in each recursive call of binary search?
✗ Incorrect
Each recursive call calculates the middle index to compare the target with the middle element.
What happens if the start index becomes greater than the end index in recursive binary search?
✗ Incorrect
When start > end, the search range is empty, so the target is not in the array.
Which of these is NOT a requirement for binary search to work correctly?
✗ Incorrect
Binary search works with duplicates as well; uniqueness is not required.
What is the advantage of using recursion in binary search?
✗ Incorrect
Recursion breaks the problem into smaller parts, making the code easier to understand and write.
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 parts.
You got /6 concepts.
Describe the base cases in recursive binary search and why they are important.
Base cases tell the function when to stop searching.
You got /4 concepts.