Algorithms

Bubble Sort

Shop Books Developers Feedback
Home

Bubble Sort

Introduction To Bubble Sort

Bubble Sort is an extremely basic and inefficient method for sorting . Bubble Sort uses the method of Comparison for sorting.

In the worst case, total comparisons can go upto n2 i.e. O(n2) where n is the size of input.

Examples With Visualisation

Comparisons


example dataset [3,2,5,4,6,1]


Algorithm

for i->0 to size-1
  for j->0 to size-1
     if a[j]>a[j+1]
      swap(a[j],a[j+1])
     else
      Continue

Bubble Sort




References

mitocw

MIT OpenCourseWare By Prof.Charles E. Leirson