Question
Suppose you have some data keys sorted in an array and you want to construct a balanced binary search tree from them. Assume a tree
Suppose you have some data keys sorted in an array and you want to construct a balanced binary search tree from them. Assume a tree node representation TreeNode that includes instance variables key, left, and right.
Write pseudocode for an algorithm that constructs the tree and returns the root node. (If using Java don't worry about making the enclosing BinaryTreeclass instance.) You will need to use methods for making a new TreeNode, and for setting its left and right children.
What is the cost to construct the tree with justification. Compare this to the expected runtime of a Binary Search
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