Data Structures & AlgorithmsEasyCognizant · Capgemini pattern

What is the worst-case time complexity of binary search on a sorted array of n elements?

  1. A. O(n log n)
  2. B. O(1)
  3. C. O(log n)
  4. D. O(n)

Correct answer: C. O(log n)

Each comparison halves the search range, so at most about log₂ n + 1 comparisons are needed: O(log n). O(n) is linear search.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic