ITPEC FE Subject B April 2024 Question 11
ITPEC FE Subject B April 2024 — Question 11 of 20
Selection sort algorithm with ascending order.
This is a classic selection sort. The outer loop picks position i, and the inner loop finds the minimum in the unsorted portion.
Blank A: `i + 1`
The inner loop j should start searching from i + 1 — the position right after the current candidate. Position i is already assigned to minPos, so we only need to scan the remaining unsorted elements.
Blank B: `<`
Since we sort in ascending order, we look for the smallest element: data[j] < data[minPos].
Blank C: `data[i]`
After finding the minimum, we swap data[i] with data[minPos]:
- temp ← data[i]
- data[i] ← data[minPos]
- data[minPos] ← temp
Why not others:
- (a–d) A = 1 — would re-scan the already sorted portion every iteration, breaking the algorithm
- (c, d, g, h) B = > — would find the maximum, producing descending order
- (f) C = data[i + 1] — swaps with the wrong position; should swap with data[i], not data[i + 1]
Key rule: In selection sort, the inner loop always starts after the current position (i + 1), and the comparison direction (< or >) determines ascending vs descending order.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.