146k views
4 votes
Explain briefly why binary search is more efficient than linear search? What additional condition must be satisfied to replace linear search with binary search?

User Secavfr
by
7.6k points

1 Answer

0 votes

Final answer:

Binary search is more efficient than linear search because it reduces the search space in half with each iteration. To replace linear search with binary search, the array must be sorted.

Step-by-step explanation:

Binary search is more efficient than linear search because it reduces the search space in half with each iteration. In binary search, the array must be sorted beforehand, and the search starts in the middle. If the target element is greater than the middle element, the search continues in the right half of the array; otherwise, it continues in the left half. This process is repeated until the target element is found or the search space is exhausted.

To replace linear search with binary search, the additional condition that must be satisfied is that the array must be sorted in ascending order. If the array is not sorted, binary search will not work correctly and may give incorrect results.

User DLaw
by
8.0k points

No related questions found