Question: Project 1: Search Benchmarks Write a program that creates an array (or vector) of 1000 double values stored in ascending order. It should call a

Project 1: Search Benchmarks

Write a program that creates an array (or vector) of 1000 double values stored in ascending order. It should call a function which uses a linear search algorithm to locate one of the values in the array and returns a count of the number of comparisons it makes until it finds the specified value. The program should then call another function that uses a binary search algorithm to locate the same value in the array and return a count of the number of comparisons it makes. The program should then display the two counts on the screen.

As test cases, print the number of comparisons required by each function to locate the number in the array at index 271, at 499 (the midpoint), at 624, and at 999. Also determine a number that isn't included in the array, such as one plus the number in the last element of the array.

Hint: The number of comparisons for the linear search at the midpoint should be about 500 and the number of comparisons for the binary search should be 2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!