Selection Sort
In this exercise we will specify the selection sort algorithm running on a small, fixed-size array of three integers.
Variables
-
A function
numsfrom the indices{1, 2, 3}to values in{1, 2, 3}. The function represents the array of numbers being sorted. For example,nums[i]equals the value stored at positioni. -
The position
minimum_indexwhich represents the next location to be sorted.
Initial State
-
numsmay be any function from{1, 2, 3}to{1, 2, 3}. minimum_indexis1.
Transitions
- If
minimum_indexis less than or equal to the length ofnums- Find the smallest element in the range
minimum_index..3. - Swap it with the element at
minimum_index. - Advance
minimum_indexby1.
- Find the smallest element in the range
- If
minimum_indexis greater than the length ofnums- The state does not change.