Question: I have this c++ quicksort program to sort 100000 integers ranging from 1 to a billion, with a seed of 100. I a tasked with

I have this c++ quicksort program to sort 100000 integers ranging from 1 to a billion, with a seed of 100. I a tasked with this For each iteration, make note of the execution time and number of comparisons for quicksort. I know how to obtain the execution time, but I dont understand how to get the number of comparisons for quicksort, without using the c++ standard library. Example output : quicksort: 11.679 msecs comps: 130288 for 100000 integers. Below is my code.

#include #include #include #include

using namespace std;

const long int size = 100000; const long int MIN= 1; const long int MAX= 1000000000;

void quicksort(long int *list,long int left,long int right){ long int i = left; long int j = right; long int pivot = list[(i + j) / 2]; long int temp; while (i <= j){ while (list[i] < pivot) i++; while (list[j] > pivot) j--; if (i <= j){ temp = list[i]; list[i] = list[j]; list[j] = temp; i++; j--; } } if (j > left) quicksort(list, left, j); if (i < right) quicksort(list, i, right); }

int main(){ double t1, t2; long int arr[size];

srand(( int)time(0)); // initialize the random number generator for (long int i=0; i

t1 = clock(); quicksort(arr,0,size); t2 = clock(); cout << "quick Sort: " << (t2 - t1)/ CLOCKS_PER_SEC * 1000<< " msec "; return 0; }

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!