COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
A binary search is to be performed on the list:1 5 10 13 48 68 100 101How many comparisons would it take to find number 101?
|
0-1
|
|
1-2
|
|
3-4
|
|
4-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: -A binary search of 10, 000 items requires at most 14 comparisons. Thus, in terms of the number of comparisons, binary search is much more efficient than sequential search. However, in order to use the binary search approach, the items must be presorted.
Detailed explanation-3: -2 Efficiency of the Binary Search. In the worst-case scenario, searching a sorted array of 1023 elements takes only 10 comparisons when using a binary search.
There is 1 question to complete.