COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
3
|
|
2
|
|
10
|
|
5
|
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 .