Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started