Write a c/c++ or Matlab or Java program to compute insertion sort and merge sort (you may use the code from textbooks by Deitel and Deitel or from the web). Obtain the run time of both routines. The input data should be an int array containing random element values (between say 0 to 1023.) Obtain run time, T, with 1-D (input) array size of n=16, 256, 4096, 65536, 1048576 (which equal to 2p where p = 4, 8, 12, 16, 20). The run time for each n should be averaged with about floor(512/(p*p)) runs, each run (for a given n) should use a different random input. Plot (with excel or matlab or other available tools) the run time for both routines on one plot, with the x axis in p values and y axis in log(T). Label on your plot which curve is for insertion sort and which is for merge sort. Submit c/c++ programs and plot, with instruction in [login to view URL] file on how to build and run your program (include the Dev-C++ or MS studio or Java Netbean project file.) A suggestion for measuring run time is as follows (not all essential codes are shown):
#include <time.h>
double etime;
float rate;
time_t t_start, t_end;
int nloops,i;
printf("Start Algorithm, nloops=%d ......\n",nloops);
srand(p); // p as in num = 2^p
time(&t_start);
for (i=0; i<nloops; i++)
{
// num is the size of the input array
for (kdx=0; kdx<num; kdx++)
{
sortArr[kdx] =rand() % 1024;
}
//call your sort Algorithm here, each time with a different input
}
time(&t_end);
etime = difftime(t_end, t_start);
rate = (float)nloops/etime;
printf("\n Processed %f Algorithm per sec, i.e. each Algorithm takes %f usec \n",
rate, etime*1000000/(float)nloops);
printf("AlgorithmTsCPUTime_c: end CPU time evaluation +++++++++++++++++++++++++\n");
Hi , i am c/c++ expert , both sorting algorithms and calculate their runtimes is very much easy.. i ll create graph of different values if you give your project to me
thank you
I have developed such a program before. I do not need to think of the algorithm for it again, I will just need to modify it to suit your exact requirements.