Python Searching and Sorting|Bubble Sort

Bubble sort

The basic idea in bubble sort is to compare two successor elements and interchange them if they are not in proper order. After each pass, the largest unsorted element is placed at its correct position.

If there are “n” elements then

After the first pass the largest element is placed at (n-1) th position. After the second pass the 2nd largest element is placed at n-2 th position and so on.

All the elements will be sorted after a maximum of n-1 passes.


It is easy to learn.
Few lines of code
It works very well on already sorted lists or list with just a few permutations.


It is not effective for large numbers of sorting elements.
Complexity is O(n2) (order of n square)