MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the largest number of comparisons needed to perform a binary search on an array with 42 elements?
A
2
B
5
C
6
D
41
E
42
Explanation: 

Detailed explanation-1: -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-2: -Here, we have to apply the binary search on 32 elements. So, it will take log232 = 5 comparisons to search for the element.

Detailed explanation-3: -we can note that 512 = 2^9. This means if we divide 512 in half 9 times we have 1 element left. Therefore we need 9 comparisons to perform our search on a 512 element phone book.

There is 1 question to complete.