Past exam question: 2066 Bhadra (Regular / Back), Q11
Open in the Padhaiko appQuestion
Write down the preorder, inorder and postorder traversal of the tree shown in the figure below.
[figure: binary tree rooted at A; A has left child B and right child C; B has left child D and right child E; C has right child F; D has right child G; E has left child H and right child I]
Solution
Tree Structure and Recursive Traversals:
- Preorder (
Root -> Left -> Right):Aleft subtree(B -> D -> G -> E -> H -> I) right subtree(C -> F)A, B, D, G, E, H, I, C, F - Inorder (
Left -> Root -> Right): left subtree(D -> G -> B -> H -> E -> I)Aright subtree(C -> F)D, G, B, H, E, I, A, C, F - Postorder (
Left -> Right -> Root): left subtree(G -> D -> H -> I -> E -> B) right subtree(F -> C)AG, D, H, I, E, B, F, C, A
Answer:
- Preorder:
A, B, D, G, E, H, I, C, F - Inorder:
D, G, B, H, E, I, A, C, F - Postorder:
G, D, H, I, E, B, F, C, A