Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago