**Bubble sorting in Array in C Programming** is one of the slowest, if not the slowest, sorts. It is for this reason that its use is very rare and this algorithm remains much criticized. But why is it so slow? We evaluate the speed of a sorting algorithm by observing its number of comparisons / exchanges and thus establish a scale that we call complexity. Bubble sorting makes a lot of comparisons / exchanges for few values to sort. It is mathematically estimated that it averages n (n-1)/ 4 operations for n values to sort.

In the worst case, the complexity of bubble sorting in Array in C Programming is also in O (n²). The worst case is, of this sort, a list sorted in the opposite direction. The best case is a sorted list. If the algorithm is confronted with this case, its complexity improves in O (n), which means that it makes only n comparisons form values to be sorted (in reality, for reasons of intervals, it is n ‘in fact only n-1).

**Bubble sorting in Array** in C Programming is one of the worst sorts because of its high complexity which results in too long execution time. And yet, this method of sorting continues to be used and this, surely, for its originality. But you still need to know that it is relatively sufficient for small lists on a computer, I say relatively. From twenty elements, it is already better to use another more suitable sorting. You have to choose your algorithm according to your needs.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<stdio.h> #include<conio.h> void main() { int a[100],i,j,n,t; clrscr(); printf("enter how many value in array\n"); scanf("%d",&n); printf("Enter %d value \n",n); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("Original List :\n"); for(i=0;i<n;i++) printf("%5d",a[i]); /* bubble sort logic */ for(i=1;i<n;i++) for(j=0;j<n-i;j++) if(a[j]>=a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } printf("\n\nSorted list :\n"); for(i=0;i<n;i++) printf("%5d",a[i]); getch(); } |