View worked solution
Answer: 4
To find the height of the binary tree, we first reconstruct the tree using its postorder and inorder traversals.
In a postorder traversal, the root node is always visited last. In an inorder traversal, the root node splits the sequence into left and right subtrees.
- The last element of the postorder traversal is
1, which is the root. - Splitting the inorder traversal around
1gives:- Left subtree:
{8, 6, 9, 4, 7, 2, 5} - Right subtree:
{3}
- Left subtree:
Repeating this process recursively, we reconstruct the unique binary tree structure:
1is the root. Its left child is2, and its right child is3.2has left child4and right child5.4has left child6and right child7.6has left child8and right child9.
The paths from the root 1 to the leaf nodes are:
- (length 1)
- (length 2)
- (length 3)
- (length 4)
- (length 4)
The height of the tree is the length of the longest path from the root to any leaf, which is .
Free practice · Your answers on this page are not saved.
