Selection Sort Visualizer

Selection Sort

Selection Sort repeatedly finds the minimum element from the unsorted part and places it at the beginning. it keeps growing the sorted portion from left to right.


void selectionSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        int minIndex = i;
        for (int j = i + 1; j < n; j++) {
            if (arr[j] < arr[minIndex])
                minIndex = j;
        }
        swap(arr[i], arr[minIndex]);
    }
}





        

Practice

Level Up