IPA IP 2021 Question 74
A question IPA Japan published in 令和3年度 ITパスポート試験 公開問題 問74, translated into English. ITPEC is based on the same exams.
In the processing shown in Flowchart X, the value of variable i changed as 1 → 3 → 7 → 13, and in the processing shown in Flowchart Y, the value of variable i changed as 1 → 5 → 13 → 25. Which of the following is the appropriate combination of words to be inserted into blanks A and B in the figures?
(Note) The repetition specification of a loop limit shows variable name: initial value, increment, final value.
Explanation
A: i + 2k, B: k: 2, 2, 6 — trace each flowchart's loop and see which expression and loop range give the stated sequences.
Flowchart X runs its loop for k = 1, 2, 3 and must take i from 1 to 3, 7 and 13. The increases are 2, 4, 6, that is 2k each time, so blank A is i + 2k:
- •k = 1: 1 + 2 = 3
- •k = 2: 3 + 4 = 7
- •k = 3: 7 + 6 = 13
With 2i + k, the second step would give 2 × 3 + 2 = 8, not 7.
Flowchart Y uses the same blank A, and takes i from 1 to 5, 13 and 25. The increases are 4, 8, 12, so 2k must be 4, 8, 12, and k runs 2, 4, 6: initial value 2, increment 2, final value 6, blank B is k: 2, 2, 6.
- •k = 2: 1 + 4 = 5
- •k = 4: 5 + 8 = 13
- •k = 6: 13 + 12 = 25
Answer (d)
Why not others:
- •(a) and (b) — with A as 2i + k, Flowchart X gives 1 → 3 → 8 → 19, not 1 → 3 → 7 → 13
- •(c) — A is right, but k: 1, 3, 7 means k = 1, 4, 7, so Y gives 1 → 3 → 11 → 25: it ends at 25 but passes through 3 and 11, not 5 and 13
Key rule: Fix the shared blank from the flowchart that is fully given, then work back from the differences in the other sequence to its loop's initial value, increment and final value.
Algorithm and Programming · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.