This mini-lesson covers AQA 4.2 โ Fundamentals of data structures. Choosing the right structure is what separates a program that runs in milliseconds from one that runs for a week.
Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect โญ stars. Press Start when you're ready.
An array is a fixed-size, ordered set of elements all of the same type, accessed by index. Because every element is the same size, the address of element i is found by arithmetic โ so access is O(1), instantly, at any index.
A record groups fields of different types under one name (a row in a file or database table). A file is a collection of records held in secondary storage.
An abstract data type (ADT) is defined by its operations, not its implementation. A stack is an ADT: it promises push, pop and peek. Whether it is built on an array or a linked list is an implementation detail the user never needs to know โ that is abstraction at work.
Static vs dynamic: a static structure has its memory fixed at compile time (a plain array) โ fast, but it can overflow or waste space. A dynamic structure grows and shrinks at run time using the heap โ flexible, but with pointer overhead and a risk of running out of heap memory.
A stack is LIFO: the last item pushed is the first popped. It has a single stack pointer holding the index of the top element.
Overflow = pushing onto a full stack. Underflow = popping an empty one. Both must be tested for.
Stacks are everywhere:
A queue is FIFO: first in, first out. It needs two pointers โ front and rear.
A linear queue has a fatal flaw. Every dequeue advances front, so the used space at the low end is never reclaimed: eventually rear hits the end of the array while the front of the array sits empty.
The circular queue fixes this by wrapping the pointers round with MOD:
A separate size counter (or one deliberately wasted slot) distinguishes "full" from "empty", since in both cases front and rear can coincide.
Priority queue: items are dequeued in order of priority, not arrival. Equal priorities are served in arrival order. Used by operating-system schedulers and by Dijkstra's algorithm.
A graph is a set of vertices (nodes) joined by edges (arcs). Edges may be directed (one-way) or undirected, and weighted (carrying a cost, distance or time) or unweighted.
Two standard representations:
| Adjacency matrix | Adjacency list |
|---|---|
| An n ร n table; cell [i][j] holds the weight of the edge iโj (or 0). | For each vertex, a list of the vertices it connects to. |
| Space O(nยฒ) regardless of the number of edges. | Space O(n + e) โ only real edges are stored. |
| Testing "is i joined to j?" is O(1). | Testing that edge needs a scan of one list. |
| Best for dense graphs; convenient to program. | Best for sparse graphs โ e.g. a road network. |
Sparse means: the number of edges is far smaller than the maximum n(nโ1)/2. A road network with 10 000 junctions has perhaps 25 000 roads, not 50 million โ an adjacency matrix would be over 99.9% zeros.
A tree is a connected, undirected graph with no cycles. A rooted tree adds a designated root; every other node has exactly one parent. Nodes with no children are leaves.
In a binary search tree (BST), every node has at most two children and obeys one invariant:
That single rule makes searching a halving process. Searching, inserting and deleting are O(log n) in a balanced tree โ but if you insert already-sorted data the tree degenerates into a linked list and collapses to O(n).
Traversals โ the name tells you when the root is visited:
A hash table converts a key straight into an array index using a hashing algorithm:
No searching is needed โ the key computes its own address, so lookup, insert and delete are O(1) on average. That is the whole point.
A collision happens when two different keys hash to the same index. Two standard fixes:
As the load factor (items รท slots) rises, collisions rise. Above roughly 0.7 the table is usually rehashed into a bigger array โ every key is recomputed against the new size.
Dictionary: an ADT of <key, value> pairs, almost always implemented as a hash table. A good hash function is fast, deterministic and distributes keys uniformly. Table sizes are usually prime to spread the MOD results out.
AQA treats a vector in three equivalent ways: as a list of numbers [2, 3, โ1], as a function from an index set to the reals, and as an arrow in n-dimensional space.
Vector addition and scalar multiplication work component by component:
The dot product multiplies matching components and sums the results, giving a single number (scalar):
A convex combination of a and b is ฮฑa + ฮฒb where ฮฑ, ฮฒ โฅ 0 and ฮฑ + ฮฒ = 1. Geometrically it lands somewhere on the straight line between the two vectors.
Why a computer scientist cares: the dot product measures similarity. Machine-learning models, search engines and recommender systems compare documents or images by turning them into vectors and taking dot products.
Tap a use case, then tap the structure it needs.
Tap an item on the left, then its partner on the right.
Arrays & records: array = same type, indexed, O(1) access; record = mixed-type fields
Stack: LIFO ยท push/pop/peek ยท overflow & underflow ยท call stack, undo, RPN, DFS
Queue: FIFO ยท front & rear ยท circular queue wraps with MOD ยท priority queue serves by priority
Graph: adjacency matrix O(nยฒ) for dense; adjacency list O(n + e) for sparse
Tree / BST: left < node < right ยท O(log n) balanced, O(n) degenerate ยท pre / in (sorted) / post-order
Hash table: index = h(key) ยท collisions โ probing or chaining ยท rehash above ~0.7 load factor
Vector: component-wise add and scale ยท dot product gives a scalar ยท convex combination lies between
That is the whole of AQA 4.2. Press Finish to see your score.
You've worked through Fundamentals of data structures for AQA A-level Computer Science (7517). ๐
Your stars: 0 / 0
Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.