All problems
Selection Sort
Problem
Sort a list of integers in ascending order and return the sorted list.
Implement selection sort: for each position i, scan the unsorted suffix for the minimum and swap it into position i. The algorithm always performs about n squared over 2 comparisons. Return a new list and handle empty input.
Hint
Find the minimum of the unsorted suffix, then swap it with the first unsorted element.
Test cases
case 1
in: [[64,25,12,22,11]]
expected: [11,12,22,25,64]
case 2
in: [[]]
expected: []
case 3
in: [[7]]
expected: [7]
case 4
in: [[3,-1,3,0]]
expected: [-1,0,3,3]
Starter codePython
def selection_sort(arr):
# Your code here
pass4 test cases · run your code against them in the editor