Question: Problem Description 1. [50 points] Complete the height() method in BinaryTree.java, which is used to return the height of this binary tree. Hint: Use recursive
Problem Description 1. [50 points] Complete the height() method in BinaryTree.java, which is used to return the height of this binary tree. Hint: Use recursive algorithm, you can use a helper method 2. [50 points] Complete the isCompleteBinaryTree() method in BinaryTree.java, which returns if the binary tree is complete. Hint: scan the node from left to right by level, if there is a node has no left child but has right child, return false; if there is a node has left child, but has no right child, future nodes can not have any child, otherwise return false. You can take printTree method in TestMyTree as a reference.
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| public class BinaryTree | |
| public TreeNode | |
| public BinaryTree(){ | |
| } | |
| public static class TreeNode | |
| public E element; | |
| public TreeNode | |
| public TreeNode | |
| public TreeNode(E o) { | |
| element = o; | |
| } | |
| } | |
| /****************************************************************** | |
| * Return the height of this binary tree. | |
| * The height of the tree is the height of root node. | |
| * Hint: Use recursive algorithm, you can use a helper method | |
| * ****************************************************************/ | |
| public int height(){ | |
| //TODO | |
| return 0; | |
| } | |
| /****************************************************************** | |
| * Return if the binary tree is complete | |
| * Hint: scan the node from left to right by level, if there is a | |
| * node has no left child but has right child, return false; if | |
| * there is a node has left child, but has no right child, future | |
| * nodes can not have any child, otherwise return false. You can | |
| * take printTree method in TestMyTree as a reference. | |
| * ****************************************************************/ | |
| public boolean isCompleteBinaryTree(){ | |
| //TODO | |
| return true; | |
| } I want an answer without any changes in this code. And i got another class with the name TestBinaryTree. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
