Selection Sort algorithm in pseudocode

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Selection Sort algorithm in pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does selection sort find the smallest remaining element each pass?
A Yes
B No
2. Does selection sort require the array to already be sorted?
A Yes
B No
3. Is arr[j] < arr[min] used to compare elements for the minimum?
A No
B Yes
4. Does min ← j record the position of a smaller element found?
A Yes
B No
5. Is min = j valid assignment syntax in pseudocode?
A No
B Yes

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1min ← 1 AWrong - array elements use square brackets, not round brackets
2IF arr[j] < arr[min] THEN BChecks whether the current element is smaller than the tracked minimum
3Records the position of the smaller element found CSets the starting minimum index to the first position
4Swaps the minimum element into its sorted position Dmin ← j
5IF arr(j) < arr[min] THEN EWrong - assignment uses ←, not =, in pseudocode
6min = j Farr[1] ← arr[min]

Definitions

Selection Sort

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ i FROM 1 TO 4
2.
__ arr[j] < arr[min] THEN
3.
IF arr[j] _ arr[min] THEN
4.
min _ j
5.
___ ← 1

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A FOR i FROM 0 TO 4
B min ← i
C FOR j FROM i+1 TO 5
Question 2
A FOR i FROM 1 TO 4
B min = i
C FOR j FROM i+1 TO 5
Question 3
A min ← i
B FOR j FROM i+1 TO 5
C IF arr(j) < arr[min] THEN
Question 4
A min ← i
B FOR j FROM i+1 TO 5
C IF arr[j] < arr[min] THEN
D min = j
Question 5
A FOR i FROM 1 TO 4
B min ← i
C FOR j FROM i+1 TO 5
D IF arr[j] < arr[min] THEN
E min == j

Answer Key

Selection Sort algorithm in pseudocode
Section A: Quick Questions
Q1
A — Yes
Q2
B — No
Q3
B — Yes
Q4
A — Yes
Q5
A — No
Section B: Match the Pairs
Q1
min ← 1 → Sets the starting minimum index to the first position
Q2
IF arr[j] < arr[min] THEN → Checks whether the current element is smaller than the tracked minimum
Q3
Records the position of the smaller element found → min ← j
Q4
Swaps the minimum element into its sorted position → arr[1] ← arr[min]
Q5
IF arr(j) < arr[min] THEN → Wrong - array elements use square brackets, not round brackets
Q6
min = j → Wrong - assignment uses ←, not =, in pseudocode
Section C: Definitions
Q1
Selection Sort — An algorithm that repeatedly finds the smallest remaining element and swaps it into its correct position.
Section D: Fill in the Blanks
Q1
FOR i FROM 1 TO 4
Q2
IF arr[j] < arr[min] THEN
Q3
IF arr[j] < arr[min] THEN
Q4
min ← j
Q5
min ← 1
Section E: Spot the Error
Q1
A — Selection sort starts at index 1, not 0, by convention.
Q2
B — Assignment uses ←, not =, in pseudocode.
Q3
C — Array elements use square brackets, not round brackets.
Q4
D — Assignment uses ←, not =, to update min.
Q5
E — Assignment uses ← only, not ==, in pseudocode.