ITPEC FE Subject B April 2025 Question 11

Source exam: ITPEC FE Subject B April 2025Topic: Sorting

ITPEC FE Subject B April 2025 — Question 11 of 20

Counting sort uses a frequency array where each index represents a value and each element stores its occurrence count.

The procedure implements counting sort:

  • s[0..10] is a frequency array initialized to all zeros
  • First loop: for each element arr[i], increment s[arr[i]] — this counts how many times each value (0–10) appears
  • Second loop: iterate i from 0 to 10; if s[i] > 0, output i exactly s[i] times

Blank A (description): asks for the contents of array s after the counting phase:
- s = {2, 1, 1, 3, 0, 1, 0, 0, 1, 2, 0} — each position holds the frequency of that value in arr

Blank B (program): the value printed is i (the index of the frequency array = the actual number being sorted)

Why not others:
- a/b/c) show the sorted output {0,0,1,2,3,3,3,5,8,9,9} — that is the printed result, not the contents of array s

- d/e/f) show unique sorted values {0,1,2,3,5,8,9} — neither s contents nor full sorted output

- h) correct s but B = jj is just the loop counter for repetition, not the value to print

- i) correct s but B = s[j] — would print the frequency count, not the value itself

Key rule: In counting sort, the frequency array index is the value; you output the index i repeatedly s[i] times. The array s itself holds counts, not sorted values.

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.