Question
Lab1- implementing Binary Search Tree (MyBST) Programming language: Java 1. Code a method member (for MyBST class) called sumLeftBranch() that return the sum of elements
Lab1- implementing Binary Search Tree (MyBST)
Programming language: Java
1. Code a method member (for MyBST class) called sumLeftBranch() that return the sum of elements of the (TreeNode) nodes in the outmost left subtree starting from the (TreeNode) root.
For example, in Figure 1 sumLeftBranch () returns 71 = (44+10+9+8)
2. Code a method member (for MyBST class) called getElemAtLevel_LeftBranch(int theLevel) that returns the element part of a node on the left subtree located at the tree level theLevel (root is located at level 1)
For example, in Figure 1 , getElemAtLevel_LeftBranch(4) returns 8
3. Code a method member (for MyBST class) called getMax() that returns the maximum element in the tree.
For example, in Figure 1, getMax() returns 100
Write an application class with the following main method
public static void main(String[] args) {
Integer[] arr= {44, 10, 88, 9, 22, 77, 99, 8, 11, 33, 66, 100, 55};
MyBST tree= new MyBST(arr); // the constructor should be implemented
System.out.println(" The sum of the left branch is "+ tree.sumLeftBranch() );
System.out.println("Element at level 4 is "+ tree.getElemAtLevel_LeftBranch(4));
System.out.println(" The maximal value in the tree is :"+tree.getMax());
}
10 100Step 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