Explain Binary Search Algorithm to search for V = 75, using the data given below
5, 10, 25, 35, 45, 50, 60, 70, 75, 80, 85
How many searches will be needed?
Searching for 75 in list [5, 10, 25, 35, 45, 50, 60, 70,
75, 80, 85]
left = 0, right = 10, mid = 5, arr[mid] = 50
> Middle element in this list is 50
> Compare Target (75) with middle element (50) of
this list
> Target value (75) is larger than this middle
element 50
> so, we have to search in right part of the
list([60, 70, 75, 80, 85])
Searching for 75 in list [60, 70, 75, 80, 85]
left = 6, right = 10, mid = 8, arr[mid] = 75
> Middle element in this list is 75
> Compare Target (75) with middle element (75) of
this list
> They are the same. Target element (75) is found.
so, binary search ends here.
It took a total of 2 comparisons using binary
search
Get Answers For Free
Most questions answered within 1 hours.