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
What is output if the user types 13 click all that apply ABCD
Klio2033 [76]

Answer:

AD?

Explanation:

3 0
3 years ago
If a flagged word is spelled correctly , right-click it and then click what?
Delvig [45]
U right click it then u click ignore
8 0
3 years ago
1. Realizați o schemă logică pentru un algoritm care sa calculeze suma primelor
DIA [1.3K]

Explanation:

The clear rendering reads;

"1. Make a logic diagram for an algorithm to calculate the sum of premiums 100 natural numbers.

2. Make a logic diagram that displays a maximum of 2 natural numbers.

3. Make a logic diagram that displays the square of a natural number".

4 0
3 years ago
Which company introduce the first Minicomputer in 1960.​
madreJ [45]

Answer:

<em>t</em><em>h</em><em>e</em><em> </em><em>f</em><em>i</em><em>r</em><em>s</em><em>t</em><em> </em><em>m</em><em>i</em><em>n</em><em>i</em><em>c</em><em>o</em><em>m</em><em>p</em><em>u</em><em>t</em><em>e</em><em>r</em><em> </em><em>w</em><em>a</em><em>s</em><em> </em><em>i</em><em>n</em><em>t</em><em>r</em><em>o</em><em>d</em><em>u</em><em>c</em><em>e</em><em> </em><em>b</em><em>y</em><em> </em><em>d</em><em>i</em><em>g</em><em>i</em><em>t</em><em>a</em><em>l</em><em> </em><em>e</em><em>q</em><em>u</em><em>i</em><em>p</em><em>m</em><em>e</em><em>n</em><em>t</em><em> </em><em>c</em><em>o</em><em>r</em><em>o</em><em>p</em><em>o</em><em>r</em><em>a</em><em>t</em><em>i</em><em>o</em><em>n</em><em> </em><em>(</em><em>D</em><em>E</em><em>C</em><em>)</em><em>a</em><em>f</em><em>t</em><em>e</em><em>r</em><em> </em><em>t</em><em>h</em><em>e</em><em>s</em><em>e</em><em> </em><em>I</em><em>B</em><em>M</em><em> </em><em>c</em><em>o</em><em>r</em><em>p</em><em>o</em><em>r</em><em>a</em><em>t</em><em>i</em><em>o</em><em>n</em><em> </em><em>a</em><em>l</em><em>s</em><em>o</em><em> </em><em>m</em><em>i</em><em>n</em><em>i</em><em>c</em><em>o</em><em>m</em><em>p</em><em>u</em><em>t</em><em>e</em><em>r</em><em> </em><em>f</em><em>o</em><em>r</em><em> </em><em>e</em><em>x</em><em>a</em><em>m</em><em>p</em><em>l</em><em>e</em><em> </em><em>P</em><em>D</em><em>P</em><em>–</em><em>1</em><em>1</em>

7 0
3 years ago
Read 2 more answers
Select the correct statements regarding Asynchronous Transfer Mode (ATM): a. ATM is a fixed-length cell standard that supports v
Korvikt [17]

Answer:

D. All of the above are correct.

Explanation:

Asynchronous Transfer Mode is a fixed-length cell structure which allows cells to support voice, video  and data. Voice data can be converted to packets and shared with large packet data. Because voice packets, encounter queuing delays, they ought to be of the same size or length.

ATM provides a route between two end points and that is why it can be said to be connection oriented. There is an ease of switching in hardware because of the fixed structure of the ATM. It also offers predictability regarding latency which could be either high or low. So, all of the above satisfy the mode of operation of the Asynchronous Transfer Mode.

4 0
3 years ago
Other questions:
  • A user can easily moved to the end of document by pressing what key combination?
    8·2 answers
  • A spreadsheet is an interactive computer program used for
    5·1 answer
  • The ____ preceding a formula alerts excel that you are entering a formula or function and not text
    14·1 answer
  • Different organizations implement different Information Systems base on their core business operations. explain
    14·1 answer
  • Which snippet of code is in XML?
    5·1 answer
  • What kind of a bug is 404 page not found
    10·2 answers
  • CC stand for.....in the email platform?
    12·2 answers
  • How are keyboards applied in the real world
    13·1 answer
  • When’s The release date for Mobile legends project next phase 3 going To come
    5·1 answer
  • please help, touch pad and trackpad are the same thing and the other answers don’t really make sense to me..
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!