Question: 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:
#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

My output:

L 400; int values[arraySize]; for (int i = 0; i < arraySize;

i++) { values [1] =getRandomNumber (arraySize * 2); } I std::sort(values, values

Required output:

+ arraySize); for (int i=0; i < numSearches; i++) { int target

getRandomNumber (arraySize 2); int result = binarySearch (values, arraySize, target); if (result 

#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

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 Programming Questions!