Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

Students also viewed these Databases questions