The time taken by the binary search algorithm to search a key in a sorted…

20072007

The time taken by the binary search algorithm to search a key in a sorted array of n elements is:

  1. A.

    O ( log2n )

  2. B.

    O ( n )

  3. C.

    O ( n log2n )

  4. D.

    O ( n2)

Attempted by 385 students.

Show answer & explanation

Correct answer: A

Binary search operates on sorted arrays by repeatedly dividing the search interval in half. In each iteration, the algorithm compares the target key with the middle element and eliminates half of the remaining elements from consideration. This halving process continues until the key is found or the interval becomes empty. Since the search space reduces by a factor of 2 in each step, the time complexity is logarithmic, specifically O(log n).

Explore the full course: Isro