Algorithm
Bubble Sort Algorithm:
- Start with an unsorted array.
- Repeat the following steps until no swaps are needed:
- Traverse the array from the first element to the second-to-last element.
- Compare each pair of adjacent elements.
- If the first element is greater than the second, swap them.
- If no swaps occur during a pass, the array is already sorted and the algorithm terminates.
- Otherwise, repeat the process for the remaining unsorted portion of the array.
Example:

Fig. 1: Step-by-Step Process for One Iteration

Fig. 2: Iteration by Iteration Visualization of Bubble sort
Note: Bubble Sort ensures that the largest unsorted element "bubbles" to its correct position after each pass.