Selection Sort Visualizer — Animated, Step-by-Step
Animated selection sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs in your browser.
Code examples
Ready-to-copy reference implementations. Free to use in your own projects and assignments.
How to use
- 1 Press Play to watch each pass scan for the minimum and swap it into place.
- 2 Use Step to advance one comparison at a time as the minimum is tracked.
- 3 Type your own numbers into Custom input and press Apply.
- 4 Follow the highlighted pseudocode and the live comparison / swap counters.
Why use this tool
- See how each pass selects the smallest remaining value and places it at the front.
- Notice it always does the same number of comparisons regardless of input order.
- Metrics show why it makes at most n−1 swaps — useful when writes are expensive.
- Runs entirely in your browser. No signup, no uploads.
Frequently asked questions
What is selection sort?
Selection sort divides the array into a sorted and an unsorted part. Each pass scans the unsorted part for the minimum and swaps it to the boundary.
What is the time complexity of selection sort?
O(n²) in all cases — best, average, and worst — because the scan for the minimum always examines every remaining element.
Is selection sort stable?
No. The long-distance swap of the minimum can move an equal element past another, changing relative order. A linked-list variant can be made stable.
When is selection sort useful?
When the number of writes must be minimized — it performs at most n−1 swaps, far fewer than bubble sort. Otherwise insertion sort is usually preferred.
What is Selection Sort Visualizer?
A Selection Sort Visualizer animates how selection sort repeatedly finds the minimum of the unsorted region and swaps it to the boundary. It shows why the algorithm always performs O(n²) comparisons but at most n−1 swaps.
Features
Step-by-step animation
Watch the minimum get found and swapped to the front each pass.
Complexity
Time: O(n²) in all cases. Space: O(1). In-place; not stable. Only O(n) swaps.
100% private
Runs entirely in your browser — nothing is uploaded.
Example
Input
[64, 25, 12, 22]
Output
select 12 → [12,25,64,22]; 22 → [12,22,64,25]; 25 → [12,22,25,64] (sorted)
Common use cases
-
1
Learn selection logic
See why the comparison count is fixed at ~n²/2 regardless of input.
-
2
Minimize writes
Understand where selection sort helps when swaps/writes are costly.
-
3
Contrast with insertion sort
Compare its fixed O(n²) against insertion sort's best-case O(n).
Zerethon's selection sort visualizer animates the algorithm in your browser, repeatedly selecting the minimum of the unsorted region and swapping it into place. Selection sort always runs in O(n²) time (best, average, and worst are identical) with O(1) extra space; it is in-place but not stable. It minimizes the number of swaps (O(n)).
- Category
- Algorithm
- Pricing
- Free
- Privacy
- Browser-based
- Signup
- Not required
References
- MIT OCW 6.006 — Introduction to Algorithms (CLRS) — MIT OpenCourseWare
- VisuAlgo — Sorting — VisuAlgo (NUS)
- Selection sort — Wikipedia
Privacy
Your data never leaves your browser unless explicitly stated. Selection Sort Visualizer runs entirely client-side — no server upload, no logging, no tracking of your input.
New to this? Read the step-by-step explanation with Big-O analysis: Learn Sorting Algorithms →
Related tools
Bubble Sort Visualizer
Animated bubble sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs entirely in your browser.
Open toolInsertion Sort Visualizer
Animated insertion sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolMerge Sort Visualizer
Animated merge sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolQuick Sort Visualizer
Animated quicksort with pivot/partition highlights, step controls, speed, custom input, live counters and pseudocode. Runs in your browser.
Open toolBuild, share, and grow on Zerethon Social
Free signup. Earn points, collect achievements, and connect with creators worldwide.