Selects the smallest remaining element each pass and moves it into place.
Selects the smallest remaining element each pass and moves it into place.
Time complexity: O(n²). Space complexity: O(1).
Core idea — Each pass scans the unsorted region for the smallest element and swaps it into place.
What each pass accomplishes — After pass k the k smallest elements are locked into their final positions at the front — the sorted region grows by one from the left each pass.
Use the interactive visualizer above to run Selection Sort on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.