Analysis of Improved Bubble 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
  
  Bubblesort( Input: Array A, Size N)
  N: Number of values to be sort
  A: Array of Size N
  Temp, Pass,J : extra variable
  
  1.	Pass=1,flag=1
  2.	while(pass<=n && flag) do:
  3.	      J :=1;
  4.           flag=0;
  5.         while(jLt=n-pass)  do:
  6.    	    if(a[j]>a[j+1])
  7.	    	     temp :=a[j];
  8.		         a[j]     :=a[j+1];
  9.		         a[j+1]  :=temp;
  10.                flag=1; 
  11.            endif    
  12.            j := j+1
  13.        end while
  14.       pass := pass+1
  15.    end while
  
Program
  
  #include <stdio.h>
  #include <conio.h>
  #include <process.h>
  #include <alloc.h>
  int count=0;
  void main()
  {
      void getdata(int[10],int);
      void putdata(int[10],int);
      void bubble_sort(int a[],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);
      bubble_sort(a,n);
      printf("\nafter sorting\n");
      putdata(a,n);
      printf("\n for n = %d value of count is  %d",n,count);
      getch();
  }
  void getdata(int x[10],int n)
  {
      int k;
      printf("enter the value  for sorting\n");
      for(k=0; k < n; k++)
      {
          scanf( "%d",&x[k] );
      }
  }
  void putdata(int x[10], int n)
  {
      int k;
      for(k=0; k < n; k++)
      {
          printf("%d\t",x[k]);
      }
      printf("\n");
  }
  void bubble_sort(int a[],int n)
  {
      int pass,j,temp;
      count++;                                                  
       int flag=1;
      for(pass=1; pass <= n-1 && flag; pass++)
      {
          count++;
          count++;
		  flag=0;
          for(j=0;j < n-pass; j++)
          {
              count++;
              count++;
              if(a[j]>a[j+1])
              {
                  count++;
                  temp=a[j];
                  count++;
                  a[j]=a[j+1];
                  count++;
                  a[j+1]=temp;
				  flag=1;
              }
              count++;
          }
          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