(Execution time) Write a program that randomly generates an array of 100000 integers and a key. Estimate the execution time of invoking the linearSearch function in Listing. Sort the array and estimate the execution time of invoking the binarySearch function in Listing. You may use the following code template to obtain the execution time:
long startTime = time(0);
perform the task;
long endTime = time(0);
long executionTime = endTime - startTime;
Listing BinarySearch.cpp
1
int binarySearch(const int list[], int key, int listSize)2 {3 int low = 0 ;4 int high = listSize − 1 ;55 while (high >= low)6 {7 int mid = (low + high) / 2 ;8 if (key− l ;10 else if (key == list[mid])11 return mid;12 else 13 low = mid + 1 ;14 }1615 return -low − 1 ;16 }
Listing LinearSearch.cpp
int linearSearch(const int list[], int key, int arraySize){for (int i = 0 ; iif (key == list[i]) return i; }return −l ; }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.