Question: Please help with coding these methods for an AVL /** * Returns the data in the deepest node. If there are more than one node

Please help with coding these methods for an AVL

/** * Returns the data in the deepest node. If there are more than one node * with the same deepest depth, return the right most node with the * deepest depth. * * Must run in O(log n) for all cases * * Example * Tree: * 2 * / \ * 0 3 * \ * 1 * Max Deepest Node: * 1 because it is the deepest node * * Example * Tree: * 2 * / \ * 0 4 * \ / * 1 3 * Max Deepest Node: * 3 because it is the maximum deepest node (1 has the same depth but 3 > 1) * * @return the data in the maximum deepest node or null if the tree is empty */ public T maxDeepestNode() {

}

/** * Returns the data of the deepest common ancestor between two nodes with * the given data. The deepest common ancestor is the lowest node (i.e. * deepest) node that has both data1 and data2 as descendants. * If the data are the same, the deepest common ancestor is simply the node * that contains the data. You may not assume data1 < data2. * (think carefully: should you use value equality or reference equality?). * * Must run in O(log n) for all cases * * Example * Tree: * 2 * / \ * 0 3 * \ * 1 * deepestCommonAncestor(3, 1): 2 * * Example * Tree: * 3 * / \ * 1 4 * / \ * 0 2 * deepestCommonAncestor(0, 2): 1 * * @param data1 the first data * @param data2 the second data * @throws java.lang.IllegalArgumentException if one or more of the data * are null * @throws java.util.NoSuchElementException if one or more of the data are * not in the tree * @return the data of the deepest common ancestor */ public T deepestCommonAncestor(T data1, T data2) {

}

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!