Bubble sorting is the one of the simple sorting algorithm .Bubble sort got its name ,all the least element go to top of the list so it is called as bubble sort

Bubble sort works by checking the fist element with second element if the element is greater ,then swap the value else remains unaffected .This process is repeated till the last element

**Graphical Representation **

```
#include<stdio.h>
int bubble(int A[],int n);
int bubble(int A[],int n)
{
int pass,i;
for( pass=0;pass<n;pass++)
{
for( i=0;i<n;i++)
{
if(A[i]>A[i+1])
{
int t=A[i];
A[i]=A[i+1];
A[i+1]=t;
}
}
printf("\n pass %d \n ",pass);
for(i=0;i<6;i++)
{
printf("%d\n",A[i]);
}
}
printf("\n the answer is \n");
for(i=0;i<6;i++)
{
printf("%d\n",A[i]);
}
return 0;
}
int main()
{
int m=6;
int a[6]={15,2,78,4,1,68};
bubble(a,m);
return 0;
}
```

**Advantages :**

Very simple

Can be used to check whether the given array is sorted or not easily

**Disadvantages:**

more time complexity

not very efficient one

**Time Complexity :**

Best case O(n^2) (modified version has O(n)

Worst case and Average case O(n^2)

### Like this:

Like Loading...

*Related*