Track progress, take quizzes and save notes on this lesson.

Free forever · no card needed

Start free
Intermediate

Arrays and Abstract Data Types

4.2.1 Data structures and abstract data types: arrays, files, ADTs

Aligned to the AQA 7517 specification

Level
Intermediate
Reading time
5 min
Published
13 June 2026
Updated
1 July 2026
On this page
  1. 1.Arrays
  2. 2.Two-Dimensional Arrays
  3. 3.File Operations
  4. 4.Sequential and Random Access
  5. 5.Abstract Data Types
  6. 6.Common Exam Mistakes

Key takeaways

  • An array stores a fixed number of elements of the same data type in contiguous memory locations, each accessed by an integer index.
  • AQA pseudocode uses 1-based indexing by convention, so the first element is at index 1, while Python, Java, and C++ use 0-based indexing.
  • An abstract data type (ADT) defines a data structure by its behaviour (the operations it supports) without specifying how it is implemented internally.
  • A stack is an ADT that could be implemented using an array or a linked list; describing a stack as an array conflates the abstraction with one particular implementation.
  • Sequential access must read records in order from the beginning, whereas random access computes the address of any record directly: address = start + (N − 1) × record size.

Arrays

An array is a data structure that stores a fixed number of elements of the same data type in contiguous memory locations. Each element is accessed by its index — an integer that specifies its position.

AQA pseudocode uses 1-based indexing by convention (first element is at index 1). Check whether your language uses 0-based (Python, Java, C++) or 1-based indexing.

1D array declaration and access:

DECLARE scores[5] : INTEGER      // Array of 5 integers

scores[1] ← 85
scores[2] ← 72
scores[3] ← 91
scores[4] ← 67
scores[5] ← 88

OUTPUT scores[3]    // 91

Array traversal — process every element using a loop:

total ← 0
FOR i ← 1 TO 5
    total ← total + scores[i]
NEXT i
average ← total / 5

Two-Dimensional Arrays

A 2D array stores data in rows and columns — like a table or grid. It is accessed with two indices: array[row][column].

DECLARE grid[3][3] : INTEGER    // 3×3 grid

// Populate with zeroes
FOR r ← 1 TO 3
    FOR c ← 1 TO 3
        grid[r][c] ← 0
    NEXT c
NEXT r

grid[2][3] ← 7    // Row 2, column 3 = 7
OUTPUT grid[2][3] // 7

Example use: a chessboard is an 8×8 2D array; a multiplication table is a 12×12 2D array; an image is a 2D array of pixel values.

Multi-dimensional arrays extend to 3 or more dimensions — for example, a 3D array could represent a data cube (rows × columns × depth).

File Operations

Programs often need to persist data beyond a single run by reading from and writing to files. AQA requires knowledge of:

OperationAQA pseudocodeEffect
Open for readingOPENFILE "data.txt" FOR READOpens file; positions at start
Open for writingOPENFILE "data.txt" FOR WRITEOpens file; overwrites content
Open for appendingOPENFILE "data.txt" FOR APPENDOpens file; positions at end
Read one lineREADFILE "data.txt", lineReads next line into line
Write one lineWRITEFILE "data.txt", valueWrites value then newline
Check end of fileEOF("data.txt")Returns True if at end
CloseCLOSEFILE "data.txt"Closes file; writes buffered data

Worked example — read all lines from a file and output each:

OPENFILE "students.txt" FOR READ
WHILE NOT EOF("students.txt") DO
    READFILE "students.txt", name
    OUTPUT name
ENDWHILE
CLOSEFILE "students.txt"

Files must be closed after use. Unclosed files can cause data loss (unflushed buffer) or prevent other programs from accessing the file.

Sequential and Random Access

Sequential access — data must be read from the beginning in order. Reading record 50 requires reading records 1 through 49 first. Used for log files, streaming data.

Random access — any record can be accessed directly by its position (address). Used for databases and binary files where records have a fixed size.

For the same file of fixed-size records [Rec1][Rec2][Rec3]...[Rec50], sequential access must read records 1 to 49 before reaching record 50, whereas random access computes the address of any record directly:

Magnetic tape only supports sequential access. Hard disks and SSDs support random access.

Want more lessons like this one?

Generate lessons on anything you study. Free account, no card needed.

Start generating

Abstract Data Types

An abstract data type (ADT) defines a data structure in terms of its behaviour — the operations it supports — without specifying how it is implemented internally.

This separation is important:

  • Code that uses an ADT depends only on its defined interface
  • The implementation can change (e.g. from array-based to linked-list-based) without affecting any calling code
  • Different implementations can be substituted without rewriting user code
ADTCore operationsDefining property
Stackpush, pop, peek, isEmptyLIFO
Queueenqueue, dequeue, isEmptyFIFO
Listappend, insert, delete, search, getOrdered, indexed
Dictionaryset, get, delete, containsKey-value lookup
GraphaddVertex, addEdge, getNeighboursVertex-edge structure

Interface vs implementation:

Interface (what):       Stack.push(item), Stack.pop(), Stack.isEmpty()
Implementation (how):   Could use an array with a top pointer,
                        or a linked list with a head pointer —
                        the calling code cannot tell the difference.

Common Exam Mistakes

1. Using the wrong index base

AQA pseudocode is 1-indexed; Python is 0-indexed. Accessing scores[0] in AQA pseudocode is typically out of bounds. Be explicit about which convention you are using in exam answers.

2. Declaring an array too small by one

If you need to store 10 items, declare DECLARE arr[10] — not DECLARE arr[9]. Off-by-one errors here produce index-out-of-bounds errors at runtime.

3. Not closing files after use

Forgetting CLOSEFILE may leave data unwritten (buffered but not flushed to disk) or prevent other processes from accessing the file.

4. Conflating an ADT with its implementation

A stack is an ADT — it could be implemented using an array or a linked list. Describing a stack as "an array" in an exam answer conflates the abstraction with one particular implementation.

Key terms

Array
A data structure that stores a fixed number of elements of the same data type in contiguous memory locations.
Index
An integer that specifies the position of an element within an array.
Two-dimensional array
An array that stores data in rows and columns, accessed with two indices as array[row][column].
Sequential access
Access where data must be read from the beginning in order, so reaching record 50 requires reading records 1 through 49 first.
Random access
Access where any record can be reached directly by computing its position (address).
Abstract data type (ADT)
A data structure defined in terms of the operations it supports, without specifying how it is implemented internally.
Stack
An ADT with push, pop, peek, and isEmpty operations whose defining property is LIFO (last in, first out).
Queue
An ADT with enqueue, dequeue, and isEmpty operations whose defining property is FIFO (first in, first out).

Frequently asked questions

An abstract data type (ADT) defines a data structure by the operations it supports, while the implementation specifies how those operations are carried out. Code that uses an ADT depends only on its interface, so the implementation can change (e.g. array-based to linked-list-based) without affecting calling code.

AQA pseudocode uses 1-based indexing by convention, so the first element is at index 1. Languages such as Python, Java, and C++ use 0-based indexing, so accessing scores[0] in AQA pseudocode is typically out of bounds.

Files must be closed after use because unclosed files can cause data loss when buffered data is not flushed to disk, or prevent other programs or processes from accessing the file. AQA pseudocode uses CLOSEFILE for this.

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Prev

Object-Oriented Programming

Next

Stacks and Queues

Related lessons

9 min

Lesson

Stacks and Queues

A-Level Computer Science · AQA 7517

2 months ago

7 min

5 min

Lesson

Graphs

A-Level Computer Science · AQA 7517

1 month ago

8 min

Lesson

Binary Search Trees

A-Level Computer Science · AQA 7517

1 month ago

Top students don’t revise more. They revise what counts.

Start revising free

Free to start. No card needed.