Bubble Sort
Understand the bubble sort algorithm by exploring its step-by-step process of comparing and swapping adjacent elements to sort an array. Learn how each iteration places the largest unsorted element at its correct position and how this method fits into foundational sorting techniques used in competitive programming.
We'll cover the following...
We'll cover the following...
Bubble sort
For each element starting from the first, compare with the adjacent element and swap the two if they are in incorrect order, i.e., arr[i] > arr[i+1]. The first iteration places the largest element at arr[N-1]. The second iteration places the second largest at arr[N-2] and so on…
- Initially:[6 3 5 4 1 2]
- Iteration 1: [6 3 5 4 1 2] -> [3