Algorithms Analysis 2025 – 400 Free Practice Questions to Pass the Exam

Question: 1 / 400

What is the asymptotic complexity of a binary search?

O(n)

O(log n)

The asymptotic complexity of a binary search is O(log n) because this algorithm effectively reduces the search space by half with each iteration.

To understand this, consider how binary search operates: it begins with a sorted array and repeatedly divides the array into two halves. By comparing the target value to the middle element of the array, the algorithm determines whether the target lies in the left half or the right half. It then eliminates one of these halves from consideration, focusing solely on the remaining portion where the target could exist. This halving process leads to a logarithmic reduction in the number of elements to be checked.

In terms of performance, if you have n elements in the array, the process would proceed as follows:

1. After the first comparison, you're down to n/2 elements.

2. After the second comparison, it’s n/4 elements.

3. After the third, n/8 elements, and so on.

This pattern continues until you are left with one element. The number of times you can halve n until you reach 1 is represented mathematically as log base 2 of n, often denoted simply as log n in Big O notation. Hence, the time complexity of binary search is O(log n),

Get further explanation with Examzify DeepDiveBeta

O(n log n)

O(1)

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy