Python DSA

Selection Sort

Selection sort algorithm

Selection Sort

Selection sort is an in-place comparison sorting algorithm that divides the input list into two parts.

Selection Sort Implementation

def selection_sort(arr):
    for i in range(len(arr)):
        min_idx = i
        for j in range(i + 1, len(arr)):
            if arr[j] < arr[min_idx]:
                min_idx = j
        arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr