Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).

Knowledge/A Level/H446/01 Computer systems/Data Structures/How to create, traverse, add data to and remove…

How to create, traverse, add data to and remove data from these data structures

How to create, traverse, add data to and remove data from the data structures mentioned above. (NB this can be either using arrays and procedural programming or an object-oriented approach)

1.4.2 Data Structures

Practise exam questions

Data Structures — Note 3 of 3

Candidates should have experience of implementing these structures in a variety of contexts, for example through a procedural program, through a different data structure and through an object-oriented approach. Candidates need to be able to read, trace and write code to implement features of these data structures. (Again we would recommend a general understanding backed up with practice implementing them, rather than trying to memorise code patterns).

What you need to know

You need to be able to read, trace and write code that creates and manipulates linked lists, stacks, queues, trees, graphs and hash tables. This can be done procedurally using arrays and pointers, or using an object-oriented approach.

What to know

  • Stack using an array: a top pointer tracks the last item. Push: check for overflow, increment top, store the item. Pop: check for underflow, read the item at top, decrement top.
  • Queue using an array: front and rear pointers. Enqueue: check the queue is not full, move rear, store the item. Dequeue: check it is not empty, read the item at front, move front. In a circular queue, pointers wrap using MOD.
  • Linked list traversal: start at the start pointer (not automatically index 0) and follow each node's next pointer until it is null. Use a while loop: you don't know how many nodes there are, and their array order needn't match the list order.
  • Linked list insertion: store the new item in the node the free pointer gives, and move the free pointer on to the next free node. Then find the node before the insertion point, set the new node's pointer to that node's next, then point that node at the new node. To insert at the HEAD there is no node before: set the new node's pointer to the node the start pointer gives, then point the start pointer at the new node. Existing items never move, so don't shift them along the array.
  • Linked list deletion: make the previous node point to the node after the one being removed; the removed node can be returned to a free list.
  • Binary search tree insertion: start at the root; go left if the new value is smaller, right if larger, until an empty position is found. Searching follows the same single path until the value is found or a null pointer shows it isn't there. To delete a leaf, make its parent's pointer null.
  • Hash table: apply the hash function to the key to find the index; on a collision, use the agreed method (e.g. check the next free slot).
  • Graph as an adjacency matrix: a 2D array with one row and one column per vertex. adj[a,b] holds the edge from vertex a to vertex b: 1 or 0 if unweighted, or the weight, with a no-edge value the question states (e.g. -1 or ∞). Add an edge by setting the cell; remove it by resetting the cell to the no-edge value. In an undirected graph, change BOTH adj[a,b] and adj[b,a]. To add a vertex to a full static array, copy it into a larger array, keeping every edge, and fill the new row and column with the no-edge value.
  • Graph as an adjacency list: each vertex has a list of its neighbours (each with its weight in a weighted graph), e.g. a dictionary of lists. Add an edge by appending the neighbour; remove one by deleting it from the list. In an undirected graph, change both vertices' lists. Add a vertex as a new entry with an empty list. Remove a vertex by deleting its entry AND removing it from every other list. To find a vertex's neighbours, read its list; in a matrix, scan its row.
  • Traversing a tree or graph: depth-first (using a stack or recursion) and breadth-first (using a queue), marking nodes as visited. Graph search algorithms built on these, such as finding the shortest path, are covered in 2.3.1.

Code examples

Stack with an array (OCR pseudocode style)
text
array stack[10]
top = -1

procedure push(item)
    if top == 9 then
        print("Stack overflow")
    else
        top = top + 1
        stack[top] = item
    endif
endprocedure

function pop()
    if top == -1 then
        print("Stack underflow")
        return null
    else
        item = stack[top]
        top = top - 1
        return item
    endif
endfunction
Circular queue in Python
python
SIZE = 5
queue = [None] * SIZE
front, rear, count = 0, -1, 0

def enqueue(item):
    global rear, count
    if count == SIZE:
        print("Queue full")
        return
    rear = (rear + 1) % SIZE      # wrap around
    queue[rear] = item
    count += 1

def dequeue():
    global front, count
    if count == 0:
        print("Queue empty")
        return None
    item = queue[front]
    front = (front + 1) % SIZE    # wrap around
    count -= 1
    return item
Linked list traversal and insertion with an object-oriented approach
python
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

def traverse(start):
    current = start
    while current is not None:
        print(current.data)
        current = current.next

def insert_after(node, data):
    new_node = Node(data)
    new_node.next = node.next     # new node points to the old next
    node.next = new_node          # previous node points to the new node
Graph as an adjacency matrix (OCR pseudocode style)
text
// Undirected, weighted graph: vertices A to D are indexes 0 to 3
// -1 means no edge
array adj[4,4]
for r = 0 to 3
    for c = 0 to 3
        adj[r,c] = -1
    next c
next r

procedure addEdge(a, b, weight)
    adj[a,b] = weight
    adj[b,a] = weight      // undirected: both directions
endprocedure

procedure removeEdge(a, b)
    adj[a,b] = -1
    adj[b,a] = -1
endprocedure

procedure printNeighbours(v)
    for c = 0 to 3
        if adj[v,c] != -1 then
            print(c)
        endif
    next c
endprocedure

addEdge(1, 3, 4)   // add B-D with weight 4

Exam technique

  • Tip:Use the pointer convention the question gives. If the pointer marks the next free space, push stores THEN increments, and pop decrements THEN reads: the reverse of this entry's stack code. Put return last: nothing after it runs.
  • Mistake:Using push and pop for a queue. A queue uses enqueue (at the rear) and dequeue (at the front). Shifting every item forward on a dequeue works but is inefficient: moving the front pointer on is the better answer.
  • Mistake:Saying a -1 pointer in a tree array marks a leaf node. One -1 only shows there is no node down that branch (a null pointer). A leaf is a node with -1 in BOTH its Left and Right pointers.
  • Mistake:Storing an undirected edge only once, or removing a vertex from an adjacency list by deleting only its own entry. An undirected edge goes in both cells (or both lists), and a removed vertex must also come out of every list that names it, or edges to a vertex that no longer exists remain.
  • Tip:When choosing between a matrix and a list for a given graph, link your answer to that graph. Many edges (dense), or frequent checks for one edge, suit a matrix: checking an edge is one step. Few edges (sparse) suit a list: it stores only the edges that exist, where a matrix uses n² cells. Don't just say 'faster': say what is faster, or what memory is saved.
  • Tip:Always check for the edge cases: full and empty structures, and inserting at the start or end of a linked list. For a 'full' test, work out the last valid index from the array size. In a LINEAR queue in a 20-element array (indexes 0 to 19), with the rear pointer starting at -1 and pointing to the last item added, the queue is full when rear is 19, not 20. The stack code here does the same: top == 9 for stack[10]. A circular queue wraps round, so it needs a count, as in the queue code here.
  • Tip:General understanding is more useful than memorised code; be ready to apply these ideas to an unfamiliar scenario.

Past exam questions

  • June 2026Paper 2Q5(b)(i)3marks
  • June 2026Paper 2Q5(b)(ii)1mark
  • June 2026Paper 2Q8(a)3marks
  • June 2025Paper 2Q3(a)2marks
  • June 2025Paper 2Q7(a)3marks
  • June 2025Paper 2Q8(g)12marks
  • June 2024Paper 1Q8(b)(i)4marks
  • June 2024Paper 1Q8(b)(ii)4marks
  • June 2024Paper 2Q4(b)2marks
  • June 2024Paper 2Q7(b)(iv)3marks
  • June 2023Paper 1Q2(b)(i)3marks
  • June 2023Paper 1Q2(b)(ii)3marks
  • June 2023Paper 1Q2(c)(iv)3marks
  • June 2023Paper 2Q1(a)(ii)4marks
  • June 2023Paper 2Q3(c)2marks
  • June 2022Paper 2Q2(c)4marks
  • June 2022Paper 2Q8(a)(i)2marks
  • June 2022Paper 2Q8(c)(i)3marks
  • November 2021Paper 1Q7(b)(i)4marks
  • November 2020Paper 2Q5(b)5marks
  • November 2020Paper 2Q6(a)(iii)4marks
  • June 2019Paper 1Q5(b)1mark
  • June 2019Paper 1Q5(c)5marks
  • June 2019Paper 2Q2(b)(i)2marks
  • June 2019Paper 2Q2(b)(ii)3marks
  • June 2018Paper 1Q5(b)(i)2marks
  • June 2018Paper 1Q5(b)(ii)2marks
  • June 2018Paper 2Q1(a)3marks
  • June 2018Paper 2Q5(a)4marks
  • June 2017Paper 2Q2(b)(i)2marks
  • June 2017Paper 2Q2(b)(ii)3marks
  • June 2017Paper 2Q2(c)(i)1mark

Ready to test yourself?

Practise 1.4.2 questions
← Previous noteLinked list, graph, stack, queue, tree, binary search tree and hash table1.4.2 Data StructuresNext topic →Define problems using Boolean logic1.4.3 Boolean Algebra

Back to Data Structures

Data Structures

Note 3 of 3

  1. 1Arrays (up to 3 dimensions), records, lists and tuples
  2. 2Linked list, graph, stack, queue, tree, binary search tree and hash table
  3. 3How to create, traverse, add data to and remove data from these data structures
Topic overview