Skip to main content
EnglandComputer ScienceSyllabus dot point

What is a tree and how is a binary search tree used?

Understand trees as a connected, undirected graph with no cycles, the terms root, child, parent, leaf and subtree, and the structure and use of a binary search tree.

A focused answer to AQA A-Level Computer Science 4.2.5, covering trees as connected acyclic graphs, the terminology root, child, parent and leaf, binary trees, and the structure and use of a binary search tree.

Generated by Claude Opus 4.88 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. Trees and terminology
  3. Binary trees
  4. Binary search trees

What this dot point is asking

AQA wants you to define a tree as a connected, undirected graph with no cycles, use the terminology (root, child, parent, leaf, subtree), and explain the structure and use of a binary search tree.

Trees and terminology

Trees model hierarchical data such as file systems (folders containing folders and files), family trees, organisation charts, the document object model of a web page, and the structure of a parsed expression. Two further terms are useful: the height of a tree is the number of levels from the root to the deepest leaf, and a node's depth is its distance from the root. Height is what determines how long operations on a tree take.

Binary trees

A binary tree is a tree in which each node has at most two children, conventionally called the left child and the right child. Each node typically stores a data value plus pointers (references) to its left and right children, with a null pointer where a child is absent. This pointer-based structure is dynamic: nodes are created and linked at run time, so the tree grows and shrinks as needed, which is one reason trees are studied alongside other dynamic structures.

Binary search trees

The BST therefore combines two useful properties: fast search (like binary search on a sorted array) and easy insertion (no need to shift elements as you would in an array). The price is that the good performance depends on the tree staying reasonably balanced. If items are inserted in already-sorted order the tree becomes unbalanced, effectively a linked list of height nn, and operations degrade to O(n)O(n). Self-balancing variants address this in practice, but the core specification focuses on the ordered structure and its traversal.

It is worth comparing a BST with a hash table, since both store data for fast retrieval. A hash table gives average O(1)O(1) look-up by key but keeps the data unordered, so it cannot easily produce the items in sorted order or answer range queries (all values between two bounds). A binary search tree gives O(logn)O(\log n) look-up when balanced, which is slightly slower, but its in-order traversal yields sorted output for free and range queries are straightforward. Choosing between them is a genuine design decision: a hash table when you only ever look up exact keys, a search tree when order matters.

Deletion from a BST is the operation students find hardest because there are three cases: removing a leaf simply detaches it; removing a node with one child links the parent directly to that child; removing a node with two children requires replacing it with its in-order successor (the smallest value in its right subtree) so the ordering rule is preserved. Understanding why the successor is chosen, namely that it is the next value in sorted order and so keeps everything to its left smaller and right larger, shows a real grasp of the structure rather than rote recall.

Exam-style practice questions

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

AQA 20194 marksThe values 8, 3, 10, 1, 6 are inserted, in that order, into an initially empty binary search tree. Describe the resulting tree by stating the root and the left and right child of each node, and explain how the value 6 reaches its position.
Show worked answer →

8 becomes the root (first value). 3 is less than 8, so it goes to 8's left. 10 is greater than 8, so it goes to 8's right. 1 is less than 8 (go left to 3) then less than 3, so it goes to 3's left. 6 is less than 8 (go left to 3) then greater than 3, so it goes to 3's right.

Resulting tree: root 8; 8's left child is 3 and right child is 10; 3's left child is 1 and right child is 6.

The value 6 reaches its position by comparison: starting at the root 8, 6<86 < 8 so move to the left child 3; then 6>36 > 3 so move to 3's right, which is empty, so 6 is inserted there.

Markers reward the correct tree structure and the comparison path (8 then left to 3 then right) that places 6.

AQA 20213 marksExplain why a binary search tree can give O(log n) search time, and state the condition under which this performance degrades to O(n).
Show worked answer →

In a binary search tree every node's left subtree holds smaller values and its right subtree holds larger values. A search compares the target with the current node and moves to just one subtree, discarding the other, so each comparison roughly halves the remaining nodes. On a balanced tree the height is about log2n\log_2 n, so a search makes about log2n\log_2 n comparisons, giving O(logn)O(\log n).

Performance degrades to O(n)O(n) when the tree is unbalanced, in the extreme when values are inserted in already-sorted order: each new value goes to one side, producing a tree that is effectively a linked list of height nn, so a search may have to pass through all nn nodes.

Markers reward the halving argument for O(logn)O(\log n) and identifying the unbalanced (sorted-insertion) case for O(n)O(n).

Related dot points

Sources & how we know this