Advertisements
Advertisements
प्रश्न
Determine the number of comparisons required in list [-4, 0, 2,7, 8, 17, 19] to search for - 4.
पर्याय
1
2
3
4
MCQ
उत्तर
1
Explanation:
Give list = [-4, 0, 2,7, 8, 17, 19]
Iteration 1: First = 0, last = 6
Midpoint= (0+6)//2 = 6112 = 3, value at index 3 is 7.
-4 < 7, so we will consider first half of the list
Iteration 2: First = 0, last = 2
Midpoint= (0+2)//2 = 1, value at index 1 is 0
-4 < 0, so we will consider left half
Iteration 3: First = 0, last = 0
Midpoint = 0//2 = 0
Number at index 0 is -4
shaalaa.com
Binary Search
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?