Sobes.tech
Senior

What is the complexity of the binary search algorithm O?

sobes.tech AI

Answer from AI

The complexity of binary search algorithm is O(log n).

Explanation:

  • Binary search works on a sorted array, dividing the search area in half each time.
  • At each step, the number of considered elements is halved.
  • Therefore, the number of steps is proportional to the logarithm of the array size.

Example: if the array has 1,000,000 elements, binary search will perform approximately 20 comparisons (log₂(1,000,000) ≈ 20).

What is the complexity of the binary search algorithm… - sobes.tech