What is the time complexity of the binary search algorithm ?
2026
What is the time complexity of the binary search algorithm ?
- A.
O(1)
- B.
O(log n)
- C.
O(n)
- D.
O(n log n)
Attempted by 164 students.
Show answer & explanation
Correct answer: B
Binary search is an efficient algorithm used to find a target value within a sorted array. It works by repeatedly dividing the search interval in half. At each step, the algorithm compares the target value to the middle element of the array. If they are not equal, it eliminates half of the remaining elements from consideration and continues searching in the other half. This halving process repeats until the target is found or the interval becomes empty. Because the search space is reduced by half in every iteration, the number of steps required to find an element (or determine it is absent) grows logarithmically with respect to the input size n. Specifically, if we start with n elements, after k steps, the remaining search space is n / 2k . The algorithm terminates when this value reaches 1, meaning k = log₂(n). Therefore, the time complexity is O(log n). Option A (O(1)) represents constant time, which applies to direct array indexing but not iterative searching. Option C (O(n)) describes linear search, where every element is checked sequentially without halving the space. Option D (O(n log n)) is typical for efficient sorting algorithms like Merge Sort, not search operations on sorted data.