Data Structures, Algorithms, & Applications in C++
Chapter 11, Exercise 15
We can build the tree in the following way. The first element in preorder 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 a. Therefore, cdb
is the inorder of the left subtree and gfeh is the
inorder of the right subtree. The next element in preorder is b.
Since b has already been determined to be in the
left subtree, it must the root of the left subtree.
Proceeding in this way, we get:
a
/ \
b e
/ / \
c f h
\ /
d g
The postorder listing is dcbgfhea
The level order listing is abecfhdg