MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Given this array:1, 2, 4, 5, 6, 7, 8, 12, 14, 21, 22, 42, 53How many comparisons are required to find 42 using the Binary Search?
A
3
B
2
C
10
D
5
Explanation: 

Detailed explanation-1: -The number of comparisons necessary to get to this point is i where n/2i =1. Solving for i gives us i =log n . 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: -What must be true before performing a binary search? The elements must be sorted. It can only contain binary values.

Detailed explanation-4: -Since 64=2log2(64)=26 64 = 2 log 2 ⁡ ( 64 ) = 2 6, the number of comparisons required for an array of length 64 is 1+log2(64)=1+6=7 1 + log 2 ⁡ ( 64 ) = 1 + 6 = 7 .

There is 1 question to complete.