Storage and data organisation - Eduqas1D and 2D arrays

Arrays form the basis for how data is stored within a program. They must be declared with meaningful identifier names and appropriate data types that match the data. Without the correct data structures and data types, programs will not work.

Part ofComputer ScienceUnderstanding Computer Science

1D and 2D arrays

Arrays

An is a that allows a programmer to organise data into groups of similar data. All the data in an array must be the same .

Using arrays to structure data

One-dimensional arrays

Take, for example, a list of employees in an organisation. These could be stored in an array called 'Employees' with the data typestring.

0123
Ivan WeberSue ThompkinsAkansha SharKeith Wilson
0Ivan Weber
1Sue Thompkins
2Akansha Shar
3Keith Wilson

Each employee in the organisation class can be identified by their position in the array, which is called an index. Computers tend to count from 0, so in the example above ‘Ivan Weber’ is 0, ‘Sue Thompkins’ is 1, and so on. This would be referenced in a program or using the name of the array, in this case 'Employees', with the index in square brackets.

Employees [0] = ‘Ivan Weber’

Employees [1] = ‘Sue Thompkins’

Two-dimensional arrays

Where the manager needs to store more data about each employee they may use a two-dimensional array, which can be described as a matrix with rows and columns. This allows each piece of data to be divided into separate categories. Instead of storing only the name of each employee they may store their first name and surname separately, along with their staff number and postcode. All the data in a two-dimensional array has to be the same data type, in this example ‘string’.

Employees

StaffNumberFirstNameSurnamePostcode
0123
0B22IvanWeberGU12 7FD
1B45SueThompkinsKS3 8GB
2D230AkanshaSharRH3 6SA
3C12KeithWilsonCH4 4DC
StaffNumber0
FirstName1
Surname2
Postcode3
0
StaffNumberB22
FirstNameIvan
SurnameWeber
PostcodeGU12 7FD
1
StaffNumberB45
FirstNameSue
SurnameThompkins
PostcodeKS3 8GB
2
StaffNumberD230
FirstNameAkansha
SurnameShar
PostcodeRH3 6SA
3
StaffNumberC12
FirstNameKeith
SurnameWilson
PostcodeCH4 4DC

This would be referenced in a program or pseudocode using square brackets to represent the row and then the column.

The postcode of Akansha Shar can be found in 'Employees' [2,3].

Two-dimensional arrays are often used to process pixel colour data of images.