Seth.

Bubble Sort

Bubble Sort - Technical Overview

1. Algorithm Description: Bubble Sort is a simple comparison-based sorting algorithm. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

2. Steps of Bubble Sort:

  • Start at the beginning of the array.
  • Compare adjacent elements and swap if needed.
  • Move larger elements towards the end of the list.
  • Repeat for the unsorted portion until the array is sorted.

3. Time Complexity: O(n²) in the worst and average case, and O(n) in the best case (when the array is already sorted).

4. Space Complexity: O(1), as it operates in-place.

5. Stability: Bubble Sort is a stable algorithm.

6. Optimizations: Early termination if no swaps are made in a pass.