AQA · GCSE · Computer Science · Higher
Tracing sliding-puzzle code statements
getTile(row, column) returns the tile value on the 3 x 3 board in position (row, column). The blank space is represented by the value 0.
| int ref1, ref2; |
| for (int i = 0; i < 3; i++) |
| { |
| for (int j = 0; j < 3; j++) |
| { |
| if (getTile(i, j) == 0) |
| { |
| ref1 = i; |
| ref2 = j; |
| } |
| } |
| } |
| row \ column | 0 | 1 | 2 |
|---|---|---|---|
| 0 | 4 | 7 | 6 |
| 1 | 3 | 8 | 1 |
| 2 | 0 (blank) | 5 | 2 |
Which two of the following statements about the program in Figure 16 are true when it is used with the board in Figure 17? Shade two lozenges.
Write your answer first. You can study the marking guidance whenever you need it.
Study the marking See what earns credit and compare it with a full-mark answer.
Marking points
- 1 Selects the nested-iteration statement.
- 2 Selects the nine-comparisons statement.
Why this answer loses marks
I counted only the outer loop and chose statements using that total.
The inner loop runs for every outer-loop pass, so the comparison count must cover every board position.