3. Implement merge sort algorithm to sort the given ‘n’ unordered elements .
Determine the time
to sort the elements for different values of ‘n’ and plot a graph of the time taken versus ‘n’.
#include <stdio.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
int C[20];
void Merge(int a[ ], int low, int mid, int high)
int i, j, k; i=low; j=mid+1; k=low;
while ( i<=mid && j<=high )
if( a[i] <= a[j] )
C[k++] = a[i++] ;
else
C[k++] = a[j++] ;
while (i<=mid)
C[k++] = a[i++] ;
while (j<=high)
C[k++] = a[j++] ;
for(k=low; k<=high; k++)
a[k] = C[k];
void MergeSort(int a[], int low, int high)
{
int mid;
if(low >= high)
return;
mid = (low+high)/2 ;
MergeSort(a, low, mid);
MergeSort(a, mid+1, high);
Merge(a, low, mid, high);
int main( )
int n, a[100],k;
clock_t st,et;
double ts;
printf("\n Enter the number of elements to be sorted:");
scanf("%d", &n);
printf("\nThe Numbers are:\n");
for(k=1; k<=n; k++)
scanf("%d",&a[k]);
LARGE_INTEGER frequency,startTime,endTime;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&startTime);
MergeSort(a, 1, n);
QueryPerformanceCounter(&endTime);
printf("\n\n\n Sorted Numbers are : \n ");
for(k=1; k<=n; k++)
{printf("%d\t", a[k]);
printf("\nThe time taken is %e",ts);
double executionTime=(double)([Link])/[Link];
printf("\n Execution time:%.9f seconds\n",executionTime);
return 0;