Given a binary tree with post-order traversal sequence DABEC and in-order traversal sequence DEBAC, its pre-order traversal sequence is:
Given a binary tree with post-order traversal sequence DABEC and in-order traversal sequence DEBAC, its pre-order traversal sequence is:
----C ---/ --E -/-\ D---B -----\ ------A I know the answer is this... What I want to ask is, why is it drawn this way??
Post-order traversal is: Left-Right-Root. In-order traversal is: Left-Root-Right.
- From the post-order traversal (DABEC), C is the root node.
- From the in-order traversal (DEBAC), C has no right subtree. Considering the remaining post-order sequence (DABE) for the left subtree, E is the root node of this left subtree.
- From the in-order traversal (DEBA) of E's subtree, D is E's left child. From the post-order traversal (DAB) of E's subtree, B is the root of the remaining right part, thus B must be E's right child. From the in-order traversal (BA) of B's subtree, A is B's right child.