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 root;
public BinaryTree(){
}
public static class TreeNode {
public E element;
public TreeNode left;
public TreeNode right;
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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!