In simple terms
A friendly intro before the formal notes — no formulas yet.
The Family Tree of Data
Trees are a way to store data that has a hierarchical relationship, like a family tree or a company's organisation chart. Unlike linear structures such as arrays, trees branch out, allowing for efficient organisation of nested information.
Imagine a real family tree. You have a single ancestor at the top (the root). They have children, who in turn have their own children. Each person is a 'node', and the lines connecting them are 'edges'. People with no children are at the ends of the branches, like 'leaves' on a tree. This structure is perfect for representing relationships where one thing has many things below it.
- 1
Start with the 'root' node at the top, the single origin point of the entire structure.
- 2
Connect the root to its 'children' using 'edges'. These children are now 'parent' nodes to their own children.
- 3
Continue adding nodes. Any node with no children is a 'leaf' node, representing the end of a branch.
- 4
A 'binary tree' is a special type where each parent node can have at most two children: a left child and a right child.
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Key formulas
Tap any symbol to reveal exactly what it means and its units.
Full topic notes
Formal explanation with the rigour you need for the exam.
Fundamental Tree Terminology
A tree is a collection of entities called nodes. Nodes are connected by edges. Each tree has exactly one root node, which is the starting point of the tree. Every other node is connected by a directed edge from exactly one other node, its parent. A node can have multiple child nodes. A path is a sequence of nodes and edges connecting a node with a descendant. For example, in a file system, the root directory (e.g., C:) is the root node, folders are nodes, and the files within them are also nodes. The connection between a folder and a sub-folder is an edge.
Root: The top-most node; it has no parent. A tree has only one root.
Parent: A node that has at least one child node.
Child: A node that has a parent.
Siblings: Nodes that share the same parent.
Leaf (Terminal Node): A node with no children.
Internal Node: Any node that is not a leaf (i.e., has at least one child).
Tree Properties: Height, Depth, and Level
To analyse the efficiency of tree-based algorithms, we need to measure their structure. The depth of a node is the length of the path (number of edges) from the root to that node. The root node is at depth 0. The height of a tree is the depth of its deepest leaf node, which is equivalent to the length of the longest path from the root to any leaf. A tree with a single node has a height of 0. The level of a node is often defined as its depth, with the root being at level 0. Be careful, as some definitions start levels at 1, but the IB convention generally aligns with depth starting at 0.
Examiners frequently ask for the height of a tree. Remember the definition: it's the number of edges on the longest path from root to leaf. A common mistake is to count the number of nodes instead. For a tree with a single node, the height is 0, not 1.
The Binary Tree
While a general tree can have any number of children per node, a binary tree is a more restricted and very common type of tree. In a binary tree, each node can have at most two children. These children are distinguished as the left child and the right child. This ordering is important. A node with one child must specify whether it is a left or right child. This simple constraint makes binary trees much easier to implement and analyse, and they form the basis for many advanced structures, including the Binary Search Tree (BST) which we will cover separately.
For a binary tree of height , the maximum number of nodes it can contain is . This occurs when the tree is 'full', meaning every node has either 0 or 2 children, and all leaves are at the same depth.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
Consider the following tree diagram where letters represent the data in each node.
A
/|\
B C D
/ \ |
E F G
|
H
(a) Identify the root node. [1] (b) Identify all leaf nodes. [2] (c) Identify the parent of node G. [1] (d) Identify the children of node B. [1] (e) Identify the siblings of node C. [1]
- 1
(a) The root node is the single top-most node. A [1]
Consider the binary tree below:
10
/ \
5 15
/ / \
2 12 20
(a) State the height of this binary tree. [1] (b) State the data in the right child of the node containing 15. [1] (c) Explain why this is a valid binary tree. [2] (d) Calculate the maximum number of nodes this tree could hold, given its height. [2]
- 1
(a) The longest path from the root (10) to a leaf is to node 2, 12, or 20. Let's take the path 10 -> 5 -> 2. This path has 2 edges. Height = 2 [1]
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
Tree (Data Structure)
A non-linear data structure that represents hierarchical data. It consists of nodes connected by edges, with a single root node and no cycles.
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Root: The top-most node; it has no parent. A tree has only one root.
- ✓
Parent: A node that has at least one child node.
- ✓
Child: A node that has a parent.
- ✓
Siblings: Nodes that share the same parent.
- ✓
Leaf (Terminal Node): A node with no children.
- ✓
Internal Node: Any node that is not a leaf (i.e., has at least one child).
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Test Your Knowledge
Test Your Knowledge
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Test Your Knowledge on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.