Write a recursive body for the following static, generic method that computes an
ID: 3858856 • Letter: W
Question
Write a recursive body for the following static, generic method that computes and returns the size of a given BinaryTree. You can use any of the BinaryTree methods except for the iterator and the size kernel method. Note that the BinaryTree must be restored, i.e., its outgoing value must be the same as its incoming value. [JAVA]
/**
* Returns the size of the given {@code BinaryTree}.
*
* @param
* the type of the {@code BinaryTree} node labels
* @param t
* the {@code BinaryTree} whose size to return
* @return the size of the given {@code BinaryTree}
* @ensures size = |t|
*/
public static int size(BinaryTree t) {...}
Explanation / Answer
*/ public static int sizeRecursive(BinaryTree t) { int size = 0; BinaryTree left = new BinaryTree1(); BinaryTree right = new BinaryTree1(); if (t.height() != 0) { T label = t.disassemble(left, right); size++; size = size + sizeRecursive(left); size = size + sizeRecursive(right); t.assemble(label, left, right); } return size; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.