Bubble Sort Algorithm
SORTING
Sorting is the process of arranging given numbers or elements in ascending or descending order.
Other sorting techniques
- Insertion sort
- Quick sort
- Heap sort
- Bucket sort
- Shell sort
- Radix sort etc.
BUBBLE SORT
Bubble sort is the simple sorting algorithm. It is easy to understand and implement. Bubble sort is called so because elements tend to move up into the correct order like bubbles rising to the surface.
Let N = number of elements in a list. Assume counting starts from 0 (zero), as computer recognises zero as a number.
NOTE: observe that there are no more elements to compare in pass 1. After pass 1, the largest element comes to an end of the list or array. So, last element doesn’t have to be compared in next pass. So pass 2 contains only 3 comparisons as shown below: