DSA Lab

Selection sort visualizer

Find the smallest value in the unsorted part and swap it to the front of that part. Repeat with one item fewer each time. When writing to memory is expensive: it makes at most n − 1 swaps, the fewest of the simple sorts.

Selection sort: its cost, and how to use this tool

Time: best O(n²), average O(n²), worst O(n²). Extra memory: O(1). Not 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

See also