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

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; }
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