Binary Search Complexity: Why the Correct Choice is O(logn)O(\log n)

Binary Search Complexity: Why the Correct Choice is O(logn)O(\log n)

Verified Sources
Sep 11, 2026

Binary search works on a sorted array by repeatedly comparing the target to the middle element and discarding half of the remaining search interval each step. This halving implies that the number of iterations (and thus the running time in the worst case) grows proportionally to a logarithm in nn, giving time complexity O(logn)O(\log n).2

Answer to the multiple-choice question: (ii) O(logn)O(\log n).

Key notions to keep straight: binary search; time complexity; worst-case; logarithmic.

Footnotes

  1. Binary search (Wikipedia) - States classical binary search performs lfloorlog2(n)+1rfloor\\lfloor \\log_2(n)+1\\rfloor iterations in the worst case and describes constant work per iteration.

  2. Time and Space Complexity Analysis of Binary Search Algorithm (GeeksforGeeks) - Explicitly states binary search time complexity is O(logn)O(\\log n) by halving each step; also discusses best/average/worst.

Why Binary Search is O(log n)

  1. 1
    Step 1

    At the beginning, the candidate search range has nn elements.

  2. 2
    Step 2

    After comparing to the middle element, binary search keeps only one half, so the interval size becomes n/2n/2, then n/4n/4, etc.2

    Footnotes

    1. Binary search (Wikipedia) - States classical binary search performs lfloorlog2(n)+1rfloor\\lfloor \\log_2(n)+1\\rfloor iterations in the worst case and describes constant work per iteration.

    2. Time and Space Complexity Analysis of Binary Search Algorithm (GeeksforGeeks) - Explicitly states binary search time complexity is O(logn)O(\\log n) by halving each step; also discusses best/average/worst.

  3. 3
    Step 3

    After kk iterations the interval size is n2k\frac{n}{2^k}. Binary search stops when n2k1\frac{n}{2^k} \le 1.

  4. 4
    Step 4

    Setting n2k=1\frac{n}{2^k}=1 gives 2k=n2^k=n, so k=log2(n)k=\log_2(n), hence the number of steps is Θ(logn)\Theta(\log n) and the time is O(logn)O(\log n).2

    Footnotes

    1. Binary search (Wikipedia) - States classical binary search performs lfloorlog2(n)+1rfloor\\lfloor \\log_2(n)+1\\rfloor iterations in the worst case and describes constant work per iteration.

    2. Binary Search Algorithm (EnjoyAlgorithms) - Derives T(n)=T(n/2)+cT(n)=T(n/2)+c and concludes O(logn)O(\\log n), matching the halving argument.

  5. 5
    Step 5

    Each iteration performs a constant amount of work (computing the mid index and a comparison), so total time stays O(logn)O(\log n).2

    Footnotes

    1. Binary search (Wikipedia) - States classical binary search performs lfloorlog2(n)+1rfloor\\lfloor \\log_2(n)+1\\rfloor iterations in the worst case and describes constant work per iteration.

    2. Time and Space Complexity Analysis of Binary Search Algorithm (GeeksforGeeks) - Explicitly states binary search time complexity is O(logn)O(\\log n) by halving each step; also discusses best/average/worst.

Matching the options

Because binary search’s interval size shrinks by a factor of 2 each step, the worst-case number of iterations is logarithmic in nn.2 Therefore:

  • (i) O(n)O(n) — incorrect (that would correspond to checking one element per step, like linear search).
  • (ii) O(logn)O(\log n) — correct.
  • (iii) O(n2)O(n^2) — incorrect (quadratic time would require something like nested loops over nn).
  • (iv) O(nlogn)O(n \log n) — incorrect (that growth typically comes from combining linear work across logn\\log n levels, e.g., merge sort, not from halving a single search interval).

To contrast, linear search has worst-case time O(n)O(n), while binary search on sorted data has time O(logn)O(\log n).

Footnotes

  1. Binary search (Wikipedia) - States classical binary search performs lfloorlog2(n)+1rfloor\\lfloor \\log_2(n)+1\\rfloor iterations in the worst case and describes constant work per iteration.

  2. Time and Space Complexity Analysis of Binary Search Algorithm (GeeksforGeeks) - Explicitly states binary search time complexity is O(logn)O(\\log n) by halving each step; also discusses best/average/worst.

  3. Linear Search vs Binary Search (GeeksforGeeks) - Compares complexities: linear search O(n)O(n) vs binary search O(logn)O(\\log n) and notes sorted requirement. 2

Time complexity growth (intuition)

Conceptual comparison of common Big-O rates (not measured runtime).

Common pitfalls & clarifications

Pro Tip

When you see an algorithm that repeatedly halves the input size, immediately consider logn\log n complexity—then verify that each iteration does only constant work.

Warning

Don’t confuse binary search with algorithms that divide and solve subproblems recursively without halving the search interval. Binary search halves the interval and follows only one branch, so it stays O(logn)O(\log n); many divide-and-conquer algorithms branch into more work and can become O(nlogn)O(n \log n).

Binary search lifecycle in one run

Initial interval

Step 1

Search range size: nn."

After first comparison

Step 2

Range size reduces to n/2n/2."

After $k$ comparisons

Step 3

Range size is n/2kn/2^k."

Termination

Final

Stop when range size reaches 1 → klog2(n)k \approx \log_2(n) → time O(logn)O(\log n)."

Knowledge Check

Question 1 of 4
Q1Single choice

The complexity of binary search (worst case) is: