Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions