Skip to main contentSkip to solution

What is the time complexity of the binary search algorithm, if the target element is present at the exact middle of the list? Consider 'n' as number of elements and is odd.

Solution

✅ Correct Option: 2

Binary search first compares the target with the element at index mid=⌊low+high2⌋mid = \left\lfloor \dfrac{low + high}{2} \right\rfloor. When nn is odd, this index is the exact middle of the list.

If the target is there, it is found in the very first comparison, whatever the value of nn. The number of steps is constant, so the time complexity is O(1)O(1). This is the best case of binary search.


Option 3: O(log⁡2n)O(\log_2 n) is the worst and average case, when the target is found only after repeatedly halving the list or is absent. It is not the case here.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question