ITPEC FE Subject B October 2025 Question 12
ITPEC FE Subject B October 2025 — Question 12 of 20
The function slides a window of length seqlen across str. For each starting position i, it compares characters one by one using index j from 1 to seqlen.
- •Blank A — `str[i + j - 1]`: Since both arrays are 1-indexed and
jstarts at 1, the corresponding position instrisi + j - 1. Ati=1, j=1this givesstr[1], correctly aligning the first character. - •Blank B — `j = seqlen + 1`: The
whileloop runs whilej ≤ seqlen. If all characters match,jincrements pastseqlentoseqlen + 1, and the loop exits naturally. If a mismatch occurs,exit whilefires withj ≤ seqlen. Soj = seqlen + 1is the success condition.
Why not others:
- str[i + j] (options a–c) — off by one; skips the first character at each window position
- j = seqlen (options a, d) — j equals seqlen during the last comparison before incrementing, so this is true even mid-comparison, not a reliable success signal
- j = seqlen - 1 (options c, f) — too early; would trigger before all characters are compared
Key rule: In 1-indexed pseudocode, when iterating j from 1 inside a window starting at i, the mapped index is i + j - 1. A while loop's natural exit means the loop variable exceeded the bound — check for bound + 1, not bound.
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.