Algorithm visualizer
Pick an algorithm, enter your own numbers or use a preset, then step through the run. The pseudocode and the explanation follow each step.
Repeatedly swap neighbours that are out of order. Each pass pushes the largest unsorted value to the end.
Count the swaps for the descending preset. Can you give a formula for it in terms of n?
Step 1 of 44
Start: nothing is in its final place yet.