ITPEC FE Subject B April 2026 Question 11
ITPEC FE Subject B April 2026 — Question 11 of 20
A is count[k] > 0 and B is i ← i + 1.
The second loop walks the key values from 1 to M and writes each one as many times as it occurred:
- •Blank A — the guard must ask whether the key value
kappeared at all, which iscount[k] > 0; keys with a count of 0 are skipped - •Blank B —
iis the write position inresult, so after storing a value it must advance by one
For the example, count is {1, 0, 2, 1, 2, 1}: key 2 has count 0 and is skipped, key 3 is written twice, and i moves forward once per written element, producing {1, 3, 3, 4, 5, 5, 6}.
Answer (d)
Why not others:
- (a), (b) and (c) — index count with i, but i is the output position, not a key value; the loop would consult the frequency of the wrong number and run past the end of count once i exceeds M
- (e) — sets i from j, the inner repetition counter, which restarts near 1 on every key and overwrites the beginning of the result
- (f) — sets i from k, a key value rather than a position, so identical keys all land in the same slot
Key rule: Keep the roles of the counters distinct — k selects the key, j counts repetitions, i marks the next free slot in the output. Most of the wrong options come from mixing two of them.
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.