MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Binary search only works on ____
A
An UNSORTED Array
B
A SORTED array
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -Binary search works on sorted arrays. Binary search begins by comparing an element in the middle of the array with the target value. If the target value matches the element, its position in the array is returned. If the target value is less than the element, the search continues in the lower half of the array.

Detailed explanation-2: -Binary search can be implemented only on a sorted list of items. If the elements are not sorted already, we need to sort them first.

Detailed explanation-3: -Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half the portion of the list that could contain the item, until you’ve narrowed down the possible locations to just one.

Detailed explanation-4: -Answer. In Binary Search, the array is repeatedly divided into two halves and the element is searched in that half whose last element is greater than or equal to the element being searched. For this reason, Binary Search needs a sorted array to perform the search operation.

There is 1 question to complete.