Practice mode Data Structures

Which condition must hold before binary search can be applied to an array?

Correct answer C. The array must be sorted

Explanation

Binary search compares the target with the middle element and discards the half that cannot contain it, which only works if the elements are in order. Duplicates are allowed, and the size can be anything. It also needs constant-time random access, so it suits arrays rather than linked lists, where reaching the middle element already costs linear time.

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.