Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions