Given an array pre[] of N nodes representing preorder traversal of BST. The task is to print its postorder traversal
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Since we are given the preorder traversal of the tree, to construct any tree we need at least two traversal {inorder,preorder},{inorder,postorder},{inorder,levelorder} that is inorder is needed, but here only one traversal is given but one more important thing is the property of this tree, that is this tree is BST, which has its left child less than or equal to the root of the tree and right child as greater than the root element. So we will use this property and construct a BST and then we simply print the Postorder traversal of the tree.
Pseudo Code:
C++ Implementation:
Output