A tree is a connected, acyclic (no cycles) directed graph with a single root node. All other nodes descend from the root via parent-child relationships.
| Term | Definition |
|---|---|
| Root | The top node — has no parent |
| Node | Any element in the tree |
| Edge | A directed connection from parent to child |
| Leaf (terminal node) | A node with no children |
| Parent | A node directly above another node |
| Child | A node directly below a parent |
| Subtree | Any node and all of its descendants |
| Height/depth | Length of the longest path from root to leaf |
A binary tree is a tree where each node has at most two children — a left child and a right child.
A binary search tree is an ordered binary tree where:
// Build BST from: 50, 30, 70, 20, 40, 60, 80
50
/ \
30 70
/ \ / \
20 40 60 80
// Search for 40: 50 → left → 30 → right → 40 ✓ (O(log n) average)
| Operation | Average | Worst (unbalanced) |
|---|---|---|
| Search | O(log n) | O(n) |
| Insert | O(log n) | O(n) |
| Delete | O(log n) | O(n) |
The worst case occurs when data is inserted in sorted order, creating a linear chain (degenerate tree).
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes