Question: Q5 (30 points). Write a program to implement a binary search tree, with the following node struct: typedefstructtreenode(intdata;structtreenodeleft;structtreenode*right;}node;/treenodestruct//integerfield//pointertotheleftchild//pointertotherightchild/ a. Given an empty root node of

Q5 (30 points). Write a program to implement a binary search tree, with the following node struct: typedefstructtreenode(intdata;structtreenodeleft;structtreenode*right;}node;/treenodestruct//integerfield//pointertotheleftchild//pointertotherightchild/ a. Given an empty root node of a binary search tree (BST) and a set of values from user input to insert into the tree, return the left most node of the BST after the insertion. It is guaranteed that values contain no duplicates. b. Search in a BST: Given the above BST and an integer value from user. Find the node in the BST that the node's value equals value. If such a node exists, return true, otherwise, return false. c. Check if the above BST is balanced or not. A binary tree is height-balanced or simply balanced if the difference in height of both subtrees of any node in the tree is either zero or one, i.e., Hight(left-subtree)-Hight(right-subtree) =0,1, or -1 (You only need to check if the tree is balanced, no need to implement rotations.) Q5 (30 points). Write a program to implement a binary search tree, with the following node struct: typedefstructtreenode(intdata;structtreenodeleft;structtreenode*right;}node;/treenodestruct//integerfield//pointertotheleftchild//pointertotherightchild/ a. Given an empty root node of a binary search tree (BST) and a set of values from user input to insert into the tree, return the left most node of the BST after the insertion. It is guaranteed that values contain no duplicates. b. Search in a BST: Given the above BST and an integer value from user. Find the node in the BST that the node's value equals value. If such a node exists, return true, otherwise, return false. c. Check if the above BST is balanced or not. A binary tree is height-balanced or simply balanced if the difference in height of both subtrees of any node in the tree is either zero or one, i.e., Hight(left-subtree)-Hight(right-subtree) =0,1, or -1 (You only need to check if the tree is balanced, no need to implement rotations.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
