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

Write a method countEmpty that returns the number of empty branches in a tree. A

ID: 662514 • Letter: W

Question

Write a method countEmpty that returns the number of empty branches in a tree. An empty tree is considered to have one empty branch (the tree itself). For non-empty trees, your method(s) should count the total number of empty branches among the nodes of the tree. A leaf node has two empty branches. A node with one non-empty child has one empty branch. A node with two non-empty children (a full branch) has no empty branches. For example the tree below has 15 empty branches (indicated by circles) 4 6 14 3 18 |5 | Assume that you are adding this method to the IntTree class as defined below: public class IntTree private IntT overallRoot;

Explanation / Answer

private String toString(IntTreeNode root, int sizeAboveLeft, int level, int size, int height, int width) { // System.out.println("toString(root, " + sizeAboveLeft + ", " + level + ", " + size + ", " + height + ", " + width + ")"); if (root == null) { return ""; } else { String result = ""; int sizeBelowLeft = __getSize(root.left); if (root.cycle()) { // sizeBelowLeft = 0; } int sizeLeft = sizeAboveLeft + sizeBelowLeft; // create line for this element // (must potentially put leading __ marks for left/right pointers) String thisElementLine = ""; String nextLine = ""; if (root.left == null) { // indent this node for (int i = 0; i
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