GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 51

Replacement-map failures on abcde

Programming in C · Arrays & Strings · Full GATE CSE 2013 paper

GATE 2013, Q51 2 marks · MCQ
Report issue

Arrays & Strings

Question 51, GATE 2013: Use the same nested replacement loops and four maps 1 abc→dab;2 cde→bcd;3 bca→cda;4 abc→bac. For input abcde specifically, which expose the flaw? A none; B2 only; C3and4; D4 only.
Question 51, GATE 2013: Use the same nested replacement loops and four maps 1 abc→dab;2 cde→bcd;3 bca→cda;4 abc→bac. For input abcde specifically, which expose the flaw? A none; B2 only; C3and4; D4 only.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Apply each map once to each original character to obtain the intended result, then compare with the procedure’s sequential replacements. For input abcde, case 1 has intended and actual output dabde. Case 2 has intended and actual output abbcd. Case 3 should produce acdde, but its b is changed twice, b→c→d, producing addde. Case 4 should produce bacde, but its initial a is changed twice, a→b→a, producing aacde. Therefore cases 3 and 4 expose the defect, option C.

The fixed input contains every candidate letter once, including both b and a that trigger the two flaws. In map 3 the intended b→c is followed by an unintended c→d, changing the second character from expected c to d. In map 4 the intended a→b is followed by unintended b→a, undoing that substitution. Comparing complete strings confirms the discrepancy rather than relying merely on the presence of an intermediate match. Cases 1and2remain unaffected.

Original paper, page 11 · Answer key