Skip to topic
    ← Back to course topics

    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

    1. 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
    1. 1Day 1-3: Review definitions of static vs dynamic data structures and practice 1D array linear search and insertion algorithms in standard pseudocode.
    2. 2Day 4-7: Practice tracing nested loops manipulating 2D arrays, specifically focusing on matrix transposition and grid coordinate traversal.
    3. 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)
    Explain

    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)).

    Write

    Produce syntactically valid pseudocode or high-level code implementing array operations without syntax errors or unhandled boundary exceptions.

    Compare

    Identify both similarities and differences between two structures, such as 1D arrays versus 2D arrays, across specified criteria.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing zero-based and one-based indexing or mixing up row and column coordinates in 2D arrays.
    ❌ Weak Answer (Loses Marks):The element at grid[2][3] is found by counting two across and three down.
    Example improved answer:In standard zero-indexed row-major notation, grid[2][3] accesses the element located at row index 2 (the third row) and column index 3 (the fourth column).
    Examiner Tip: Always explicitly check whether the pseudocode or exam question specifies zero-indexed or one-indexed arrays, and remember the convention: array[row][column].
    Pitfall: Describing an array as dynamic or capable of storing multiple data types without qualification.
    ❌ Weak Answer (Loses Marks):An array can grow to whatever size is needed when adding data items.
    Example improved answer:In classical computer science and the AQA specification, an array is a static data structure with a fixed size allocated in contiguous memory locations, containing elements of the same data type.
    Examiner Tip: Distinguish between high-level language implementations (such as Python lists) and true abstract arrays which are fixed-size and homogeneous.
    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. 1.Step 1: Initialise a variable total to 0 to accumulate the sum.
    2. 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. 3.Step 3: Construct an inner loop iterating through every column index c from 0 to 4.
    4. 4.Step 4: Add board[r][c] to total on each iteration.
    5. 5.Step 5: Output the accumulated total after loops terminate.
    Final Answer: total = 0 FOR r = 0 TO 3 STEP 2 FOR c = 0 TO 4 total = total + board[r][c] ENDFOR ENDFOR OUTPUT total

    Question: Explain two differences between a 1D array and a 2D array in terms of indexing and logical representation.

    1. 1.Step 1: Define how 1D arrays are addressed versus 2D arrays (single subscript vs. pair of subscripts).
    2. 2.Step 2: Contrast the logical conceptual models (linear sequence vs. grid/table of rows and columns).
    3. 3.Step 3: State how contiguous memory mapping occurs for both structures.
    Final Answer: Firstly, a 1D array requires a single subscript/index (e.g., arr[i]) to access an element, representing a linear list, whereas a 2D array requires two subscripts (e.g., arr[r][c]), representing a tabular grid of rows and columns. Secondly, while both are stored contiguously in physical memory, accessing an item in a 2D array mathematically involves computing an offset using both row and column boundaries.
    Active Recall Memory Test
    What does it mean that an array is stored in 'contiguous' memory?
    Key Fact: All elements of the array are stored in unbroken, sequential memory addresses directly adjacent to one another.
    What is the formula to calculate the memory address of element arr[i] given base address B and element size S?
    Key Fact: Address = B + (i * S) for zero-indexed arrays.
    Why does an array provide O(1) time complexity for reading any element by index?
    Key Fact: Because the exact memory address can be computed directly in a single mathematical calculation rather than traversing preceding nodes.
    What primary limitation does a static array have compared to a dynamic linked list?
    Key Fact: A static array cannot change its allocated size during runtime, leading to potential buffer overflows or wasted pre-allocated memory.
    Frequently Asked Questions
    Is a Python list the same thing as an array in AQA A-Level Computer Science?
    No. In AQA Computer Science, an array is defined strictly as a static, fixed-size structure storing identical data types in contiguous memory. Python lists are dynamic array wrappers that store pointers to heterogeneous objects and resize automatically. In exams, you must discuss arrays using the classical static, homogeneous definition.
    How do 2D arrays map onto physical RAM if memory is linear?
    Physical RAM is one-dimensional, so multi-dimensional arrays are flattened using either row-major order or column-major order. In row-major order, all elements of row 0 are placed sequentially, immediately followed by row 1, and so on. The memory address is calculated as: Base Address + ((RowIndex * NumberOfColumns) + ColumnIndex) * ElementSize.
    What happens if an algorithm accesses an array index that does not exist?
    Attempting to access an index outside the declared bounds causes an index out-of-bounds exception in high-level managed languages. In low-level languages like C, it can lead to buffer overflow vulnerabilities, reading garbage memory, or a segmentation fault.
    When should I use a 2D array instead of multiple 1D arrays?
    Use a 2D array when data inherently possesses a two-dimensional grid or tabular structure, such as a chess board, image pixels, or spreadsheet matrices. Multiple 1D arrays can be harder to synchronise, whereas a 2D array maintains structured spatial relationships under a single, unified variable identifier.