Practice mode Data Structures

What is the maximum number of comparisons binary search needs to find a key in a sorted array of 1000 elements?

Correct answer D. 10

Explanation

Each comparison halves the remaining range, so the worst case is floor(log₂ n) + 1 comparisons. Since 2^9 = 512 and 2^10 = 1024, floor(log₂ 1000) is 9, giving 10. Linear search could need all 1000 comparisons, which shows why binary search's O(log n) cost matters for large sorted data.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.