What is Bubble Sort?
Repeatedly compare neighbouring values and swap them until the list is sorted.
Type a tool name, format or task
Repeatedly compare neighbouring values and swap them until the list is sorted. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Repeatedly compare neighbouring values and swap them until the list is sorted. Compare the first two values and swap them if the left one is bigger. Move one step right and repeat until the end - the biggest value has bubbled to the last place. Repeat the pass for the remaining values until no swaps are needed. Time complexity: O(n²). Space complexity: O(1). Mostly for learning. It shows the idea of comparing and swapping that table sorting in the UI is built on.
Repeatedly compare neighbouring values and swap them until the list is sorted.
Time: O(n²). Space: O(1).
Mostly for learning. It shows the idea of comparing and swapping that table sorting in the UI is built on.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Start with 10 numbers. Bubble sort compares neighbours and swaps them when they are in the wrong order.
function bubbleSort(arr) {for (let i = 0; i < arr.length - 1; i++) {for (let j = 0; j < arr.length - 1 - i; j++) {if (arr[j] > arr[j + 1]) {[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];}}}return arr;}
Tip: use the arrow keys to step and the space bar to play or pause.