Analysis of Quick 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
  
procedure quickSort(left, right)

   1. if right-left less then  0
   2.   return
   3.  else     
   4.  pivot = A[right]
   5.  partition = partitionFunc(left, right, pivot)
   6.  quickSort(left,partition-1)
   7.  quickSort(partition+1,right)    
   8. end if		
   
end procedure 

function partitionFunc(left, right, pivot)
  1. leftPointer = left
  2. rightPointer = right - 1

  3. while True do
  4.  while A[++leftPointer] //pivot do
  5.       //do-nothing            
  6.   end while
		
  7.   while (rightPointer > 0 && A[--rightPointer] > pivot) do
  8.     //do-nothing         
  9.  end while
		
  10.    if (leftPointer >= rightPointer)
  11.       break
  12.    else                
  13.       swap (leftPointer,rightPointer)
  14.  end if
		
  15. end while 
	
  16. swap (leftPointer,right)
  17. return (leftPointer)
	
end function
  
Program
  
#include <stdio.h>
int count=0;
void main()
{
	void getdata(int[10],int);
	void putdata(int[10],int);
	void quick_sort(int a[],int,int);
	//void partition(int a[],int,int);
	int i,a[100],n;
	clrscr();
	printf("enter the value of n\n");
	scanf("%d",&n);
	getdata(a,n);
	printf("\nbefore soring\n");
	putdata(a,n);
	quick_sort( a,0,n-1);
	printf("\nafter sorting\n");
	putdata(a,n);
	printf("\n for n = %d value of count is  %d",n,count);
	getch();
}
void getdata(int a[10],int n)
{
     int k;
     printf("enter the value  for sorting\n");
     for(k=1;k<=n;k++)
     {
      scanf("%d",&a[k]);
     }
}
void putdata(int a[10], int n)
{
	int k;
	for(k=1;k<=n;k++)
	{
	      printf("%d\t",a[k]);
	 }
	 printf("\n");
}
void partition(int a[],int p,int r)
{
	int x,i,j,temp;
	x=a[r];
	i=p-1;;
	count++;
	for(j=p;j<=r-1;j++)
	{
		count++;
		if(a[j]=x)
		{
		count++;
			i=i+1;
		count++;
			temp=a[j];
		count++;
			a[j]=a[i];
		count++;
			a[i]=temp;
		count++;
		}
		count++;
	}
	count++;
	temp =a[r];
	count++;
	a[r]=a[i+1];                       //partioning
	count++;
	a[i+1]=temp;
	count++;
}

void quick_sort(int a[],int p,int r)
{	int q;
	count++;
	if(p<r)
	{
		count++;
		q=partition(a,p,r);
		count++;
		quick_sort(a,p,q-1);
		count++;
		quick_sort(a,q+1,r);
		count++;
	}
}   
          
  
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