Use the technical terms associated with arrays

10.2 Arrays – Technical Terminology (Cambridge AS & A‑Level 9618)

1. Syllabus Mapping (What is Covered Here?)

Syllabus AreaPresent in These NotesWhat to Add Elsewhere
10.1 Data Types & RecordsBrief reminder added (see §2)Full list of primitive types and record structures (topic 10.1) – see the “Data Types” hand‑out.
10.2 ArraysDefinition, terminology, static vs dynamic, 1‑D/2‑D, bounds, address formulas, initialisation (including literals), lower‑bound handling.None.
10.3 FilesLink added (see §8)Full file‑handling pseudocode and examples.
10.4 Abstract Data Types (ADT)Stack/queue implementation using arrays (see §9)Detailed ADT specifications and other implementations.
12.1 Program Development Life‑CycleNote on where array design fits (see §7)Full PDLC diagram and description.
12.2 Program Design (Structure charts, state‑transition diagrams)Simple structure‑chart example (see §7)Comprehensive design techniques.
12.3 Testing & MaintenanceBoundary‑value testing advice (see §10)Full testing strategy.
A‑Level extensions (Topics 13‑20)“Next steps” box (see §11)Separate A‑Level notes on recursion, exception handling, etc.

2. Quick Reminder – Primitive Data Types (Topic 10.1)

  • INTEGER – whole numbers, e.g. int in Java.
  • REAL – floating‑point numbers, e.g. float/double.
  • CHAR – single character.
  • STRING – sequence of characters.
  • BOOLEANtrue/false.
  • DATE – calendar date (rarely used in array examples).

All elements of an array must be of the same primitive type (or the same user‑defined record type).

3. Core Terminology

  • Array – an ordered collection of same‑type elements stored in contiguous memory locations.
  • Element – a single value located at a particular position.
  • Index / Subscript – integer used to locate an element. Most languages use zero‑based indexing (first element = 0).
  • Lower bound – the smallest legal index (usually 0, but some languages allow other values).
  • Upper bound – the largest legal index, equal to length − 1 for zero‑based arrays.
  • Length / Size – total number of elements the array can hold.
  • Dimension – number of indices required to address an element (1‑D, 2‑D, …).
  • Static array – size fixed at compile time; cannot be changed at run time.
  • Dynamic array – size determined at run time or can be altered (e.g. new int[n], ArrayList, Python list).
  • Row‑major order – rows stored consecutively (used by Java, C, Python).
  • Column‑major order – columns stored consecutively (used by Fortran).
  • Declaration – statement that defines an array’s type and size.
  • Initialisation – assigning values at declaration or later; may use literals.
  • Access / Retrieval – reading a value using its index.
  • Assignment / Update – writing a new value using its index.
  • Iteration – processing each element, usually with a for loop.
  • Bounds checking – run‑time test that an index lies within legal limits.
  • Out‑of‑bounds error – exception or undefined behaviour caused by an illegal index.

4. Declaration & Initialisation (including literals)

4.1 Pseudocode (Paper 2)

DECLARE scores[5] OF INTEGER          // length = 5, lower bound = 0

SET scores[0] ← 0

SET scores[1] ← 0

SET scores[2] ← 0

SET scores[3] ← 0

SET scores[4] ← 0 // explicit initialisation

4.2 Java

// static size, default initialisation (0 for int)

int[] scores = new int[5];

// static size with literal initialisation

int[] marks = {78, 85, 92, 67, 81};

// dynamic size (run‑time value)

int n = Integer.parseInt(input());

int[] data = new int[n];

// resizable collection (often used in A‑Level questions)

ArrayList<Integer> list = new ArrayList<>();

4.3 Python

# list of length n, initially all zeros

scores = [0] * n

# literal initialisation

marks = [78, 85, 92, 67, 81]

# dynamic growth

marks.append(90)

5. Memory Layout & Address‑Calculation

5.1 One‑Dimensional (Row‑major)

For element i (zero‑based) in an array with element size s bytes and base address B:

\[

\text{address}(i) = B + i \times s

\]

5.2 Two‑Dimensional (Row‑major)

For an array A with R rows, C columns, element size s, and base address B:

\[

\text{address}(i,j) = B + (i \times C + j) \times s

\]

where i = row index, j = column index (both zero‑based).

5.3 Two‑Dimensional (Column‑major – Fortran style)

\[

\text{address}(i,j) = B + (j \times R + i) \times s

\]

5.4 Worked Example (Row‑major)

Array A is a 4 × 5 integer matrix, each integer occupies 4 bytes, base address 0x1000.

  1. Parameters: R = 4, C = 5, s = 4, B = 0x1000.
  2. Address of A[2][3]:

    \[

    \text{offset} = (2 \times 5 + 3) \times 4 = 13 \times 4 = 52\text{ bytes}

    \]

    \[

    \text{address} = 0x1000 + 52 = 0x1034

    \]

  3. Result: A[2][3] resides at memory address 0x1034.

6. Bounds‑Checking & Out‑of‑Bounds Errors

// Java example – illegal access

int[] ages = {12, 15, 17, 19, 21}; // length = 5

int value = ages[5]; // index 5 is out of bounds

Running the fragment throws ArrayIndexOutOfBoundsException because the valid indices are 0 ≤ index < 5. In an exam answer you should state:

  • “The program attempts to access ages[5], which lies outside the valid bounds (0 ≤ index < 5). This causes an out‑of‑bounds error.”

7. Where Arrays Fit in the Development Process

  • Analysis – decide whether the data set has a known fixed size (static) or a size that varies (dynamic).
  • Design – create a structure‑chart showing an “Array‑Processing” module that may call “Read‑File”, “Sort”, “Search”, etc.
  • Implementation – write declaration, initialise, and use the array as described above.
  • Testing – apply boundary‑value testing (first index, last index, just‑outside both ends) and check for off‑by‑one errors.
  • Maintenance – if requirements change, revisit the choice of static vs dynamic and adjust the size handling.

8. Connection to Files (Topic 10.3)

Arrays are often used as buffers when reading from or writing to files. A typical pattern is:

// Pseudocode

DECLARE buffer[100] OF INTEGER

OPEN file FOR READ

WHILE NOT EOF(file) DO

READ nextValue FROM file

IF index < 100 THEN

SET buffer[index] ← nextValue

INCREMENT index

ENDIF

ENDWHILE

CLOSE file

See the “Files” hand‑out for full syntax and error handling.

9. Simple ADT Implementations Using Arrays (Topic 10.4)

9.1 Stack (LIFO) using a 1‑D array

DECLARE stack[SIZE] OF INTEGER

DECLARE top ← -1 // empty stack

PROCEDURE push(x)

IF top = SIZE‑1 THEN

OUTPUT "Stack overflow"

ELSE

top ← top + 1

SET stack[top] ← x

ENDIF

ENDPROCEDURE

PROCEDURE pop() RETURNS INTEGER

IF top = -1 THEN

OUTPUT "Stack underflow"

RETURN -1 // sentinel value

ELSE

SET result ← stack[top]

top ← top - 1

RETURN result

ENDIF

ENDPROCEDURE

9.2 Queue (FIFO) using a 1‑D array

DECLARE queue[SIZE] OF INTEGER

DECLARE front ← 0, rear ← -1, count ← 0

PROCEDURE enqueue(x)

IF count = SIZE THEN

OUTPUT "Queue full"

ELSE

rear ← (rear + 1) MOD SIZE

SET queue[rear] ← x

count ← count + 1

ENDIF

ENDPROCEDURE

PROCEDURE dequeue() RETURNS INTEGER

IF count = 0 THEN

OUTPUT "Queue empty"

RETURN -1

ELSE

SET result ← queue[front]

front ← (front + 1) MOD SIZE

count ← count - 1

RETURN result

ENDIF

ENDPROCEDURE

These examples illustrate how arrays underpin many abstract data types examined in the syllabus.

10. Testing Arrays – Typical Exam‑Style Checks

  • Boundary‑value test: verify behaviour at index 0 and index length‑1.
  • Just‑outside test: attempt to access -1 and length – should trigger an out‑of‑bounds error.
  • Off‑by‑one errors: common when loops use i <= length instead of i < length.
  • Initialisation check: confirm that default values (e.g., 0 for int) are as expected unless overridden.

11. Summary Table of Terms

TermExam‑relevant Definition
ArrayOrdered collection of same‑type elements stored contiguously.
ElementSingle value located at a particular index.
Index / SubscriptInteger used to locate an element; first index is usually 0.
Lower boundSmallest legal index (often 0, but may differ in some languages).
Upper boundLargest legal index, equal to length − 1 for zero‑based arrays.
Length / SizeNumber of elements an array can contain.
DimensionNumber of indices required to address an element (1‑D, 2‑D, …).
Static arraySize fixed at compile time; cannot be resized later.
Dynamic arraySize determined or altered at run time (e.g., new int[n], ArrayList, Python list).
Row‑major orderRows stored consecutively in memory.
Column‑major orderColumns stored consecutively in memory.
DeclarationStatement that defines an array’s type and size.
InitialisationAssigning initial values, either at declaration (literals) or later.
Access / RetrievalReading a value using its index.
Assignment / UpdateWriting a new value using its index.
IterationProcessing each element, typically with a for loop.
Bounds checkingRun‑time test that an index lies within valid limits.
Out‑of‑bounds errorException or undefined behaviour caused by an illegal index.

12. Suggested Diagram (to be added to slides/hand‑outs)

One‑dimensional array visualising indices 0 … n‑1 and contiguous memory cells.

13. Next Steps for A‑Level (Topics 13‑20)

  • Multidimensional arrays for image processing and matrix maths (Topic 13).
  • Recursion (e.g., binary search on a sorted array) – builds on array indexing (Topic 14).
  • Exception handling – formal way to deal with out‑of‑bounds errors (Topic 15).
  • File organisation – using arrays as buffers for record‑oriented files (Topic 16).
  • Advanced ADTs (priority queues, heaps) – array‑based implementations (Topic 17).
  • Virtual machines & memory models – deeper look at how row‑major/column‑major affect performance (Topic 18).

These notes cover the AS‑Level requirements; consult the A‑Level extensions for deeper exploration.