CZ
CalcyZone
computer-science Verified Precision Tool

Bubble Sort Visualizer & Step Calculator

Interactive step-by-step Bubble Sort execution visualizer with comparisons, swaps, and time complexity breakdown.

Interactive Algorithm Visualizer

Bubble Sort

Enter your custom input data → Run the real algorithm engine → Observe step transitions.

⚙️ Customize Algorithm Input Data

Step 1 of 12⚡ Algorithm Running
WHAT HAPPENED?

Initial unsorted array of 5 elements.

WHY?

Algorithm state rule requirement

WHAT CHANGED?

State pointers updated

64
[0]
25
[1]
12
[2]
22
[3]
11
[4]

Mathematical Formula

Compare adjacent elements arr[j] & arr[j+1]; swap if arr[j] > arr[j+1]

Overview & Explanation

Bubble Sort is a simple comparison-based sorting algorithm that repeatedly steps through an array, compares adjacent elements, and swaps them if they are in the wrong order.

How It Works

  • Iterate through the array from left to right.
  • Compare each pair of adjacent elements.
  • Swap elements if the left element is greater than the right element.
  • Repeat passes until no swaps are required.

Practical Applications

  • Educational visualizer for algorithm fundamentals
  • Sorting small or nearly-sorted datasets

Bubble Sort Step Derivation

Sorting array [64, 34, 25, 12, 22]

1

Pass 1

Compare 64 & 34

= Swap -> [34, 64, 25, 12, 22]
2

Pass 2

Compare 64 & 25

= Swap -> [34, 25, 64, 12, 22]
3

Pass 3

Compare 64 & 12

= Swap -> [34, 25, 12, 64, 22]
4

Pass 4

Final Passes

= Sorted -> [12, 22, 25, 34, 64]

Frequently Asked Questions

What is the time complexity of Bubble Sort?
Bubble Sort has a worst and average case time complexity of O(n²) and a best case complexity of O(n) when the array is already sorted.
Is Bubble Sort a stable sorting algorithm?
Yes, Bubble Sort is stable because it only swaps adjacent elements when the left element is strictly greater than the right element.