DSA Lab
Sorting visualizer
Nine sorting algorithms, one step at a time. See which items are compared and moved, which line of code is running, and why, then test yourself.
Bubble sort: how it works and when to use it
Pick any of the nine algorithms above: each opens on its own page. This page starts with bubble sort.
Walk along the list swapping neighbours that are out of order. After each pass the largest remaining value has bubbled to the end.
Teaching, and tiny lists. With the early stop it notices an already sorted list in one pass.
Time: best O(n), average O(n²), worst O(n²). Extra memory: O(1). Stable, in place.
Sort a ready-made input or your own numbers. The bars are the array; the code beside them (in Python, C, C++ or Java) marks the line that just ran, and every step is explained and worked out below the bars.
Lessons that use it
- Bubble, selection and insertion sort (Algorithms)Three O(n²) sorts, step by step: swapping neighbours, picking the minimum, and inserting into a sorted part.