Study resource
Tree-traversal study guide
Study Tree-traversal with curriculum-aligned Study Guide resources, practice links, and exam-focused support.
At a glance
study guide
Resource type
Topic
Tree-traversal
Study guide overview
Deeper Study Guide: Tracing and Applying Tree Traversals
Use this guide to trace each traversal accurately, justify the order of node visits, and connect each algorithm to its specified application.
A reliable tracing method
Start at the root and write down the required order for the traversal: pre-order is root-left-right, in-order is left-root-right, and post-order is left-right-root. Do not list a node merely because you first reach its position. Instead, apply the rule recursively to each subtree.
For a tree whose root is
M, whose left subtree has rootFwith childrenBandH, and whose right child isT, trace the left subtree and right subtree according to the same rule:- Pre-order: visit
M, then traverseFbeforeT. The result isM, F, B, H, T. - In-order: traverse the left side of
F, visitF, then its right side; visitM; then visitT. The result isB, F, H, M, T. - Post-order: complete both subtrees before their parent. The result is
B, H, F, T, M.
The important reasoning is not just the final sequence. For example, in post-order,
Fcannot be output until bothBandHhave been output, andMcannot be output until both complete subtrees have been processed.Applying the specified uses
For copying a tree, use pre-order and create or copy the current node before recursively handling its subtrees. This preserves the relationship between a parent and the children that are copied beneath it.
For a binary search tree, use in-order traversal when the required result is the contents in ascending order. The left subtree is output before the root, and the right subtree is output after the root, giving the required ordering for the binary search tree.
For infix to RPN conversion, use post-order on an expression tree. An operator is produced after the expression represented by its left subtree and the expression represented by its right subtree. This places the operator after its operands, which is the postfix arrangement. The same post-order reasoning applies when producing a postfix expression from an expression tree.
For emptying a tree, post-order ensures that a node's subtrees are processed before the node itself. When tracing, check that every child appears before its parent.
Exam application checklist
- Identify the traversal named in the question.
- Write its three-part order before starting.
- Mark the root, then trace the left and right subtrees recursively.
- Check that every node appears exactly once.
- If the question asks for a use, connect the order to the stated task rather than giving an unrelated example.
- If the tree is a binary search tree and in-order is requested, check that the output is ascending.
- If post-order is used for postfix output, check that operands occur before their operator.
Self-check questions
Can you explain why pre-order is suitable for copying a tree? Can you trace all three orders for a tree with missing children? Can you explain why in-order output is ascending specifically for a binary search tree? Can you identify which traversal places a parent after both children? Finally, given an expression tree, can you justify each symbol's position in the postfix result rather than only writing the final sequence?
- Pre-order: visit
Ready to practise?
Choose your next step
Use the study guide for understanding, then switch into an active revision mode.
Related topics
