In Java: Implement Public T findRightmostLowest. DO NOT ADD ANY DATA (variable members) TO THE BSTREE/NODE CLASS. DO NOT USE NEW OR CREATE ARRAYS. Will leave good review and thumbs up! Thank you.
Here is the code done on the BSTree provided for the class.
import java.util.Arrays; public class BSTree> { private static class Node> { public T data; public Node left, right;
public Node(Node left, T data, Node right) { this.left = left; this.data = data; this.right = right; }
public boolean contains(T d) { int comp = d.compareTo(data); if (comp == 0) return true; // Already in tree if (comp
} public int size() { // We know there is a node here int total = 1; // This node may have left children if (left != null) total = total + left.size(); // This node may have right children if (right != null) total = total + right.size(); // The total size of the tree from this point... return total; } public Node delete(T d) { int comp = d.compareTo(data); if (comp == 0) return deleteNode(); if (comp private Node root;
public BSTree() { root = null; }
/** * Adds data to the tree if it didn't already contain it. * * @param data */
public boolean contains(T data) { if (root == null) return false; return root.contains(data); } public int size() { if (root == null) return 0; return root.size(); } public void delete(T data) { if (root == null) return; root = root.delete(data); } public T findRightmostLowest() { // TODO: Implement. return null; } }
The following methods should be implemented for BSTree. Begin with BSTree.java available on Canvas. You will probably have to implement corresponding helper Node methods! Do not add any data (variable) members to the BSTree/Node class, only methods (helper methods OK). For full credit, implement all methods without using new or creating arrays. (5 point penalty per method for using new/creating arrays) 2. Implement public T findRightmostLowest() Among the nodes which are furthest from the root, find the one which is furthest to the right (largest). In the above tree, there are two lowest nodes: B and F. Both of them are distance 3 from the root; all other nodes are less than distance 3. F is to the right of B so tree.findRightmostLowest() should return "F". If F was removed from the tree, B would the rightmost lowest even though we only went left to get there because it's the only node that is furthest from the root. Whether or not we remove F, if we added "MB" and "MA" to the tree, "MA" would be the rightmost lowest as they are to the right of "F" (larger) The following methods should be implemented for BSTree. Begin with BSTree.java available on Canvas. You will probably have to implement corresponding helper Node methods! Do not add any data (variable) members to the BSTree/Node class, only methods (helper methods OK). For full credit, implement all methods without using new or creating arrays. (5 point penalty per method for using new/creating arrays) 2. Implement public T findRightmostLowest() Among the nodes which are furthest from the root, find the one which is furthest to the right (largest). In the above tree, there are two lowest nodes: B and F. Both of them are distance 3 from the root; all other nodes are less than distance 3. F is to the right of B so tree.findRightmostLowest() should return "F". If F was removed from the tree, B would the rightmost lowest even though we only went left to get there because it's the only node that is furthest from the root. Whether or not we remove F, if we added "MB" and "MA" to the tree, "MA" would be the rightmost lowest as they are to the right of "F" (larger)