Selection Sort

Sort an array using the selection sort algorithm by repeatedly finding the minimum element.

Code

Algorithms
a = arr.copy()
for i in range(len(a)):
    min_idx = i
    for j in range(i + 1, len(a)):
        if a[j] < a[min_idx]:
            min_idx = j
    a[i], a[min_idx] = a[min_idx], a[i]
return a

Parameters

Array to sort

Server

More Python Snippets