Study Guide

Arrays

Computer ScienceΒ· Unit 10: Data types & structuresΒ· 15 min read

1. Core Concepts & 1D Arraysβ˜…β˜…β˜†β˜†β˜†β± 5 min

πŸ“˜ Definition

One-Dimensional (1D) Array

DECLAREname[size]:DATATYPEDECLARE name[size] : DATA_TYPE

A linear collection of same-type elements stored in contiguous memory. Each element is accessed via a single index offset from the array's starting address.

Example:

An array of 10 integers to store student test scores

Unlike individual variables, arrays group related data together, making it easy to process all elements with a loop. They are the most widely used data structure in introductory programming, and appear in almost every Paper 2 programming question.

πŸ“ Worked Example

Declare a 1D array of 5 floating-point numbers called temperatures, initialize the first element to 22.5, and output the third element (zero-indexed).

  1. 1
    1. Declare the array with correct type, name and size:
  2. 2
    DECLARE temperatures[5]:REAL\text{DECLARE } temperatures[5] : \text{REAL}
  3. 3
    1. Initialize the first element at index 0:
  4. 4
    temperatures[0]=22.5temperatures[0] = 22.5
  5. 5
    1. The third element is at index 2, so output it:
  6. 6
    OUTPUT temperatures[2]\text{OUTPUT } temperatures[2]

Exam tip:

Always confirm the indexing convention stated in the question before writing your code.

2. Two-Dimensional (2D) Arraysβ˜…β˜…β˜…β˜†β˜†β± 5 min

πŸ“˜ Definition

Two-Dimensional (2D) Array

DECLAREname[rows][columns]:DATATYPEDECLARE name[rows][columns] : DATA_TYPE

An array of arrays, structured as a grid with rows and columns. Each element is accessed using two indices: the first for the row, the second for the column.

Example:

A 3x3 grid for a tic-tac-toe game board

2D arrays are commonly used to represent grids, matrices, tables, and game boards in exam questions. Paper 1 may also ask you to calculate the memory address of a 2D element for row-major or column-major order storage.

πŸ“ Worked Example

Declare a 4-row, 6-column 2D integer array called gameGrid, and set the element in the 2nd row, 5th column (zero-indexed) to 10.

  1. 1
    1. Declare the array with rows first, then columns:
  2. 2
    DECLARE gameGrid[4][6]:INTEGER\text{DECLARE } gameGrid[4][6] : \text{INTEGER}
  3. 3
    1. 2nd row = index 1, 5th column = index 4, so assign the value:
  4. 4
    gameGrid[1][4]=10gameGrid[1][4] = 10
βœ“ Quick check

Test your understanding:

  1. What index accesses the first row, first column of a zero-indexed 2D array?

    • [0][0]

    • [1][1]

    • [0][1]

    • [1][0]

    Reveal answer
    [0][0] β€”

    Correct! Zero-indexing starts counting from 0, so the first element in each dimension gets index 0.

3. Common Examined Array Operationsβ˜…β˜…β˜…β˜†β˜†β± 5 min

The most common array operations tested in exams are traversal (iterating over all elements), finding maximum/minimum values, calculating sum/average, linear search, insertion, and deletion. All of these use loops to access elements by index.

πŸ“ Worked Example

Write pseudocode to find the maximum value in a zero-indexed 1D array scores of 10 integers.

  1. 1
    1. Initialize the maximum value to the first element of the array:
  2. 2
    maxScore=scores[0]maxScore = scores[0]
  3. 3
    1. Traverse the array starting from the second element (index 1):
  4. 4
    FOR i=1 TO 9\text{FOR } i = 1 \text{ TO } 9
  5. 5
    IF scores[i]>maxScore THEN\quad \text{IF } scores[i] > maxScore \text{ THEN}
  6. 6
    maxScore=scores[i]\quad \quad maxScore = scores[i]
  7. 7
    END IF\quad \text{END IF}
  8. 8
    END FOR\text{END FOR}
  9. 9
    1. After the loop completes, maxScore holds the maximum value of the array.

4. Common Pitfalls

Wrong move:

Off-by-one errors when looping: looping from 1 to 10 for a 10-element zero-indexed array.

Why:

The last valid index of a 10-element zero-indexed array is 9, so accessing index 10 is out of bounds.

Correct move:

Loop from 0 to n-1 for zero-indexed arrays of size n, matching the convention given in the question.

Wrong move:

Swapping row and column indices when declaring or accessing 2D arrays.

Why:

CIE pseudocode uses [rows][columns] convention by default, so swapping leads to incorrect size declarations and wrong element access.

Correct move:

Always write the row index/size first, followed by the column index/size.

Wrong move:

Assuming arrays are dynamic and can grow beyond their declared size.

Why:

Static arrays (the standard array taught in 9618) are fixed-size at declaration. They cannot be resized during program execution.

Correct move:

Declare an array large enough to hold all possible input values at the start of your program.

Wrong move:

Assuming all arrays are zero-indexed without checking the question.

Why:

Some exam questions explicitly use one-indexing for simplicity, so using zero-indexing leads to wrong results.

Correct move:

Always read the question statement to confirm the indexing convention before writing any code.

5. Quick Reference Cheatsheet

Concept

Key Fact

Pseudocode Example

1D Array Declaration

Fixed size, same type

DECLARE scores[10] : INTEGER

2D Array Declaration

Rows first, then columns

DECLARE grid[3][3] : INTEGER

Zero-index 1D

Indices 0 to n-1 for size n

FOR i ← 0 TO 9

One-index 1D

Indices 1 to n for size n

FOR i ← 1 TO 10

2D Element Access

Row index first, column second

grid[row][col]

Find Maximum Value

Start with first element, iterate

max = arr[0] IF arr[i] > max THEN max = arr[i]

6. Frequently Asked

Are arrays zero-indexed or one-indexed in CIE 9618 exams?

Most pseudocode used in CIE 9618 is zero-indexed by default, but you must always check the question statement, as some questions explicitly use one-indexing. Never assume without confirming.

When this came up on past exams

AI-estimated based on syllabus patterns β€” cross-check with official past papers for accuracy. Use only as revision-focus signals.

  • 2022 Β· 1

    Array memory address calculation

  • 2023 Β· 2

    2D array grid manipulation

  • 2021 Β· 1

    Array traversal for maximum value

Going deeper

What's Next

Arrays are the foundation for almost all more complex data structures you will learn in A-Level Computer Science. Understanding how arrays store data in contiguous memory is critical for understanding how linked lists, stacks, queues, and hash tables work, as all of these often use arrays as an underlying storage layer. Mastering array operations like traversal and search also builds the core algorithmic thinking you need for solving complex programming problems in Paper 2. Next, you will learn to combine different data types using records, before moving on to more advanced algorithms and dynamic data structures.