How do we store and work with collections of related data?
Use one-dimensional and two-dimensional arrays and records to store collections of data, and access elements using indexes and field names.
A focused answer to AQA GCSE Computer Science 3.2.6, covering one-dimensional and two-dimensional arrays and records, and accessing elements using indexes and field names.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
AQA wants you to use one-dimensional and two-dimensional arrays and records to store collections of data, and to access individual elements using an index or a field name.
One-dimensional arrays
For example scores <- [10, 25, 8]; then scores[0] is 10 and scores[2] is 8. The big advantage is that an array can be processed with a loop: instead of naming a hundred variables, you store a hundred values in one array and step through the indexes with a FOR loop. A five-element array has valid indexes 0 to 4, so the last index is always one less than the number of elements.
Two-dimensional arrays
A 2D array suits anything naturally grid-shaped: a noughts-and-crosses board, a seating plan, a timetable, or a spreadsheet of marks. Nested loops (a loop inside a loop) are the standard way to visit every cell, the outer loop stepping through rows and the inner loop through columns.
Records
For example a student record might have fields name (string), age (integer) and present (Boolean), accessed as student.name and student.age. The field names make the code self-documenting, because student.age is clearer than an array element student[1].
Arrays versus records
The key contrast is that an array holds values of the same type accessed by a numeric index, while a record holds related values that may be of different types accessed by a field name. Real programs often combine them, for example an array of student records.
Processing a two-dimensional array
A 2D array is visited with nested loops: an outer loop steps through the rows and an inner loop steps through the columns of each row. For a grid board with 3 rows and 3 columns, FOR row <- 0 TO 2 containing FOR col <- 0 TO 2 then OUTPUT board[row][col] will print every cell, row by row. This is how you total a table of marks, search a seating plan, or check a noughts-and-crosses board. The key is to keep clear which index is the row and which is the column, and to loop each from 0 to one less than the number of rows or columns.
Try this
Q1. State what an array index is. [1 mark]
- Cue. The position number of an element, used to access it, usually starting at 0.
Q2. Explain one difference between an array and a record. [2 marks]
- Cue. An array stores values of the same type accessed by index; a record stores related values of possibly different types accessed by field name.
Exam-style practice questions
Practice questions written in the style of AQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AQA 20194 marksAn array scores holds [10, 25, 8, 40, 15], with indexes starting at 0. State the value of scores[3], and write AQA-style pseudocode using a FOR loop to output every element of the array.Show worked answer →
With zero-based indexing, scores[3] is the fourth element, which is 40.
A correct loop:
FOR i <- 0 TO 4 OUTPUT scores[i]ENDFOR
Markers reward the correct element (40, not 8), and a loop that runs from index 0 to 4 (the last valid index of a five-element array) outputting scores[i] each time. Looping to 5 would cause an out-of-range error.
AQA 20224 marksA program stores details of a student. Explain why a record is more suitable than an array for this, and give the fields and data types you would use. Show how you would access the student's age.Show worked answer →
A record is more suitable because a student's details are of different data types, and a record can hold values of different types under one name with each accessed by a meaningful field name. An array must hold values of a single type accessed by a numeric index, which is awkward for mixed data.
Suitable fields: name (string), age (integer), present (Boolean). The age is accessed as student.age.
Markers reward the key reason (records allow mixed types with named fields), sensible fields with types, and the field-name access student.age.
Related dot points
- Use the common data types, declare and assign variables and constants, and understand the difference between a variable and a constant.
A focused answer to AQA GCSE Computer Science 3.2.1, covering the common data types, declaring and assigning variables and constants, and the difference between a variable and a constant.
- Use the three programming constructs of sequence, selection and iteration, including definite and indefinite iteration, and nest them.
A focused answer to AQA GCSE Computer Science 3.2.2, covering the three programming constructs of sequence, selection and iteration, the difference between definite and indefinite iteration, and nesting.
- Use subroutines (procedures and functions), pass parameters and return values, and understand the scope of local and global variables.
A focused answer to AQA GCSE Computer Science 3.2.8, covering subroutines (procedures and functions), passing parameters, returning values, and the scope of local and global variables.
- Understand and explain how the linear search and binary search algorithms work, trace each one, and compare them including the requirement that binary search needs a sorted list.
A focused answer to AQA GCSE Computer Science 3.1.3, covering how linear search and binary search work, how to trace each one, and how they compare including why binary search needs a sorted list.
Sources & how we know this
- AQA GCSE Computer Science (8525) specification — AQA (2020)