Grade 12 Computer Science · Two-dimensional arrays
Common mistakes with grids
The four mistakes stemming from forgetting a row is an array.
Four mistakes, and three of them are one
Swapping the two positions, asking about a length in the wrong place, assuming every row is equal. Three mistakes that look entirely different, and yet one picture in your head prevents all three. And the fourth, the quietest of all, does not come from it at all. What is the picture?
Three of the four mistakes below vanish the moment the picture from the first lesson is held in mind: there is no grid, there is an array whose items are arrays. The fourth belongs to the neighbour pattern.
- Swapping the two positions — The first chooses a row and the second a cell within it, and they are not symmetric. Think “row then cell”, not “row and column”. The phrasing prevents the mistake in advance.
- Asking about a length in the wrong place — The outer structure knows how many rows; only the row knows how many cells are in it. Ask each row separately, inside the outer loop. It costs nothing and works for any shape.
- Assuming all the rows are of the same length — A column-by-column traversal breaks, and a length kept outside skips or exceeds. The natural order makes no such assumption. In the second order — verify explicitly that the shape is rectangular.
- Forgetting to skip the cell itself when counting neighbours — Nine positions and not eight; every count is greater by one and every average skewed. The skip line first in the loop’s body, so it is not forgotten when logic is added.