ITPEC FE Subject B October 2025 Question 2
ITPEC FE Subject B October 2025 — Question 2 of 20
The program finds the mode of an integer array using a brute-force frequency count:
- •Outer loop (
ifrom 1 to n-1): picks each candidate elementarr[i] - •Counter reset:
c ← 1(the element counts itself) - •Inner loop (
jfrom i+1 to n): comparesarr[i]with every subsequent element - •Blank A =
arr[i] = arr[j]— checks ifarr[j]matches the current candidate; if yes, incrementsc - •Blank B =
m_c < c— after counting, checks if this candidate's frequencycexceeds the current bestm_c; if yes, updatesm_c ← candm ← arr[i]
Why not others:
- Options a, b (B: m < arr[i] or m ≠ arr[i]): compare the mode value, not frequency — logically wrong
- Option d (B: m_c > c): would update the mode when frequency is lower, finding the least common element instead
- Options e–h (A: m = arr[j]): compare the current mode value m against arr[j] instead of comparing array elements to each other — breaks the counting logic
Key rule: When filling blanks in a frequency-counting algorithm, identify which variable tracks count (c, m_c) vs value (m, arr[i]). The inner loop condition compares values (arr[i] = arr[j]), while the update condition compares counts (m_c < c).
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.