On the code Complete the height and subtreeSize methods so t

 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() {    } } 

Solution

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;

}

 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, respec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site