Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this program is to search for a number using the linear and binary search algorithms and report back how many comparisons were

The purpose of this program is to search for a number using the linear and binary search algorithms and report back how many comparisons were done to find a number using both techniques in a sorted array.

Using the Searching and Sorting Source Code that I provided last week (posted on Moodle), modify the MAIN source code to prompt the user to enter a number in the range of 1 to 100 to search for. Then, the program should search an array of sorted numbers for the number using both the linearSearch and binarySearch functions.

For searching, the program should generate a sorted array of integers from 1 to 100 with 100 elements. You can create a new function called initArray2 (the one I provided in the source code is called initArray and can be used to help write initArray2) to initialize the parameter array as follows:

array [0] = 1

array [1] = 2

etc.

until array [99] = 100

Once the number is found in both the linearSearch and binarySearch functions, the functions should print out how many comparisons were done to find the number before returning to the calling function (main).

Input Validation: Do not accept a number to search for that is less than 1 or greater than 100.

In C++

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

Students also viewed these Databases questions

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago