Repeatedly swaps adjacent out-of-order pairs; the largest value bubbles to the end each pass.
Repeatedly swaps adjacent out-of-order pairs; the largest value bubbles to the end each pass.
Time complexity: O(n²). Space complexity: O(1).
Core idea — Repeatedly walk the array swapping any adjacent pair that's out of order.
What each pass accomplishes — After each full pass the largest value still unsorted has 'bubbled' all the way to its final place at the end — so the sorted region grows by one from the right every pass.
Use the interactive visualizer above to run Bubble Sort on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.