Single- and multi-dimensional arrays (or equivalent) — AQA A-Level Computer Science
An array is a static, contiguous, and homogeneous data structure used to store elements accessible via numerical indices in single or multi-dimensional forms. In AQA A-Level Computer Science, mastering array dimensions, row-major versus column-major ordering, and efficient index manipulation is essential for both Paper 1 programming and Paper 2 data structure theory.
Single- and multi-dimensional arrays (or equivalent) explained
An array is a fixed-size collection of elements of the same data type, where each element is reached by an index.
Read the full explanation
Using an array in the design of a solution means identifying when a problem involves many related values that must be stored, looked up or processed in turn, and then choosing a structure that holds them under one name. For example, a program that records the daily temperatures for a week needs seven values; rather than declaring seven separate variables, a designer can declare one array of seven elements and use a loop, with the index running from 0 to 6, to read or update each day in turn. Designing with arrays also means considering how the index is calculated, the array's size, and how the program will avoid accessing an index outside the valid range.
Your focus
- Use arrays (or equivalent) in the design of solutions to simple problems.
Which command word is this?
Set out the cause and effect, mechanics, or reasoning of an array operation with linked technical points (e.g., explaining why random access is O(1)).
Single- and multi-dimensional arrays (or equivalent) exam tips
Topic Overview
Arrays are fundamental, contiguous data structures that store collections of items of the identical data type under a single identifier. In single-dimensional form, they provide constant time O(1) random access to linear sequences via an integer index, whereas multi-dimensional arrays extend this concept to multiple axes such as matrices, grids, and volumetric representations.
Understanding array mechanics is critical for Paper 1 programming tasks and Paper 2 systems architecture questions in AQA A-Level Computer Science. Mastery of array traversal, bounds checking, and memory allocation lays the essential foundation for implementing complex abstract data types including stacks, queues, and adjacency matrices for graphs.
Key Concepts
- →Static allocation and homogeneity: True arrays have a predetermined size fixed at declaration and hold items of a single uniform data type.
- →Direct indexing: Elements are retrieved in O(1) time complexity by calculating memory offsets using base address plus index multiplied by element size.
- →Multi-dimensional indexing: Nested indices (e.g., array[row][col] or array[x][y][z]) logically map multi-coordinate structures into linear memory addresses.
- →Row-major vs column-major order: Two-dimensional arrays are stored contiguously in memory by linearising either consecutive rows or consecutive columns.
Marking Points
- Identifies that the problem involves a collection of related values of the same type that must be stored under one name.
- Selects an array to hold those values rather than many separate variables.
- Plans how a loop with an index will access each element in turn.
- Accounts for the array's size and the valid index range when designing access.
- Explains how the chosen array structure supports the solution's required processing.
Examiner Tips
- 💡Show the array declaration, its size and the index range in your design rather than describing it vaguely.
- 💡Link every loop in your design to the array it processes, so the link between structure and iteration is clear.
- 💡Check that every index you use falls within the valid range before finishing the design.
- 💡Always check whether the exam question specifies zero-based or one-based indexing before declaring loop counter bounds in pseudocode.
- 💡Use meaningful variable names like 'row' and 'col' instead of generic 'i' and 'j' when writing nested loops to prevent coordinate inversion mistakes.
- 💡Explicitly mention 'contiguous memory allocation' and 'homogeneous data types' when asked to define an array in Paper 2 theory questions.
Common Mistakes
- Declares a separate variable for each value in a collection, which makes the design hard to extend and repeat; use one array with an index instead.
- Assumes the first index is 1, which causes an off-by-one error when the array starts at 0; check the indexing convention used.
- Uses a loop bound equal to the array length, which accesses an index past the last element; the bound should stop at length minus one.
- Chooses an array for data that has no shared type or meaning, so the structure does not fit the problem; use the structure that reflects the data.
- Confusing Python lists with true arrays: Python lists are dynamic references to heterogeneous objects, whereas formal specification arrays are fixed-capacity and homogeneous.
- Inverting row-column coordinates: Students frequently write array[column][row] instead of array[row][column], leading to index out-of-bounds runtime errors.
- Off-by-one errors: Forgetting that an n-element zero-indexed array has valid indices spanning 0 to n-1, not 0 to n.
Revision Plan
- 1Day 1-3: Review definitions of static vs dynamic data structures and practice 1D array linear search and insertion algorithms in standard pseudocode.
- 2Day 4-7: Practice tracing nested loops manipulating 2D arrays, specifically focusing on matrix transposition and grid coordinate traversal.
- 3Day 8-10: Work through 3D array visualisations (e.g., layered grids or time-series sensor matrices) and practice past Paper 1 and Paper 2 exam questions.
Exam Question Types
- 📋Trace tables: Stepping through nested iteration constructs modifying specific elements in a 2D array.
- 📋Pseudocode algorithm design: Writing procedures to traverse, filter, or aggregate data within multi-dimensional arrays.
- 📋Comparative analysis: Explaining performance and storage differences between static arrays and dynamic lists or linked data structures.
Command Word Expectations (AQA)
Set out the cause and effect, mechanics, or reasoning of an array operation with linked technical points (e.g., explaining why random access is O(1)).
Produce syntactically valid pseudocode or high-level code implementing array operations without syntax errors or unhandled boundary exceptions.
Identify both similarities and differences between two structures, such as 1D arrays versus 2D arrays, across specified criteria.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A 2D array named board has 4 rows and 5 columns, with indices starting at 0. Write an algorithm in pseudocode to calculate and output the sum of all elements located in the even-indexed rows (row 0 and row 2).
- 1.Step 1: Initialise a variable total to 0 to accumulate the sum.
- 2.Step 2: Construct an outer loop iterating over the row index r from 0 to 3 with a step of 2 (or use a step count to select rows 0 and 2).
- 3.Step 3: Construct an inner loop iterating through every column index c from 0 to 4.
- 4.Step 4: Add board[r][c] to total on each iteration.
- 5.Step 5: Output the accumulated total after loops terminate.
Question: Explain two differences between a 1D array and a 2D array in terms of indexing and logical representation.
- 1.Step 1: Define how 1D arrays are addressed versus 2D arrays (single subscript vs. pair of subscripts).
- 2.Step 2: Contrast the logical conceptual models (linear sequence vs. grid/table of rows and columns).
- 3.Step 3: State how contiguous memory mapping occurs for both structures.