Question: Binary search is a divide-and-conquer approach to search a sorted array for a particular value. Your program must implement binary search and return the index

 Binary search is a divide-and-conquer approach to search a sorted array

Binary search is a divide-and-conquer approach to search a sorted array for a particular value. Your program must implement binary search and return the index of the array if the number is found, or 0 if the number is not found. Your implementation must use recursion and you cannot use any inbuilt searching or find functions Command Window The binary search algorithm searches for a number in a pre-sorted array by determining the midpoint of the array and if that element is not the required number, then it proceeds to check the smaller array on the left or right of the midpoint -depending on whether the number is smaller or larger. Your binary search function will have exactly two inputs-the array to be searched and the number to search for (see example, right) >> input = [ 1, 3, 4, 5, 7, 9, 10, 12, 15); >bin search (input, 1) > bin search (input, 2) ans 0 bin search (input, 3) > bin search (input, 10) 9 10 12 15 > bin search (input, 11) ans left array midpoint right array 0 Once you have written your function, create an array of size 100, with random numbers between 1 and 100 Sort the array using the inbuilt MATLAB sort function and then call your binary search function on a random number between 1 and 100. Repeat this process at least 1000 times and report on how many values were found as well as how many tmes it was found in the first midpoint

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!