Classic algorithms · 11 / 22 Exercise Medium

Selection sort

Objective

Create a Python program that sorts a list with the selection sort algorithm and shows the list after each step.

Instructions

  • Read a line with at least two integers separated by spaces.
  • For each position i from 0 to len(list) - 2: find the position of the smallest element between i and the end (if there is a tie, the first one) and swap it with the one at position i.
  • After each step show Step K: n1 n2 ..., with K starting at 1.
Input
64 25 12 22 11
Output
Step 1: 11 25 12 22 64
Step 2: 11 12 25 22 64
Step 3: 11 12 22 25 64
Step 4: 11 12 22 25 64

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise