ITPEC IP April 2024 Question 9

Source exam: ITPEC IP April 2024Topic: Algorithm and Programming

ITPEC IP April 2024 — Question 9 of 100

A must be i minus 1, and B must be the last array element. The program first saves the original first element, 1, in tmp. During the loop, each element at index i must move into the preceding position, so the assignment is array[i - 1] ← array[i].

For a five-element array, the loop copies indices 2 through 5 into indices 1 through 4, producing {2, 3, 4, 5, 5} temporarily. The saved first value is then placed at the final index 5, producing {2, 3, 4, 5, 1}.

Answer (d)

Why not others:
- (a) and (b) use i + 1, which shifts in the wrong direction and can address beyond the array

- (c) uses the correct i - 1 shift but writes tmp to index n - 1, overwriting the fourth element rather than filling the last position

Key rule: A circular left shift stores the first element, moves every later element one index lower, and restores the saved element at index n.

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 IP past-paper collection or Report an issue.