For both above trees, the preorder and postorder traversal results in same sequence of numbers:

preorder : { a, b, c, d }
postorder : { d, c, b, a }

Therefore, it is not possible to construct a unique binary tree with the help of preorder and postoder sequences. However, a unique full binary tree can easily constructed with them. To illustrate, consider below preorder and postorder sequence –

We know that root is the first element in preorder sequence and the last element in postorder sequence. Therefore, the root node is 1. Then we locate the next element in preorder sequence, which must be the left child of the root node. In this case, the left child is 2. Now since 2 is root node of the left subtree, all nodes before 2 in the postorder sequence must be present in the left subtree of the root node i.e. {4, 5, 2} and all the nodes after 2 (except the last) must be present in right subtree i.e. {8, 9, 6, 7, 3}. Now the problem is reduced to building the left and right subtrees and linking them to the root node.

Left subtree:

Postorder : {4, 5, 2}
Preorder : {2, 4, 5}

Right subtree:

Postorder : {8, 9, 6, 7, 3}
Preorder : {3, 6, 8, 9, 7}

The idea is to recursively follow the above approach until the complete tree is constructed. This is demonstrated below in C++:

Note that above algorithm will ensure a unique binary tree only when all keys in the given preorder/postorder sequence are distinct. For example, two full binary trees exists for following preorder and postorder sequences whose node keys are not distinct.