Showing posts with label bubble sort. Show all posts
Showing posts with label bubble sort. Show all posts

Wednesday, 19 June 2013

Bubble Sort

It is the simplest type of sorting technique. In this sorting technique, first two elements are compared and if first element is greater than second, they are swapped. This process is repeated for each pair of adjacent elements to the end of the data set. It again starts with first two elements and repeat the process until no swap occurs.
This sorting technique can only be used for sorting small lists. This technique can also be used for the large lists if only few elements require sorting.

Important: Average and worst case performance of this sorting technique is O (n2).


Example: Consider the following unordered list 


5              10           3              1              9              0

First Pass

 5 <10 so there is no need of swapping.