Bubble sort

Bubble sort :

Bubble sort is the simpler and well known sorting technique. It is less efficient for large amount of data as its average and worst case complexity is high. Bubble sort is stable and adaptive.In this sorting technique, we need to compare and swap the adjacent elements of the array till we get whole array sorted.i

Worst case:O(n2)

Average case :O(n2)

Best case:O(n)

e.g. To sort  8,5,2,1

ALGORITHM:

    • Input the array, a[]
    • while (i<=n-1)
      while(j<(n-j-1)
      Compare a[j] with a[j+1] and swap as per requirement
      Increment j
      [END OF INNER LOOP]
      Increment i
      [END OF OUTER LOOP]

C SOURCE CODE:

Leave a Reply

Your email address will not be published. Required fields are marked *