Skip to main content
WalesComputer ScienceSyllabus dot point

How are advanced data structures built and traversed, and how do recursion and advanced algorithms operate on them?

Describe and apply advanced data structures and algorithms: linked lists, trees and their traversals, recursion, and advanced searching and sorting.

A focused answer to WJEC A-Level Computer Science Unit 3 data structures and algorithms, covering linked lists and pointers, binary tree traversals, recursion, and advanced searching and sorting with efficiency.

Generated by Claude Opus 4.813 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

WJEC wants you to go beyond the AS data structures to advanced structures and the algorithms that operate on them: linked lists built from pointers, binary tree traversals (pre-order, in-order, post-order), recursion applied to structures, and advanced searching and sorting with their efficiency. This is core A2 content in Unit 3 and is examined both by tracing operations and by explaining how pointer-based structures work.

The answer

Linked lists and pointers

The trade-off is that you cannot jump straight to the nth item as you can with an array index; you must follow the pointers from the head. Linked lists suit data that changes size often and is processed in sequence.

Binary tree traversals

The choice of traversal matters: in-order gives sorted output, pre-order is used to copy a tree or produce prefix expressions, and post-order is used to delete a tree safely or evaluate postfix expressions.

Recursion on structures

Recursion is the natural way to process trees and linked lists: the structure is defined in terms of smaller versions of itself (a tree is a node with two subtrees), so the algorithm mirrors that definition with a base case (an empty subtree or null pointer) and a recursive case.

Advanced searching and sorting

Advanced algorithms are judged by efficiency: binary search is O(log n) on sorted data, merge sort and quicksort are O(n log n), far better than the O(n squared) of bubble or insertion sort on large data.

Examples in context

Example 1. A music playlist as a linked list
A playlist where songs are inserted and removed constantly suits a linked list: adding a track in the middle just reassigns two pointers, with no need to shuffle a large array. This shows why dynamic, frequently edited sequences favour linked structures over arrays.
Example 2. In-order traversal to print a sorted index
A binary search tree storing words can be printed alphabetically simply by an in-order traversal, with no separate sort. The structure does the ordering, so the algorithm is just a recursive walk, illustrating why the choice of traversal is tied to the task.
Example 3. Why quicksort beats bubble sort at scale
Sorting a million records with quicksort takes about a million times twenty operations; bubble sort takes about a million squared. The advanced algorithm is not merely tidier but transforms an impractical task into a quick one, which is the point of studying efficiency in Unit 3.

Try this

Q1. State which tree traversal outputs the values of a binary search tree in ascending order. [1 mark]

  • Cue. In-order traversal (left, node, right).

Q2. State one advantage of a linked list over an array. [1 mark]

  • Cue. It can grow and shrink dynamically, with insertion and deletion by reassigning pointers (no shifting of other items).

Exam-style practice questions

Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

WJEC 20204 marksState the order in which the nodes of a binary tree are visited by an in-order traversal, and apply it to a tree with root 50, left child 30 and right child 70.
Show worked answer →

State the in-order rule, then apply it to the small tree.

In-order traversal visits the left subtree, then the node (root), then the right subtree, recursively.

For the tree with root 50, left child 30, right child 70: visit the left subtree (30), then the root (50), then the right subtree (70). The output is 30, 50, 70.

In-order traversal of a binary search tree always produces the values in ascending order, which is one of its most useful properties.

Markers reward the left-node-right rule and the correct output 30, 50, 70 in ascending order.

WJEC 20225 marksExplain how a new node is inserted at the front of a singly linked list, referring to the pointers involved.
Show worked answer →

Describe the pointer operations needed to add a node at the head, in the correct order.

A singly linked list keeps a pointer to the first node (the head). Each node holds data and a pointer to the next node.

To insert at the front: create the new node; set the new node's next pointer to point to the current head node; then set the head pointer to point to the new node.

The order matters: if you reassign the head pointer first, you lose the reference to the rest of the list. Doing the new node's next pointer first preserves the chain.

Markers reward creating the node, pointing the new node's next at the old head, updating the head to the new node, and noting the importance of the order.

Related dot points

Sources & how we know this