Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1: Implement the binary search function from your textbook on p. 67 and add an additional referen ce parameter 'int&steps' which is counting up

image text in transcribed
image text in transcribed
Exercise 1: Implement the binary search function from your textbook on p. 67 and add an additional referen ce parameter 'int&steps' which is counting up the costs associated with the iterations needed to find the target value. When the target is found in the vector binary_search returns the index at which the target is stored; otherwise, the function returns value -1. Notice that we are using our own Vector data structure. So make sure to include "Vector.h" int binary_search (int x, const Vectorcint>& vec, int& steps) int low0 int high vec. size() - 1; steps0 while (low x) else return -1, // not found Test your function in an 'int main()' which builds up a vector of 25 arbitrary integer values in ascending order. For binary search to work, your vector must be sorted. The manner in which the binary_search function is written calls for the vector values to be in ascending order. Run binary_search for 5-10 target values, some included in the vector, some not included. Let the main() function report 1. 2. whether the value was found and at what "cost" (you get this information from the int& parameter)

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_2

Step: 3

blur-text-image_3

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions