Question: Java Programming Complete the height() method Complete the isCompleteBinaryTree() method Code: import java.util.LinkedList; import java.util.Queue; public class BinaryTree { public TreeNode root; public BinaryTree(){ }

Java Programming

Complete the height() method

Complete the isCompleteBinaryTree() method

Code:

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;

}

}

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!