Exam-style question
Try this first
A programmer needs to represent a 4 by 5 grid of integer values. Explain how a two-dimensional array can model this grid. Then describe how the idea generalises to an n-dimensional array, including the role of the indexing tuple.
Model answer
What a good answer should say
- A two-dimensional array can contain four rows and five columns, with each element being an integer.
- Each value is identified by two indices, one for its row and one for its column.
- For example, an element can be referred to using an expression such as grid[row][column] in Python.
- More generally, an n-dimensional array is a set of elements with the same data type.
Explanation
Why this works
The answer links the two-dimensional case to the general definition. It identifies the dimensions, the common data type, and the fact that an ordered tuple of n integers identifies an element.
A matrix or grid is a suitable example of a two-dimensional array.
Common mistake
No common mistake is linked to this question yet.
