Question: 2. Lists and Trees (20 points) (Learning Objectives 1 and 2) The following code fragment defines a structure for storing a binary tree and a



2. Lists and Trees (20 points) (Learning Objectives 1 and 2) The following code fragment defines a structure for storing a binary tree and a function for re-constructing a binary search tree from an array of integers. The integers in the array are ordered according to the postorder traversal of the original binary search tree. We also assume that all integers are distinct. 1 typedef struct _tnode t int value; struct tnode left, *right; 4 tnode; 6 tnode *build_bst from_postorder (int array, int lb, int ub) if (lb > ub) { return NULL 10 tnode node malloc (sizeof (tnode)) 12 node->valuearray [ub]; 13 14 // find the left subtree and the right subtree of node in the array 15 // assume that all integers in left subtreenode-value 16 17 hile ((partition_idx ub) { return NULL 10 tnode node malloc (sizeof (tnode)) 12 node->valuearray [ub]; 13 14 // find the left subtree and the right subtree of node in the array 15 // assume that all integers in left subtreenode-value 16 17 hile ((partition_idx
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
