Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem #3 \" Link-based Binary Tree Download this java file. Complete the heigh

ID: 3932537 • Letter: P

Question

Problem #3 " Link-based Binary Tree Download this java file. Complete the height) and When you think you are done, submit your solution in Web-CAT subtreesizet) methods so that they compute the height of the node and the number of nodes in the sode's subtree, respectively How To Submit Submit cach of your solutions to Web-CAT. They should be submitted as Weck09Problemo1, Week09Problem02, and Week09Problem03, respectively

Explanation / Answer

public class BTNode { protected E element; protected BTNode left; protected BTNode right; protected BTNode parent; public BTNode(E element, BTNode parent) { this.element = element; this.parent = parent; } public int height(){ int lh = left == null ? -1 : left.height(); int rh = right == null ? -1 : right.height(); return lh > rh ? lh + 1 : rh + 1; } public int subtreeSize(){ int total = 0; if(left != null){ total += 1 + left.subtreeSize(); } if(right != null){ total += 1 + right.subtreeSize(); } return total; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote