Easy · O(log n)
Binary Search quiz
Answer the questions in your own time, change a pick whenever you like, then hand in to see your score and why each answer is right. Nothing is saved or sent.
Questions (10)
- Viewing
- Answered
- Not answered
binarySearch looks for 23 in [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]. Which indexes does the loop look at, in order?
The listing computes mid = lo + Math.floor((hi - lo) / 2) instead of Math.floor((lo + hi) / 2). Why?
What does binarySearch([], 3) return?
binarySearch([1, 3, 5, 7, 9, 11, 13, 15], 12) fails to find 12. What are lo and hi when the loop stops?
In [1, 2, 2, 2, 2, 2, 3], which index does binarySearch(sorted, 2) return?
What does lowerBound([1, 3, 5, 7], 9) return?
binarySearch runs on a sorted array of 1,000,000 numbers. At most how many times can the loop look at the middle?
binarySearch runs on [4, 1, 3, 2, 5], which is not sorted, with target 1. What does it return?
A typo changes lo = mid + 1 to lo = mid in binarySearch. What does binarySearch([1, 3], 3) do?
For a = [1, 5, 5, 5, 7, 9], what is lowerBound(a, 6) - lowerBound(a, 5)?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10
Take it further
- AnimationSearching
Binary Search Animation
A step-by-step binary search with gliding lo / mid / hi pointers, ready for your lessons, slides and posts
Free
