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)

Lab1- implementing Binary Search Tree (MyBST) Programming language: Java 1. Code a

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 100

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!