Question
JAVA: The Height of a Binary Tree To start, a node in a binary tree looks like the following, in terms of Java: public class
JAVA: The Height of a Binary Tree
To start, a node in a binary tree looks like the following, in terms of Java:
public class BinaryTreeNode {
int key;
BinaryTreeNode left, right, parent;
public BinaryTreeNode(int key){
this.key=key;
left=right=parent=null; }
}
And a binary tree looks like the following:
public class BinaryTree {
BinaryTreeNode root;
public BinaryTree(){
root=null; }
}
Okay so WHAT TO DO:
implement at least the Insertion operation, either non-recursively or recursively.
MAIN PART: You need a method, with its signature being int treeHeight(BinaryTreeNode root), that gives the height of any tree with its top node referred by the root parameter.
Here is the recursive opertion:
Algorithm 6 TREE-INSERT-REC(yx,z) if x if z.key
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