Enter comma separated numbers for sorting
Unsorted
Sorted
Current Position
Scanning
Minimum Found
Swapping
Ready
0
Elements
0
Pass
0
Comparisons
0
Swaps
Execution
About Selection Sort Visualizer
The Selection Sort Visualizer helps you understand how the selection sort algorithm works in a simple, interactive way. Instead of just reading code, you can actually see how the algorithm selects the smallest element and places it in the correct position step by step.
Key Features
- Step-by-step visualization
- Minimum element highlighting
- Color-coded states (sorted, unsorted, scanning, swapping etc.)
- Run and step modes
- Adjustable speed control
- Custom input and random data generation
- Live statistics (comparisons, swaps, passes)
- Execution log with explanations
- Reset functionality
How to Use the Selection Sort Visualizer
Using the visualizer is simple and interactive. Follow these steps -
- Enter numbers separated by commas
- Click
LoadorRandomto set data - Use
Runfor automatic sorting orStepfor manual execution - Adjust speed using the slider
- Follow colors to understand each operation
- Check the execution log for step details
- Click
Resetto start again
As the algorithm runs, different colors represent different actions -
- š£ Unsorted ā Elements yet to be processed
- š¢ Sorted ā Elements in final position
- šµ Current Position ā Current index being placed
- š Scanning ā Elements being compared
- š” Minimum Found ā Current smallest element
- š“ Swapping ā Elements being exchanged
What is Selection Sort Algorithm?
Selection Sort is a simple comparison-based sorting algorithm that works by repeatedly finding the smallest element from the unsorted part of the array and placing it at the beginning.
How it works
- Start from the first element
- Find the minimum element in the remaining unsorted array
- Swap it with the current position
- Move to the next position
- Repeat until the array is fully sorted
Example
Array: [29, 10, 14, 37, 13]
- Pass 1 ā smallest is 10 ā swap with 29 ā
[10, 29, 14, 37, 13] - Pass 2 ā smallest is 13 ā swap with 29 ā
[10, 13, 14, 37, 29] - Pass 3 ā smallest is 14 ā already in place
- Pass 4 ā smallest is 29 ā swap with 37
Final sorted array: [10, 13, 14, 29, 37]
Time Complexity
- Best Case: O(n²)
- Average Case: O(n²)
- Worst Case: O(n²)