Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ My code doesn't output what is required because my binary search numbers are too small. We are suppose to make the code be searched

C++

My code doesn't output what is required because my binary search numbers are too small. We are suppose to make the code be searched binarily 1000 times. Can anyone help me fix my errors?(exclude linear search. Only need binary search)

Note: The code is for a random number to be binary searched through so the required code is an example as long as it outputs something similar.

My Code:
student submitted image, transcription available below

student submitted image, transcription available below

student submitted image, transcription available below

My output:

student submitted image, transcription available below

student submitted image, transcription available below

Required output:

student submitted image, transcription available below

student submitted image, transcription available below 

#include #include #include #include using namespace std; int binarySearch (int [], const int,const int ); int getRandomNumber (const int); void printArray(int [], const int); int main() { srand(time(NULL)); const int numSearches = 1000; const int arraySize L 400; int values[arraySize]; for (int i = 0; i < arraySize; i++) { values [1] =getRandomNumber (arraySize * 2); } I std::sort(values, values + arraySize); for (int i=0; i < numSearches; i++) { int target getRandomNumber (arraySize 2); int result = binarySearch (values, arraySize, target); if (result == -1) { cout < < "Target: < < target < < "not found in array using BINARY SEARCH." < < endl; } else { cout < < "Target: " < < target < < "found at index: al" < < result < < "1" < < endl;

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

How would you handle the difficulty level of the texts?

Answered: 1 week ago

Question

Describe MRP processing.

Answered: 1 week ago