ITPEC FE Subject B October 2025 Question 2

Source exam: ITPEC FE Subject B October 2025Topic: Array Manipulation

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 (i from 1 to n-1): picks each candidate element arr[i]
  • Counter reset: c ← 1 (the element counts itself)
  • Inner loop (j from i+1 to n): compares arr[i] with every subsequent element
  • Blank A = arr[i] = arr[j] — checks if arr[j] matches the current candidate; if yes, increments c
  • Blank B = m_c < c — after counting, checks if this candidate's frequency c exceeds the current best m_c; if yes, updates m_c ← c and m ← 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.