DSA · Interactive
Watch real code sort, search and scan arrays, one step at a time. Pause it, rewind it, feed it your own numbers, and see exactly which line is running.
Most explanations of quick sort are a paragraph and a diagram of the final result. The part that trips people up, what the pointers do in the middle, is left to your imagination.
Here you see every comparison and every swap as it happens, next to the line of code doing it. When you get confused, step back one move. When you think you understand, type in a tricky input like duplicates or a sorted list and check whether you can predict the next step.
That loop of predict, watch, check is how the idea sticks, and it is exactly what an interviewer tests when they ask you to trace an algorithm by hand.
Partition around a pivot, then sort each side. Fast in practice, in place, but not stable.
Avg O(n log n)Space O(log n)
Split in half, sort each half, merge. Always O(n log n) and stable, at the cost of O(n) extra memory.
Avg O(n log n)Space O(n)
Insert each value into the sorted part on its left. O(n²) in general, but close to O(n) on nearly sorted data, and stable.
Avg O(n²)Space O(1)
Find the smallest remaining value and swap it into place. Always n(n − 1)/2 comparisons, but at most n − 1 swaps.
Avg O(n²)Space O(1)
Swap out-of-order neighbours until nothing moves. Stable and simple, O(n) on sorted input with an early exit, O(n²) otherwise.
Avg O(n²)Space O(1)
Build a max-heap, then swap the root to the end and sift down. O(n log n) in every case with O(1) extra memory, but not stable.
Avg O(n log n)Space O(1)
Count each value, take running totals, place values right to left. O(n + k) time and space, stable, but only for small integer ranges.
Avg O(n + k)Space O(n + k)
A stable counting sort on each digit, least significant first. O(d(n + k)) time, O(n + k) space, stable, no comparisons.
Avg O(d · (n + k))Space O(n + k)
Built the same way: real code, line-by-line sync, your own input.
Crio Software Development
Crio's Software Development Fellowship has you practise data structures and algorithms by building real projects, the way they come up at work and in interviews. Start with a free trial session.
Free trial · No credit card required
Last updated 20 November 2026