Question: Problem 4. (15 points) (a) Construct the binary tree using the labels of the nodes printed in pre-order and in-order traversals of the tree as

Problem 4. (15 points) (a) Construct the binary tree using the labels of the nodes printed in pre-order and in-order traversals of the tree as given below: (10 points) PreOrder : 31498 2 5 0 7 6 Inorder : 48 91 352 706 (b) Suppose you have arrays PREORDER[n], and POSTORDER[nthat give the positions of nodes in the preorder and postorder traversals of the array. In the above example, PREORDER[4] = 3 as node 4 appears as third item in the preorder traversal of the tree. Complete the following algorithm that given two nodes i and j, can determine if i is an ancestor of j in the binary tree or not using those arrays . Your algorithm should have O(1) time and space complexity. (5 points) is Ancestor(PREORDER, POSTORDER,i,j) Input: Binary tree T's PREORDER and POSTORDER traversal order arrays, distinct nodes i and j in the tree T Output: Return true iff i is an ancestor of y
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
