ALGORITHMS_TODAY.COM
◄ BACK_TO_INDEX.exe
[SORTING] MODULE LOADED

BUBBLE_SORT

Repeatedly compares adjacent elements and swaps them into order. The simplest — and slowest — sorting truth.

TIME_COMPLEXITY
O(n²)
SPACE_COMPLEXITY
O(1)
DIFFICULTY
BASIC
STABILITY
STABLE
PROCESS: BUBBLE_SORT.exe■ COMPLETE
> step[001/000]
██ COMPARING██ SWAPPING██ SORTED██ UNSORTED
CLOCK_SPEED
DECRYPTED_SOURCE.js● LIVE
// BUBBLE_SORT.js — O(n²) time complexity
function bubbleSort(arr) {
  const n = arr.length;

  for (let i = 0; i < n - 1; i++) {
    let swapped = false;

    for (let j = 0; j < n - i - 1; j++) {
      // Compare adjacent elements
      if (arr[j] > arr[j + 1]) {
        // Swap in-place
        [arr[j], arr[j+1]] = [arr[j+1], arr[j]];
        swapped = true;
      }
    }

    // Early exit: array already sorted
    if (!swapped) break;
  }

  return arr; // DECODED
}
DECRYPTED_LOGIC.txt
01Outer loop executes n-1 passes over the array
02Inner loop compares each adjacent element pair
03If left element exceeds right — swap positions
04Largest value bubbles rightward each pass
05Short-circuit if no swap detected in a pass