One-Dimensional Arrays
Master One-Dimensional Arrays for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). A one-dimensional array stores a list of values of the same type under one identifier.
Free downloads
These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.
Topic overview
An array is a data structure holding multiple values of the same data type under a single name, with each element accessed by its index.
Declaring scores as an array of 5 integers creates 5 storage slots. Individual elements are accessed as scores[0], scores[1] and so on. As with strings, indexing starts at 0, so an array of 5 elements has indexes 0 to 4.
The advantage over separate variables is that arrays work with loops. Processing 100 separate variables would need 100 lines of code; processing a 100-element array needs a loop of three lines. This is why arrays and iteration are almost always examined together.
Revision notes
Declaring and accessing
An array holds multiple values of the same type under one name.
Elements are accessed by index: scores[0] is the first, scores[1] the second. An array of 5 elements has indexes 0 to 4, so the last index is one less than the size.
Why arrays help
Arrays can be processed with loops, which separate variables cannot.
A FOR loop from 0 to 4 can access every element of a 5-element array in three lines. Doing the same with 5 separate variables would need 5 separate statements.
Common operations
Traversing: use a FOR loop over every index.
Searching: check each element against a target. Finding a total: initialise a running total to 0, then add each element inside the loop. Finding the largest: keep a running maximum and update it whenever a larger element is found.
Key points
- An array holds values of the same data type.
- Elements are accessed by index.
- Indexing starts at 0.
- The last index is the size minus 1.
- Arrays can be processed with loops.
- Arrays and iteration are used together.
Worked examples
Example 1
An array called scores holds 8 elements. State the index of the first and last elements. [2 marks]
Working
Example 2
Write pseudocode to total the elements of a 5-element array called nums. [3 marks]
Working
Example 3
Explain one advantage of using an array rather than separate variables. [2 marks]
Working
Common mistakes
Using an index equal to the array size.
Indexes run from 0 to size minus 1.
Forgetting to initialise a running total.
It must be set to 0 before the loop starts.
Storing different data types in one array.
All elements must be the same type.
Starting the loop at 1.
Array indexing starts at 0.
Exam tips
- Remember the last index is size minus 1.
- Initialise running totals before the loop.
- Loop from 0 to size minus 1.
- Link arrays to loops when justifying their use.
Key terms
- Array
- A structure holding multiple values of one type.
- Element
- One value stored in an array.
- Index
- The position of an element, starting at 0.
- Traverse
- To visit every element in turn.
Related topics
Written and reviewed against the current AQA specification. Spotted an error? Let us know.