Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In class, we briefly mentioned how to perform a binary search on an array. Note that this approach is more efficient than any of the
In class, we briefly mentioned how to perform a binary search on an array. Note that this approach is more efficient than any of the other searching approaches we discussed. As a reminder, the algorithm for the iterative version of binary search, where we are given an array array of size n and a target, is given below:
*******THIS SHOULD BE DONE IN C CODE, NOT C++*******
Function BINARY-SEARCH(array, n, target) 1: Let bottom 0 2: Let top = n-1. 3: Let found = false. 4: Let index be the index of array. 5: while (bottom target) then Let top be middle -1. else 12 13: Let bottom be middle + 1. end if 15 end if 16: end while You are asked to turn this into a recursive program. Write a function called binary_search that implements the recursive algorithm for an array of integers. Hint: In class, most of our examples had 1 to 2 parameters, and one of the arguments slightly changed each time we called the function. For this program, you will need more than two parameters, and more than one argument will change each time we call the function As for the array itself, assume the array has 10 items, and the program asks the user to enter the 10 integers Also, I highly suggest you spend some time thinking about how to implement the recursive algorithm before you start coding
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started