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 nums from 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 position i.
  • The position minimum_index which represents the next location to be sorted.

Initial State

  • nums may be any function from {1, 2, 3} to {1, 2, 3}.
  • minimum_index is 1.

Transitions

  • If minimum_index is less than or equal to the length of nums
    • Find the smallest element in the range minimum_index..3.
    • Swap it with the element at minimum_index.
    • Advance minimum_index by 1.
  • If minimum_index is greater than the length of nums
    • The state does not change.
selection-sort
Ready
⌘↵ to submit