Question: In this exercise we develop a method to reconstruct a binary tree from an inorder and postorder traversal sequence of the unknown tree, as well




In this exercise we develop a method to reconstruct a binary tree from an inorder and postorder traversal sequence of the unknown tree, as well as provide the postorder traversal sequence of the tree Please complete the program ReconstructTree.py, which lets the user enter the inorder and postorder traversal sequences of a tree as input arguments into the function buildTree (). The function then constructs the corresponding binary tree. The program also needs to include the function postorder (), which returns the postorder traversal sequence of an input tree Please note: O All nodes of the tree contain a single character and the inorder and postorder traversal sequences are strings formed by these characters in the corresponding order. Note that in our examples the reconstructed tree is a binary tree, but not a binary search tree Please construct the tree using a list-of-list representation and use the supplied file ListBinaryTree.py All of your own implementations should be contained within ReconstructTree.py O O O The following figures show test cases and expected output of the program Binary Tree construction: Please enter the inorder sequence: 42513 Please enter the preorder sequence: 12453 [1, [2, [4, None, None], [5, None, None]], [3, None, None]l] Postorder traversal of tree is: 45231 Binary Tree construction: Please enter the inorder sequence: CS105 Please enter the preorder sequence: 0SC15 [0, [S, [C, None, None], [1, None, None]], [5, None, None]] Postorder traversal of tree is: C1S50 Binary Tree construction: Binary Tree construction: Please enter the inorder sequence: cbdae Please enter the preorder sequence: abcde [a, [b, [c, None, None], [d, None, None]], [e, None, None]] Postorder traversal of tree is: cdbea In this exercise we develop a method to reconstruct a binary tree from an inorder and postorder traversal sequence of the unknown tree, as well as provide the postorder traversal sequence of the tree Please complete the program ReconstructTree.py, which lets the user enter the inorder and postorder traversal sequences of a tree as input arguments into the function buildTree (). The function then constructs the corresponding binary tree. The program also needs to include the function postorder (), which returns the postorder traversal sequence of an input tree Please note: O All nodes of the tree contain a single character and the inorder and postorder traversal sequences are strings formed by these characters in the corresponding order. Note that in our examples the reconstructed tree is a binary tree, but not a binary search tree Please construct the tree using a list-of-list representation and use the supplied file ListBinaryTree.py All of your own implementations should be contained within ReconstructTree.py O O O The following figures show test cases and expected output of the program Binary Tree construction: Please enter the inorder sequence: 42513 Please enter the preorder sequence: 12453 [1, [2, [4, None, None], [5, None, None]], [3, None, None]l] Postorder traversal of tree is: 45231 Binary Tree construction: Please enter the inorder sequence: CS105 Please enter the preorder sequence: 0SC15 [0, [S, [C, None, None], [1, None, None]], [5, None, None]] Postorder traversal of tree is: C1S50 Binary Tree construction: Binary Tree construction: Please enter the inorder sequence: cbdae Please enter the preorder sequence: abcde [a, [b, [c, None, None], [d, None, None]], [e, None, None]] Postorder traversal of tree is: cdbea
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
