ITPEC FE Subject B October 2025 Question 15
ITPEC FE Subject B October 2025 — Question 15 of 20
Calculating IDF by counting documents containing a given term
The function calcIDF computes IDF for a term across a corpus of documents. Each document is split into words, then each word is compared to term.
- •Blank A is inside the inner loop iterating over
words(the split result ofcorpus[i]), so the comparison must bewords[j] = term - •Blank B checks after the inner loop whether the term was found in that document — since
isContainsTermis set totruewhen found, the condition must beisContainsTerm = true
Why not others:
- corpus[j] = term (options a–d) — corpus[j] is an entire document string, not an individual word; the inner loop index j iterates over words, not corpus
- isContainsTerm = false in B (options e, g) — termCount should increment when the term was found, not when it was absent
- words[j] ≠ term with true (option h) — would set the flag on mismatch, counting documents that do NOT contain the term
Key rule: When a loop splits a string into parts and iterates over them, the comparison target is the split array (words[j]), not the original collection (corpus[j]).
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.