Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Language/Type: C++ binary search searching Related Links: Wikipedia: binary search Suppose we are performing a binary search on a sorted vector initialized as follows:

C++

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Language/Type: C++ binary search searching Related Links: Wikipedia: binary search Suppose we are performing a binary search on a sorted vector initialized as follows: Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code) and write the value that would be returned from the search. Main Page Exercises C++ Solve an Exercise binarySearch 20 Language/Type: C++ binary search searching Related Links: Wikipedia: binary search Suppose we are performing a binary search on a sorted vector initialized as follows: Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code) and write the value that would be returned from the search. Language/Type: C++ binary search searching Related Links: Wikipedia: binary search Suppose we are performing a binary search on a sorted vector initialized as follows: Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code) and write the value that would be returned from the search. Now suppose we are performing both an iterative (loop-based) sequential search and then a recursive binary search on the same list. The sequential search is a standard version that does not take any advantage of the sortedness of the list, simply looking each element in order from the start to the end of the list. Suppose we are searching the list for the value 25 . Also suppose that we are operating on a special computer where reading an element's value in the list (such as examining the value of numbers []) costs 7 units of time; calling any function costs 10 units of time; and all other operations are essentially 0 cost. (Keep in mind that even in a non-recursive search, the cost of making the one and only call to binarysearch still counts in your total.) What is the total "cost" of running a sequential search and recursive binary search over this list of data, searching for the value 25 ? Language/Type: C++ recursion return Related Links: vector Write a recursive function named binarySearch that accepts a reference to a sorted vector of integers and an integer target value and uses a recursive binary search algorithm to find and return an index at which that target value is found in the vector. If the target value is not found in the vector, return -1. The following code shows some example calls and their expected return values: Function: Write a C++ function as described, not a complete program. You should assume that the vector's elements are already sorted; you do not need to handle the case of an unsorted vector. Your function must be recursive and must use a binary search algorithm. Do not use loops or auxiliary data structures

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

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions