ITPEC FE Subject B April 2026 Question 12
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array indexes start at 1.
The function isIsomorphic compares the two character arrays s1 and s2 that are given as arguments. Both s1 and s2 have one or more elements.
Two character arrays are considered isomorphic if the characters in s1 can be consistently replaced to obtain s2 without changing the order of characters. Each character in s1 must map to exactly one character in s2, and no two characters in s1 may map to the same character in s2. A character may map to itself.
If s1 and s2 do not have the same number of elements, the function returns false. Otherwise, it returns true if s1 and s2 are isomorphic and false if they are not.
The table lists examples of s1 and s2 given to the function isIsomorphic and the return values.
Table Examples of s1 and s2 given to the function isIsomorphic and the return values
Answer group
Explanation
A: s2[i] ≠ s2[j], B: s2[i] = s2[j] — every pair of positions must agree in both arrays: equal in s1 exactly when equal in s2.
The double loop visits every pair of positions i < j and returns false on either way a one-to-one mapping can break:
- •Blank A:
s1[i] = s1[j]buts2[i] ≠ s2[j]— one source character maps to two different targets.{"f", "o", "o"}against{"b", "a", "r"}fails here at positions 2 and 3. - •Blank B:
s1[i] ≠ s1[j]buts2[i] = s2[j]— two source characters map to one target.{"a", "b"}against{"c", "c"}fails here.
For {"e", "g", "g"} and {"a", "d", "d"} no pair triggers either condition, so the function returns true.
Answer (d)
Why not others:
- •(a) and (b) — compare
s1[i]withs2[j], a character of one array against a character of the other; isomorphism never requires the two alphabets to share letters. With (a),egg/addfails ati= 1,j= 2 because"e" ≠ "d"; with (b) it fails ati= 2,j= 3 because"g" ≠ "d", though the expected result istrue - •(c) — inverts both tests, so it rejects the consistent pairs: for
egg/add, positions 2 and 3 haves1equal ands2equal, and (c) returnsfalse
Key rule: A one-to-one mapping must be checked in both directions: equal sources give equal targets, and different sources give different targets.
String Processing · AI-written, may contain errors
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.