Question: 1. The following functions construct a binary search tree from a sorted array. 1 typedef struct _Tnode { 2 int info; 3 struct _Tnode *left;

1. The following functions construct a binary search tree from a sorted array. 1 typedef struct _Tnode { 2 int info; 3 struct _Tnode *left; struct _Tnode *right; 5 } Tnode; 4 6 7 Tnode * Tnode_construct (int info) 8 { 9 Tnode *node = malloc(sizeof (*node)); 10 if (node == NULL) { 11 fprintf(stderr, "can't get memory "); 12 return NULL; 13 } 14 node->info = info; 15 node->left = node->right NULL; 16 return node; 17 ] 18 19 Tnode *BST_build(int *array, int lb, int ub) 20 { 21 if (lb > ub) { 22 return NULL; 23 } 24 int mid = (10 + ub)/2; 25 Tnode *node = Tnode_construct (array(nid]); 26 if (node NULL) { 27 return NULL; 28 } 29 node ->left BST_build (array, lb, mid 1); 30 node->right = BST_build(array, nid + 1, ub); 31 return node; 32 } Consider the statements in the main function: 33 int array [] = {1, 3, 5, 7, 9, 11, 13, 15}; 34 int array_size = sizeof(array)/sizeof(array [0]); 35 Tnode *bst = BST_build (array, 0, array_size - 1); Draw the computation tree that corresponds to the function call BST_build(array, 0, array_size - 1). You should show the last two parameters of the recursive function BST_build in each node of the computation tree. Draw the binary search tree constructed. Ignoring the space required to store the array and the space to store the binary search tree, what is the space complexity when array_size is n? What is the time complexity when array_size is n? Justify your answers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
