Analysis of Merge Sort

Best Case

Enter 5 numbers

Sorted Array:

No. of instructions count:

Enter 10 numbers

Sorted Array:

No. of instructions count:

Enter 15 numbers

Sorted Array:

No. of instructions count:

Enter 20 numbers

Sorted Array:

No. of instructions count:

Enter 25 numbers

Sorted Array:

No. of instructions count:

Average Case

Enter 5 numbers

Sorted Array:

No. of instructions count:

Enter 10 numbers

Sorted Array:

No. of instructions count:

Enter 15 numbers

Sorted Array:

No. of instructions count:

Enter 20 numbers

Sorted Array:

No. of instructions count:

Enter 25 numbers

Sorted Array:

No. of instructions count:

Worst Case

Enter 5 numbers

Sorted Array:

No. of instructions count:

Enter 10 numbers

Sorted Array:

No. of instructions count:

Enter 15 numbers

Sorted Array:

No. of instructions count:

Enter 20 numbers

Sorted Array:

No. of instructions count:

Enter 25 numbers

Sorted Array:

No. of instructions count:

Algorithm
  
int merge_sort(int arr[],int p,int r)
arr:Input Array arr;
p:starting index
r:Last index
q,count:external variable
1.  int q;
2.  if(p<r)
3.	  count++;
4.    q=(p+r)/2;
5.    merge_sort(arr,p,q);
6.    merge_sort(arr,q+1,r);
7.    merge(arr,p,q,r);
8.  end if

9.  return 0;
10. end merge_sort

int merge(int arr[],int l,int m,int h)
arr:Input array arr
l,m:Index
arr1,arr2:external array
n1,n2,i,j,k,count: External variable

  int arr1[10],arr2[10];
  int n1,n2,i,j,k;
  n1=m-l+1;
  count++;
  n2=h-m;
  count++;
  for(i=0;i<n1;i++)
  {
	  count++;
    arr1[i]=arr[l+i];
	count++;
  }
  for(j=0;j<n2;j++)
  {
	  count++;
    arr2[j]=arr[m+j+1];
	count++;
  }
  arr1[i]=9999;  
  arr2[j]=9999;
count++;
  i=0;
  j=0;
  for(k=l;k<=h;k++)  
  {
    if(arr1[i]<=arr2[j])
	{
		count++;
      arr[k]=arr1[i++];
	  count++;
	}
    else
	{
		count++;
      arr[k]=arr2[j++];
	  count++;
	}
  }
  
  return 0;
}

  
Program
  
 
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <alloc.h>
int arr[20];
int count=0;
void main()
{	int merge_sort(int[10],int,int);
int merge(int[],int,int,int);
  int n,i;
  printf("Enter the size of array\n");
  scanf("%d",&n);
  printf("Enter the elements:");
  for(i=0;i<n;i++)
  {
    scanf("%d",&arr[i]);
  }
  merge_sort(arr,0,n-1);

  printf("Sorted array:");
  for(i=0;i<n;i++)
  {
    printf("%d",arr[i]);
  }
  printf("count=%d",count);
  getch();
}

int merge_sort(int arr[],int p,int r)
{
  int q;
  if(p<r)
  {
	  count++;
    q=(p+r)/2;
    merge_sort(arr,p,q);
    merge_sort(arr,q+1,r);
    merge(arr,p,q,r);
  }

  return 0;
}

int merge(int arr[],int l,int m,int h)
{
  int arr1[10],arr2[10];
  int n1,n2,i,j,k;
  n1=m-l+1;
  count++;
  n2=h-m;
  count++;
  for(i=0;i<n1;i++)
  {
	  count++;
    arr1[i]=arr[l+i];
	count++;
  }
  for(j=0;j<n2;j++)
  {
	  count++;
    arr2[j]=arr[m+j+1];
	count++;
  }
  arr1[i]=9999;  
  arr2[j]=9999;
count++;
  i=0;
  j=0;
  for(k=l;k<=h;k++)  
  {
    if(arr1[i]<=arr2[j])
	{
		count++;
      arr[k]=arr1[i++];
	  count++;
	}
    else
	{
		count++;
      arr[k]=arr2[j++];
	  count++;
	}
  }
  
  return 0;
}

          
  
Best Case
Average Case
Worst Case
5 Numbers
10 Numbers
15 Numbers
20 Numbers
25 Numbers

select appropriate function for growth of graph

Best case
Average case
Worst case