Selection Sort Visualizer

Unsorted
Sorted
Current Position
Scanning
Minimum Found
Swapping
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 Load or Random to set data
  • Use Run for automatic sorting or Step for manual execution
  • Adjust speed using the slider
  • Follow colors to understand each operation
  • Check the execution log for step details
  • Click Reset to 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

  1. Start from the first element
  2. Find the minimum element in the remaining unsorted array
  3. Swap it with the current position
  4. Move to the next position
  5. 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²)