1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
saul85 [17]
3 years ago
13

A perfect binary tree is a complete binary tree with all levels fully filled. Add a method in the BST class to return true if th

e tree is a perfect binary tree.
Computers and Technology
1 answer:
algol [13]3 years ago
6 0

Answer:

class BST {

static class Node

{

int val;

Node left, right;

}

static boolean checkPerfectBT(Node node, int h, int d)

{

if (node == null)

return true;

 

if (node.left == null && node.right == null)

{

if(h==d+1)

return true;

else

return false;

}

 

if (node.left == null || node.right== null)

return false;

 

return checkPerfectBT(node.left, h, d+1) && checkPerfectBT(node.right, h, d+1);

}

static int height(Node node)

{

int dep = 0;

while (node != null)

{

node = node.right;

dep=dep+1;

}

return dep;

}

static boolean isPerfectBT(Node node)

{

int h = height(node);

return checkPerfectBT(node, h, 0);

}

 

static Node addNode(int x)

{

Node node = new Node();

node.val= x;

node.right = null;

node.left = null;

return node;

}

public static void main(String args[])

{

int i,j,k;

Node node= null;

node = addNode(34);

node.left = addNode(2);

node.right = addNode(322);

 

node.left.left = addNode(21);

node.left.right = addNode(23);

node.right.left = addNode(37);

node.right.right = addNode(54);

 

if (isPerfectBT(node) == true)

System.out.println("This is a Perfect Binary tree");

else

System.out.println("This is Not a perfect Binary Tree");

}

}

Explanation:

  • Calculate the depth of BST by using a while loop until it reaches a null value.
  • In the addNode method, make an object of Node class.
  • In the main method, pass the values to addNode method.
  • Finally display the relevant message to show if it's Perfect or not.
You might be interested in
Rainfall_mi is a string that contains the average number of inches of rainfall in Michigan for every month (in inches) with ever
const2013 [10]

Answer:

Hi!

The answer in Javascript is:

function monthsWithMoreOfThree() {

  var Rainfall_mi = '3,4,1,5,2,6,7,9'; <em>//Defined and declared</em>

  var num_rainy_months = 0;

  var values = Rainfall_mi.split(","); <em>//use split method for Strings. Array is returned</em>

   for (var i = 0; i < values.length; i++) { <em>//for each value, compares with 3</em>

     if(values[i] > 3) { <em>//In Javascript, you can compare an String value with an int. Can use parseInt(aString) to explicit parse but is not necessary</em>

       num_rainy_months++; <em>//If value is greater than 3, adds 1 to num_rainy_months</em>

     }

   }

}

5 0
2 years ago
A storyboard is an example of an implementation tool.<br><br> A.<br> True<br><br> B.<br> False
Phantasy [73]
A True A storyboard is hardware installed directly onto the motherboard or using a <span>Peripheral device</span>
4 0
2 years ago
Read 2 more answers
How to make text icome one word at a timen filmora
bezimeni [28]

You would want to add multiple text slides.

I hope this helps as the wording of the question was unclear.

8 0
1 year ago
Researching the history of computers is a good troubleshooting technique.<br> True or False?
Verdich [7]

Yes very much so! You could learn previous mistakes/bugs/etc and find solutions to fixing them and avoiding getting them. As well as much more. History is always a fun subject for anything, really in my opinion.

4 0
2 years ago
WHAT IS MULTIMEDIA SUPPOSED TO MEAN ???
melisa1 [442]

Answer:

using more than one medium of expression or communication

3 0
2 years ago
Read 2 more answers
Other questions:
  • Make the correct match.
    11·1 answer
  • When using color in computer-generated presentation aids, you should use?
    10·1 answer
  • When you move a paragraph in a document that includes text with a footnote, what happens to the footnote reference?
    7·2 answers
  • What is f(-3) for the function f(a)=-2a2-5a+4?​
    10·1 answer
  • In preparing his persuasive presentation, Reza should most likely focus on clearly presenting his
    6·2 answers
  • What are the two basic classes of active directory objects?
    14·1 answer
  • What is the missing line of code?
    10·2 answers
  • Draw AND, OR, XOR and XNOR gates with truth table and logic gates.<br><br>.​
    11·1 answer
  • The analogy of a computer system is often used to illustrate the different parts of memory. The keyboard is where we encode new
    8·1 answer
  • Write a python program that will read a number (num) and display all the numbers divisible by 3 or 5
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!