Bubble Sort

Bubble Sort is a simple sorting algorithm that repeatedly steps through the input list element by element, comparing the current element with the one after it, swapping their values if needed. These passes through the list are repeated until no swaps had to be performed during a pass, meaning that the list has become fully sorted.

### How it works: 1. Compare adjacent elements. If the first is greater than the second, swap them. 2. Move to the next pair of elements and do the same. 3. Continue this process for each pair of adjacent elements to the end of the data set. The largest element will "bubble" up to the end. 4. Repeat the process for all remaining elements until the entire array is sorted.

Constraints

  • 1 <= array.length <= 10^4
  • -10^9 <= array[i] <= 10^9
TimeO(N^2)
SpaceO(1)
Ready to startStep 0 / 0
TypeScript