117k views
4 votes
Which of these statements is true of a binary search algorithm?

A) It is only applicable to sorted arrays.
B) It has a time complexity of O(n).
C) It is not efficient for large datasets.
D) It works well for unsorted lists.

User Lena Bru
by
8.7k points

1 Answer

6 votes

Final answer:

The correct statement about binary search is that it is only applicable to sorted arrays. It is efficient due to its O(log n) time complexity and does not work with unsorted lists.

Step-by-step explanation:

The true statement about a binary search algorithm is A) It is only applicable to sorted arrays. A binary search repeatedly divides a sorted array into two halves, compares the target value to the middle element, and continues the search in the half where the target value could be. The time complexity of binary search is O(log n), not O(n), which makes statement B incorrect. Due to its logarithmic time complexity, binary search is actually very efficient for large datasets, which makes statement C incorrect. Lastly, because binary search relies on the elements being sorted to work correctly, it does not work well for unsorted lists, hence statement D is also incorrect.

User Ben Gale
by
7.9k points