Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this c++ mergesort function , to sort 100000 random integers. I need to find the time to run and number of comparisons. I

I have this c++ mergesort function , to sort 100000 random integers. I need to find the time to run and number of comparisons. I got the time but I do not know where would be the best place to set a counter of comparison on mergesort, where would this be placed? Below is a sample output and my code so far.

mergesort: 16.998 ms comps: 1536383

#include #include #include #include #include

using namespace std; const long int size = 100000; const long int MIN= 1; const long int MAX= 1000000000;

void merge(long int *arr,long int size,long int first,long int middle,long int last){

long int temp[size]; for(int i = first; i<=last; i++) { temp[i] = arr[i]; } int i=first, j=middle+1, k= first; while(i<=middle && j<=last) { if(temp[i] <= temp[j]) { arr[k] = temp[i]; i++; } else { arr[k]=temp[j]; j++; } k++; } while(i<=middle) { arr[k]=temp[i]; k++; i++; } }

void mergesort(long int *arr, long int size,long int first,long int last){ if(first

int main(){ double t1, t2; long int arr[size]; srand(( int)time(0)); // initialize the random number generator for (long int i=0; i

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago