EuraStudy
A data structure is a way of organising data so that the operations a program needs are efficient. This chapter separates the abstract data type - the operations promised - from its concrete implementation, then builds the core structures: arrays and records, the last-in-first-out stack and the first-in-first-out queue, the pointer-linked list, graphs and trees, and the hash table that gives near-constant-time lookup. Choosing the right structure is one of the most heavily assessed design skills in the whole A-Level.
5 sections~19 min reading time3 competenciesLevel Foundation 1 · Standard 2 · Advanced 2
basic level
AS-Level expects arrays, records, stacks and queues and their operations, plus the idea of an abstract data type.
higher level
The full A-Level adds linked lists, graphs (with adjacency matrix and list representation), trees including binary trees, and hash tables with collision resolution.
Reading depth: In depth
Text size: Standard
Array element address
Because elements are equal-sized and contiguous, any index is reached in constant time - the array's key advantage.
A 2-D array grid has 4 columns and is stored row by row (row-major). If element grid[0][0] is at address 200 and each element occupies 4 bytes, find the address of grid[2][1].
In row-major order element has linear index .
Add the offset to the base: .
Result: grid[2][1] is at address 236 - the same constant-time arithmetic the hardware uses for every array access.
Typical mistakes
Active revision
A program stores 30 students, each with an id (integer), name (string) and average mark (real). Describe the data structure you would use, give the type of one element, and state the index of the tenth student in a zero-indexed array.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education) · AQA A-level Computer Science 7517 specification (AQA)
A circular queue
Circular queue advance
Modulo the capacity wraps the pointer from the last cell back to the first, reusing freed space.
A stack is empty. Trace push(4), push(7), pop(), push(2), push(9), pop(), giving the contents (base to top) and the value returned by each pop.
Contents base-to-top: [4, 7]. The stack pointer is at 7.
Removes and returns the top, 7. Contents: [4].
Contents: [4, 2, 9].
Removes and returns the top, 9. Contents: [4, 2].
Result: The pops return 7 then 9; the stack finishes as [4, 2]. The most recently pushed item is always the first popped (LIFO).
Typical mistakes
Active revision
A circular queue has capacity 5 (indices 0-4) and is empty. Trace enqueue(A), enqueue(B), enqueue(C), dequeue(), enqueue(D), enqueue(E), enqueue(F), giving the front and rear pointers and contents after each step.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A singly linked list
A list holds 12 -> 30 -> 47 -> null. Insert 25 so the list becomes 12 -> 25 -> 30 -> 47. Describe the pointer changes in the correct order.
Allocate a new node holding 25; call it P. Its next pointer is not yet set.
Set P.next to the node holding 30 (the current successor of 12). The new node now points into the list; nothing is lost.
Set the next pointer of the node holding 12 to P. Order matters: attach P before changing 12's pointer, or the rest of the list would be orphaned.
Result: Two pointers change (P.next and 12.next); no other node moves. The list is now 12 -> 25 -> 30 -> 47 -> null.
Typical mistakes
Active revision
A singly linked list holds 12 -> 30 -> 47 -> null with head pointing at 12. Describe, in terms of pointers only, how to insert the value 25 between 12 and 30, and state how many pointers you must change.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education)
An undirected graph
The adjacency matrix of the graph
Insert the keys 5, 3, 8, 1, 4 into an empty binary search tree, in that order. Describe where each key lands.
The tree is empty, so 5 becomes the root.
3 < 5 so it goes to the left of 5; 8 > 5 so it goes to the right of 5.
1 < 5 (go left to 3), 1 < 3 so it becomes 3's left child. 4 < 5 (go left to 3), 4 > 3 so it becomes 3's right child.
Result: Root 5; left child 3 (with children 1 and 4); right child 8. An in-order traversal reads 1, 3, 4, 5, 8 - sorted order, as the BST invariant guarantees.
Typical mistakes
Active revision
Draw the adjacency matrix for the undirected graph with vertices A, B, C, D and edges A-B, A-C, B-C, C-D. Then insert the keys 5, 3, 8, 1, 4 into an initially empty binary search tree, in that order, and draw the result.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A hash table with separate chaining
Modulo hash function
Maps an integer key to an index in a table of size . Choosing prime helps spread keys evenly.
Load factor
As it approaches 1 collisions become frequent and lookups slow; the table is usually resized before then.
Insert 15, 8, 22, 4 into a table of size 7 using and separate chaining. Give each key's slot and the final chains.
; ; ; .
15 goes to slot 1. 8 collides at slot 1 and is chained after 15. 22 also hashes to 1 and is chained after 8. 4 goes to the empty slot 4.
Result: Slot 1 holds the chain 15 -> 8 -> 22; slot 4 holds 4; all other slots are empty. Looking up 22 hashes to slot 1 and scans the chain to the third node.
Typical mistakes
Active revision
Using the hash function and separate chaining, insert the keys 15, 8, 22, 1 into an empty table of size 7. State the slot each occupies and which keys share a chain.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
References & sources
Department for Education