Data Structures, Algorithms, & Applications in C++
Chapter 11, Exercise 17
We can build the tree in the following way. The last element in postorder is
the tree root. Everything to the left of the tree root in inorder is in
the left subtree and everything to the right is in the right subtree.
The tree root is h. Therefore, aedbc
is the inorder of the left subtree and gf is the
inorder of the right subtree. The next element in postorder is g.
Since g has already been determined to be in the
right subtree, it must the root of the right subtree.
Proceeding in this way, we get:
h
/ \
e g
/ \ \
a d f
\
c
/
b
The preorder listing is headcbgf
The level order listing is hegadfcb