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

On the code, Complete the height() and subtreeSize() methods so that they comput

ID: 3932827 • Letter: O

Question

 On the code, Complete the height() and subtreeSize() methods so that they compute the height of the node and the  number of nodes in the node's subtree, respectively Code: package edu.buffalo.cse116;  public class BTNode {   /** Tree's element which is stored within this Node. */   protected E element;    /** Left child of the current Node. */   protected BTNode left;   /** Right child of the current Node. */   protected BTNode right;   /** Parent in the binary tree for the current Node. */   protected BTNode parent;    /**    * Creates a new BTNode object with the specified element and parent BTNode.    *    * @param element Data to be held in this BTNode.    * @param parent Parent for this Node within the binary tree.    */   public BTNode(E element, BTNode parent) {     this.element = element;     this.parent = parent;   }    /**    * Returns the height of this BTNode within the binary tree it helps define.    *    * @return 0-based height of this BTNode    */   public int height() {    }    /**    * Returns the number of BTNodes within the subtree rooted at this BTNode    *    * @return Size of the subtree rooted at this BTNode    */   public int subtreeSize() {    } } 

Explanation / Answer

public int height(parent node)

{

if (node== null)

{ return =0; }

else

{

int lheight =height.left(node.left);

int rheight = height.right(node.right);

if ( lheight > rheight)

return (lheight + 1);

else

return(rheight + 1);

2.

public int subtreeSize (BTNode , parent)

{

int count = 1;

int count2 = 0;

    if (parent->left != NULL) {

       count += subtreeSize(parent->left);

    }

    if (parent->right != null) {

        count += subtreeSize(parent->right);

    }

    return count;

if (BTNode->parent != null) {

        count = subtreesize(BTNode->parent);

    }

return count;

}

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