Revisionโ€บOCR A Levelโ€บData Types, Data Structures & Algorithms
OCR A Level H446 ยท Topic 1.4

Data Types, Data Structures & Algorithms

60 practice questions

Practice Questions

60 questions

How do you access element at row 2, column 3 of a 2D array?

easy

A program stores a student's name, age and exam scores together as a single unit. Which data structure is this an example of?

easy

Explain why a 2D array might be used to represent a chessboard, and how a specific square would be accessed.

medium

Which of the following is NOT typically considered a primitive data type?

easy

Explain how a negative integer is typically represented in binary using two's complement.

medium

A character (e.g. a single letter) is stored in a computer as:

easy

Explain how a Boolean data type is stored, and why this is not always the most efficient use of memory.

medium

Real (floating-point) numbers are typically stored in a computer using:

medium

Explain the key difference between how an integer and a real (floating-point) number are stored in binary, and why this matters for a programmer.

medium

What is the range of values that can be represented by an unsigned 8-bit binary number?

easy

What data structure uses LIFO ordering?

easy

Queue [A,B,C]. Dequeue once, enqueue D. Result?

medium

What is a stack overflow in the context of recursion?

medium

What does a priority queue do differently from a regular queue?

medium

A stack is implemented using an array. What operation adds an item?

easy

Explain what is meant by an abstract data type (ADT).

medium

Which data structure operates on a First-In-First-Out (FIFO) basis?

easy

Describe how a stack could be used to check whether a string of brackets, e.g. "({[]})", is correctly balanced.

hard

A stack is empty. The following operations are performed in order: push(5), push(8), peek(), pop(), push(3), pop(). State the value returned by each peek() and pop() operation, and the final contents of the stack.

medium

What is the main purpose of a 'circular queue' (compared to a standard linear queue implemented with an array)?

medium

Explain static vs dynamic data structures with one advantage each.

medium

What is the difference between a singly and doubly linked list?

medium

Describe post-order traversal of a binary tree.

medium

Give one advantage each of adjacency matrix vs adjacency list for graphs.

hard

What is the difference between a binary tree and a binary search tree?

medium

Explain why a linked list can be more efficient than an array for inserting an item in the middle of a large collection.

medium

Explain the difference between a static data structure and a dynamic data structure, giving an example of each.

medium

A binary search tree is used to store integers. Which traversal would visit the nodes in ascending numerical order?

medium

Explain why choosing an appropriate data structure is important when designing a program, using a real-world example.

medium

Describe a real-world use case for a graph data structure, explaining what the nodes and edges represent.

medium

What is a hash table and what is a collision?

medium

What is the worst-case time complexity of searching for an item in a hash table?

hard

What is a 'hash function' used for in a hash table?

easy

Explain how 'linear probing' resolves a collision in a hash table.

medium

In a hash table that uses 'chaining' to resolve collisions, each array index stores:

medium

Explain why it is important for a hash function to distribute keys as evenly as possible across the available indices.

medium

The 'load factor' of a hash table is best described as:

medium

Explain the trade-off involved in choosing the size of the underlying array for a hash table.

medium

Compared to searching an unsorted linked list of n items for a particular value, searching a well-implemented hash table for the same value is generally:

hard

Explain what is meant by 'rehashing' a hash table, and when it might be triggered.

hard

What is the difference between depth-first and breadth-first graph traversal?

hard

A graph has the following adjacency information: A connects to B and C; B connects to A and D; C connects to A; D connects to B. Starting at A, list the order in which nodes are visited using breadth-first search (BFS).

medium

Breadth-first search (BFS) typically uses which data structure to keep track of which nodes to visit next?

easy

Using the same graph as before (A connects to B and C; B connects to A and D; C connects to A; D connects to B), list one possible order in which nodes are visited using depth-first search (DFS) starting at A.

medium

Depth-first search (DFS) typically uses which data structure (or technique) to keep track of which nodes to visit next?

easy

Describe, in outline, how Dijkstra's algorithm finds the shortest path from a start node to all other nodes in a weighted graph.

hard

Dijkstra's algorithm, as commonly taught, requires that all edge weights in the graph are:

medium

A graph has nodes A, B and C. The edge A-B has weight 4, the edge A-C has weight 1, and the edge C-B has weight 1. Using Dijkstra's algorithm starting at A, find the shortest distance from A to B, showing your reasoning.

hard

Breadth-first search (BFS) is often used to find the shortest path between two nodes in:

medium

Explain a situation where breadth-first search (BFS) would be a more appropriate choice than depth-first search (DFS), and vice versa.

medium

What is the time complexity of searching a balanced BST?

medium

What is the worst-case time complexity of bubble sort?

medium

Describe how merge sort works and state its time complexity.

hard

Which sorting algorithm repeatedly selects a pivot value and partitions the list into elements smaller and larger than the pivot?

medium

Which of the following operations on an array typically has a time complexity of O(1)?

easy

Explain the difference between O(n) and O(nยฒ) time complexity, giving an example algorithm for each.

medium

What is the time complexity of binary search on a sorted array of n elements?

medium

Explain why an algorithm with O(log n) time complexity is considered very efficient, even for large values of n.

medium

Which of the following lists time complexities in order from most efficient (fastest growth) to least efficient (slowest/worst growth) for large n?

medium

Explain what Big O notation describes about an algorithm, and why two algorithms with the same Big O complexity might still perform differently in practice.

hard

Revision Notes

Data Types & Number Representation

โญ Exam tip: Two's complement, binary arithmetic and floating-point normalisation are calculation questions โ€” practise converting BOTH ways and always show working for method marks.
Primitive data types:Integer (whole numbers), real/float (with a fractional part), Boolean (True/False), character (a single symbol) and string (a sequence of characters). The type chosen fixes the operations allowed and the memory used.
Two's complement (8-bit)
Represent -45:
  +45      = 0010 1101
  invert   = 1101 0010
  add 1    = 1101 0011   โ†’ -45
Check place values (MSB is NEGATIVE):
  1101 0011 = -128 +64 +16 +2 +1 = -45  โœ“
8-bit range: -128 (1000 0000) to +127 (0111 1111)
Binary arithmetic & overflow
Add  0100 1111 (79)
   + 0011 0001 (49)
   = 1000 0000 (-128 in 2's complement!)
The true answer 128 does not fit in 8 bits, so the
sign bit flips โ†’ OVERFLOW. Detect: adding two
positives gives a negative (or two negatives give a
positive).
Floating point representation
Number = mantissa x 2^exponent, both in two's complement.
NORMALISED form: mantissa starts 0.1โ€ฆ (positive) or
1.0โ€ฆ (negative) to maximise precision.

Mantissa 0.1011, exponent 0011 (=3):
  move binary point right 3 โ†’ 0101.1 = 5.5

Trade-off: more mantissa bits = more PRECISION;
more exponent bits = greater RANGE.
Hex, shifts and masks
Hex = binary in groups of 4 bits:
  1011 0110 = B6
Logical left shift by 1 = x2:
  0001 0110 (22) << 1 = 0010 1100 (44)
Right shift by 1 = รท2 (integer):
  0010 1100 (44) >> 1 = 0001 0110 (22)
AND mask to test/clear bits:
  1011 0110 AND 0000 1111 = 0000 0110 (low nibble)
Character sets:ASCII uses 7 bits (128 characters) โ€” fine for English but cannot represent other scripts. Unicode (UTF-8/16/32) uses more bits to cover every language plus symbols and emoji, with UTF-8 being backwards-compatible with ASCII for the first 128 codes.
โš ๏ธ Common mistake: The most common two's-complement error is forgetting that the most significant bit has a NEGATIVE place value (โˆ’128 for 8 bits). Always write the place values with the leftmost one negative before adding.

Data Structures (Stacks, Queues, Lists, Trees, Graphs)

โญ Exam tip: You must be able to WRITE the push/pop and enqueue/dequeue algorithms with overflow/underflow checks, and trace tree traversals.
Abstract Data Type (ADT):A data type defined by its operations and behaviour, not its implementation โ€” the user knows WHAT operations exist and what they do, not HOW they are coded. Examples: stack, queue, list, tree, graph, hash table, dictionary.
Stack (LIFO) with overflow/underflow
push(item):
  IF top = maxSize - 1 THEN
    REPORT "stack overflow"
  ELSE
    top โ† top + 1
    stack[top] โ† item
pop():
  IF top = -1 THEN
    REPORT "stack underflow"
  ELSE
    item โ† stack[top]
    top โ† top - 1
    RETURN item
Uses: the call stack, undo, backtracking, evaluating
expressions, converting infix โ†’ postfix.
Circular queue (FIFO)
enqueue(item):
  IF count = size THEN REPORT "queue full"
  rear โ† (rear + 1) MOD size
  queue[rear] โ† item ; count โ† count + 1
dequeue():
  IF count = 0 THEN REPORT "queue empty"
  item โ† queue[front]
  front โ† (front + 1) MOD size ; count โ† count - 1
  RETURN item
MOD wraps the pointers so freed slots are reused โ€”
otherwise the queue "walks off" the end of the array.
Linked list:A dynamic sequence of nodes, each holding data and a pointer to the next node (a null pointer marks the end). Insertion/deletion is O(1) once the position is found (just repoint pointers), and it grows/shrinks at run time โ€” but there is no random access (you must traverse from the head) and pointers use extra memory.
Graphs:A set of vertices (nodes) connected by edges, which may be directed and/or weighted. Stored as an <strong>adjacency matrix</strong> (Vร—V grid; O(Vยฒ) space, O(1) edge lookup โ€” good for dense graphs) or an <strong>adjacency list</strong> (each vertex lists its neighbours; O(V+E) space โ€” good for sparse graphs). Model real networks: roads, social links, the web.
Binary search tree traversals
Tree:        8
           /   \
          3    10
         / \     \
        1   6    14
In-order  (L,Root,R): 1 3 6 8 10 14  โ† SORTED order
Pre-order (Root,L,R): 8 3 1 6 10 14  โ† copy/serialise
Post-order(L,R,Root): 1 6 3 14 10 8  โ† delete/evaluate
Hash table:Maps keys to values by passing the key through a hash function to compute an index โ€” average O(1) insert/search. A collision (two keys hash to one index) is resolved by chaining (store a list at each slot) or open addressing (probe to the next free slot). A high load factor increases collisions, so the table is resized/rehashed.
๐Ÿ’ก When asked to choose a structure: a stack for anything LIFO (undo, function calls, backtracking); a queue for FIFO (print spooler, buffering); a hash table when fast key lookup matters; a BST when you need sorted order AND fast search.

Boolean Algebra & Logic

โญ Exam tip: Simplification questions want the working shown line by line, naming the law used at each step โ€” the final answer alone rarely gets full marks.
GateNotationOutput is 1 whenโ€ฆ
ANDA.Bboth inputs are 1
ORA+Bat least one input is 1
NOTNOT Athe input is 0
XORA โŠ• Bthe inputs are different
NANDNOT(A.B)NOT both inputs are 1
NORNOT(A+B)both inputs are 0
LawRule
CommutativeA.B = B.A ; A+B = B+A
Associative(A.B).C = A.(B.C)
DistributiveA.(B+C) = A.B + A.C
AbsorptionA + A.B = A ; A.(A+B) = A
IdentityA.1 = A ; A+0 = A
NullA.0 = 0 ; A+1 = 1
ComplementA.(NOT A) = 0 ; A+(NOT A) = 1
Double negationNOT(NOT A) = A
De Morgan's laws
NOT(A AND B) = (NOT A) OR (NOT B)
NOT(A OR B)  = (NOT A) AND (NOT B)
Method: "break the bar and swap the operator."

Use them to push NOTs inward and to convert
between AND/OR forms (useful for NAND/NOR circuits).
Simplification (show every step)
Simplify:  A.B + A.(NOT B) + (NOT A).B
= A.(B + NOT B) + (NOT A).B   [distributive]
= A.(1)          + (NOT A).B   [complement]
= A             + (NOT A).B    [identity]
= A + B                        [absorption variant]
Final: A + B
Adders:A half adder adds two single bits, outputting SUM (A XOR B) and CARRY (A AND B). A full adder also takes a carry-in, so full adders can be chained to add multi-bit binary numbers โ€” the carry-out of each bit feeds the carry-in of the next.
D-type flip-flop:An edge-triggered circuit that stores one bit: on the rising edge of the clock it copies input D to its output Q (and holds it until the next edge). Flip-flops are the building blocks of registers and memory, and synchronise data to the clock.
โš ๏ธ Common mistake: De Morgan slip: students change the operator but forget to negate EACH variable (or vice-versa). NOT(A.B) is (NOT A)+(NOT B) โ€” both the operator AND each term change.