MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many searches will it take to find 10 in [1, 3, 5, 7, 10, 12, 15] using BINARY search?
A
3
B
4
C
5
D
6
Explanation: 

Detailed explanation-1: -It would take only three iterations with the Binary Search algorithm. However, the main disadvantage of the Binary Search algorithm is that it requires a sorted array to discard half of the search space at each iteration.

Detailed explanation-2: -In a binary search algorithm, the array taken gets divided by half at every iteration. Again dividing by half in the third iteration will make the array’s length = (n/2)/2=n/(2^k).

Detailed explanation-3: -The maximum number of comparisons is logarithmic with respect to the number of items in the list. Therefore, the binary search is O(log n) .

Detailed explanation-4: -Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array.

There is 1 question to complete.