Skills101
← All practice quizzes

Binary Search Quiz

8 questions10 minPass: 60%+10 XP on first pass

The classic template, lower bound, overflow-safe mid, rotated arrays and binary search on the answer.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    About how many comparisons does binary search need on 1,000,000 sorted numbers?

  2. Question 2

    Why is mid = lo + (hi - lo) / 2 preferred over (lo + hi) / 2 in Java?

  3. Question 3

    What does this return for nums = [1, 3, 5, 7], target = 4?

    lo, hi = 0, len(nums)
    while lo < hi:
        mid = (lo + hi) // 2
        if nums[mid] < target:
            lo = mid + 1
        else:
            hi = mid
    print(lo)
    
  4. Question 4Select all that apply

    Which statements about binary search are true? (select all that apply)

  5. Question 5

    In a rotated sorted array like [4, 5, 6, 7, 0, 1, 2], what is always true at any mid?

  6. Question 6

    "Binary search on the answer" works when…

  7. Question 7

    Koko eats piles [3, 6, 7, 11] and has h = 8 hours. What is the minimum speed k?

  8. Question 8

    Which loop pairing can cause an infinite loop?