Computer Science, asked by akshat005113, 2 months ago

WAP search an element in a list and display the frequency of element present in list and their location using binary search by using user defined function. in python

Answers

Answered by sharmavinay84479
1

Answer:

In a nutshell, this search algorithm takes advantage of a collection of elements that is already sorted by ignoring half of the elements after just one comparison.

Compare x with the middle element.

If x matches with the middle element, we return the mid index.

Else if x is greater than the mid element, then x can only lie in the right (greater) half subarray after the mid element. Then we apply the algorithm again for the right half.

Else if x is smaller, the target x must lie in the left (lower) half. So we apply the algorithm for the left half.

Similar questions