MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What must be true before performing a binary search?
A
The elements must be sorted.
B
It can only contain binary values.
C
The elements must be some sort of number (i.e. int, double, Integer)
D
There are no necessary conditions.
Explanation: 

Detailed explanation-1: -What must be true before performing a binary search? The elements must be sorted. It can only contain binary values.

Detailed explanation-2: -Binary search works only on a sorted set of elements. To use binary search on a collection, the collection must first be sorted. When binary search is used to perform operations on a sorted set, the number of iterations can always be reduced on the basis of the value that is being searched.

Detailed explanation-3: -Answer: Correct option is 3) If there are two numbers that are equal to the search item, it can pick any one of those depending on the implementation. Explanation: A binary search algorithm is an alternative to linear/sequential search algorithm.

Detailed explanation-4: -Binary search is faster than linear search except for small arrays. However, the array must be sorted first to be able to apply binary search.

Detailed explanation-5: -True, Binary search is applied only on the sorted list it can not apply to an unsorted list. Whereas linear search is applicable for all types of lists.

There is 1 question to complete.