Today you are going to take a look at family trees and implement a method to cou
ID: 3918330 • Letter: T
Question
Today you are going to take a look at family trees and implement a method to count the number of leaves it has in it. Details Download the ZIP files named FilesNeeded.zip for use in IntelliJ. When you are happy with your solution, upload the files into the src folder and run. You are going to finish off Tree.java to complete the leafCount( method of the Node class. Input You will note that most of the Tree class and, within it, the Node class have been implemented for you. In PoD.java, we have read in details to create a Tree with several nodes. Processing You are going to complete the details the leafCount() method Details of what this method should do follows: For a given node N . If N is a leaf, the leaf count is 1 . Otherwise o Let c, cn be the children of N o The leaf count is leaf Count c..+leaf Couni Cn) Your method will return this leaf count. Output Output will be handled by the main method and has already been taken care of for you.Explanation / Answer
import java.util.*; public class PoD { //============================================================================= /** * Returns true if binary tree is balanced * @param bTree BinaryTree of interest * @return boolean value (true if balanced, false if not) */ public static boolean isBalanced(BinaryTree bTree) { if(bTree == null) { return true; } else { return isBalanced(bTree.left()) && isBalanced(bTree.right()) && Math.abs(bTree.left().height() - bTree.right().height()) 0) && (n%3==0)) { b = new BinaryTree(n,makeBT(n-1),makeBT(n-2)); } else if (n>0) { b = new BinaryTree(n,makeBT(n-2),null); } else { b = new BinaryTree(n,null,null); } return b; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.