Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what would be the missing code to run this program? please follow the zybook format 15.14 LAB: Binary search Binary search can be implemented as
what would be the missing code to run this program? please follow the zybook format
15.14 LAB: Binary search Binary search can be implemented as a recursive algorithm. Each call makes a recursive call on one half of the list the call received as an argument. Complete the recursive function BinarySearch( with the following specifications. 1. Parameters: o a target integer o a vector of integers o lower and upper bounds within which the recursive call will search 2. Return value: o the index within the vector where the target is located o -1 if target is not found The template provides the main program and a helper function that reads a vector from input. The algorithm begins by choosing an index midway between the lower and upper bounds. 1. If target == integers. at (index ) return index 2. If lower == upper, return -1 to indicate not found 3. Otherwise call the function recursively on half the vector parameter: o If integers . at ( index) target, search the vector from lower to index - 1 The vector must be ordered, but duplicates are allowed. Once the search algorithm works correctly, add the following to BinarySearch(): 4. Count the number of calls to BinarySearch().. 5. Count the number of times when the target is compared to an element of the vector. Note: lower == upper should not be counted. Hint: Use a global variable to count calls and comparisons. The input of the program consists of: 1. the number of integers in the vector 2. the integers in the vector 3. the target to be located CS ExI tha ingit is CamScanner 9 4 56 789Ex: If the input is: 9 1 2 3 4 5 6 7 8 9 the output is: index: 1, recursions: 2, comparisons : 3 464730.321487 4.qx3zay> Instructor note: Line 54 here uses notation from C, as opposed to C++ - printf is the C equivalent of using the cout function in C++. The "translated" line would look like: cout 2 #includeStep 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