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

EXERCISE D SHORT ANSwER 15 POINTS Consider the following definitions for a binar

ID: 3849013 • Letter: E

Question

EXERCISE D SHORT ANSwER 15 POINTS Consider the following definitions for a binary tree: public class TreeNode public object item; public TreeNode left; public TreeNode right; public class Tree private TreeNode root Implement (recursively) the method numofNodesAtLevelRec for the class Tree to compute the number of nodes at a specific level (e.g the root node is at level 1, its children at level 2 etc.) in a binary tree. Returns number of nodes at the input level in this binary tree. public int int 1 i return numofNodesAtLevelRec root, Internal recursive method to implement numofNodesAtLevel". Returns the number of nodes of the subtree rooted at "currRoot". private int TreeNode currRoot, int 1)

Explanation / Answer

Program in JAVA:

public class Treenode
{
public object item;
public TreeNode left;
public TreeNode right;
int count ( )
{
tree right = get right node ( );
tree left = get left node ( );
int c = 1;
if (right!=null) c+=right count ( );
if (left!=null) c+=left count ( );
return c;
}
}

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