Which of the following is true about the time complexity of the Binary Search…
2025
Which of the following is true about the time complexity of the Binary Search algorithm ?
- A.
O(n)
- B.
O(log n)
- C.
O(nlog n)
- D.
O(n2)
Attempted by 90 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 based on whether the target is greater than or less than the middle element. This halving process continues until the target is found or the interval becomes empty.\nBecause the search space is reduced by half at every iteration, the maximum number of steps required to find an element (or determine it is absent) corresponds to how many times you can divide n by 2 before reaching 1. Mathematically, this is expressed as log base 2 of n, denoted as O(log n). In contrast, linear search (Option A) checks every element sequentially resulting in O(n), while sorting algorithms like Merge Sort typically run in O(n log n) (Option C). Option D, O(n^2), represents inefficient quadratic time complexities often seen in nested loops. Therefore, the correct time complexity for Binary Search is O(log n).