Sorting Visualizer


15

Bubble Sort

Bubble Sort is a simple sorting algorithm that repeatedly compares adjacent elements in a list and swaps them if they are in the wrong order. The process continues until no swaps are needed, indicating that the list is sorted. During each pass, the largest unsorted element "bubbles up" to its correct position at the end of the list. This continues until the entire list is sorted.

Time Complexity:

Space Complexity - O(1)

Algorithm:

  1. Start with the first element of the array.
  2. Repeat the following steps until the array is sorted:
    1. For each pair of adjacent elements:
      1. If the first element is greater than the second, swap them.
    2. Move to the next pair of adjacent elements.
    3. Continue until the end of the array is reached.
  3. After each full pass, the largest unsorted element will be in its correct position.
  4. Repeat the process until no swaps are needed, indicating the array is sorted.
Bubble Sort (GFG)
Source Code LinkedIn