Recall & Review
beginner Click to reveal answer
What is the main idea behind the binary search algorithm?
Binary search finds an item in a sorted list by repeatedly dividing the search range in half until the item is found or the range is empty.
beginner Click to reveal answer
In the iterative binary search, what variables are used to keep track of the search range?
Two variables, usually called
low and high, mark the start and end of the current search range in the list.intermediate Click to reveal answer
Why do we calculate the middle index as
mid = low + (high - low) // 2 instead of (low + high) // 2?Calculating
mid this way avoids potential overflow errors when low and high are very large numbers.beginner Click to reveal answer
What condition ends the iterative binary search loop?
The loop ends when
low becomes greater than high, meaning the search range is empty and the item is not found.beginner Click to reveal answer
What is the time complexity of the binary search algorithm?
Binary search runs in O(log n) time, where
n is the number of elements in the list.What must be true about the list for binary search to work correctly?
✗ Incorrect
Binary search requires the list to be sorted to correctly divide and conquer the search space.
In iterative binary search, what happens if the target is less than the middle element?
✗ Incorrect
If the target is less than the middle element, the search continues in the left half by updating the high index.
Which variable is updated when the target is greater than the middle element in iterative binary search?
✗ Incorrect
When the target is greater, the low index is updated to narrow the search to the right half.
What is the initial value of
low in iterative binary search?✗ Incorrect
low starts at 0, the first index of the list.What does the iterative binary search return if the target is not found?
✗ Incorrect
Returning -1 is a common way to indicate the target is not found in the list.
Explain how the iterative binary search algorithm works step-by-step.
Think about how you cut the search space in half each time.
You got /5 concepts.
Describe why binary search is faster than linear search on sorted lists.
Consider how many elements you skip each step.
You got /4 concepts.
