C++ print Postorder traversal from Preorder and Inorder traversal of a tree
belongs to collection: Data Structure programs using C and C++ (Sorting Programs)
All Answers
total answers (1)
belongs to collection: Data Structure programs using C and C++ (Sorting Programs)
total answers (1)
Algorithm:
As we know that in preorder traversal root is always the first element so we will find the left and right subtree recursively and at last the root, for that we have to search inorder for the left and right subtree. First we will search elements of preorder in inorder as the elements after the index of the searched element in inorder are the members of the right subtree and elements before the index are elements of right subtree and the searched element is the root of that subtree.
Consider the program:
Output