Bubble Sort is the most simple form of sorting algorithm based on comparisons. It works by repeatedly stepping through the list of items such as an array and swapping the two adjacent elements if they are in a different order.

This algorithm has no such real-life uses due to its poor performance and is used primarily as an educational tool to teach students about sorting concepts.

Take a look at this video explaining Bubble Sort Algorithm in two minutes.

Bubble Sort Algorithm Performance

Bubble sort algorithm is the worst performing algorithm and most of the other sorting algorithms have a better worst-case or average complexity, often O(n log n).

Worst Case and Average Case Complexity: O(n2)
Best Case Time Complexity: O(n)

Bubble Sort Comparison
Bubble Sort Comparison with other sorting algorithms
Bubble Sort - Pseudocode
Bubble Sort – Pseudocode

Bubble Sort Program

The following C program reads an integer array and prints it on the screen. It then sorts the array using bubble sort and print it again.

Output of the Bubble Sort Program

See also: Shell Sort, Quick SortInsertion Sort, Selection Sort