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
Which of the following is typically used in a flowchart to indicate a decision?
Vilka [71]
Diamond is typically used in a flowchart or indicate a decision.
6 0
3 years ago
What hull type is best for use on ponds small lakes and calm rivers?
Vika [28.1K]
There are different types of hull, the hull type that is best for use on ponds, small lakes and calm rivers is the FLAT BOTTOM HULL. This is the type usually find in fishing boat, it has a flat spanning and a shallow draft which is very stable in calm weather. 
5 0
3 years ago
Can someone help me on drawing ER and Use case diagram on following scenarios. ASAP!!! Please :(
GalinKa [24]

Answer:

The ER Diagram is in the attachment. And I an including the membership details in the use case:

Applicants: Coach will ask for iD.

if the application is not registered, coach sends to registration department.

Applicants registers-->> shows registration ID-->> goes to account section

Submits the fee->> goes to coach again-->>coach asks for fee sjip-->> On yes-->> entrance allowed else-->> sent to account section

Applicants apply for course-->>if prerequisite is met, registration allowed

else-->>registration denied

Note: If registration is allowed the applicant is sent to account section and

Also note:

First check, then registration, then course prerequisite check,then account->entrance

If registered->direct entry.

Explanation:

The answer is self explanatory.

4 0
3 years ago
which resource do programmers sometimes have to refer to and use during planning the logical steps of the solution
Lerok [7]
The answer would be pseudocode.

<span>Pseudocode helps programs map out the logical pattern of how their program has to look. This means that by getting down the logical idea on how a program should look like, they will be able to implement this algorithm later on in the actual program. :)</span>
6 0
3 years ago
Read 2 more answers
All software, services and protocols not required by the system or necessary being disabled or not installed is called:____.
mihalych1998 [28]

Answer: Minimization

Explanation:

All the software, services and protocols

that's not required by the system or necessary being disabled or not installed is referred to as minimization

Minimization simply has to do with the uninstalling of the software that's useless and that's not using up the protocols as well.

Therefore, the correct option is D.

8 0
3 years ago
Other questions:
  • If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of s
    12·1 answer
  • A ________ is a set of programs that manipulate the data within a database.
    12·1 answer
  • What is tuple and attribute of a relation​
    11·1 answer
  • A network system administrator would typically be responsible for which of the following duties?
    7·2 answers
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • How did the invention of the printing press lead eventually to an increase in the diversity of religious expression?
    7·1 answer
  • Why is charles babbage known as father of computer?​
    10·1 answer
  • Ali is in the hospital about to undergo a brain-imaging process that involves taking many x-rays from different angles aided by
    9·1 answer
  • how risk can impact each of the seven domains of a typical IT infrastructure: User, Workstation, Local Area Network (LAN), Local
    7·1 answer
  • Explain how communication has helped to the staff in organization to reach their maximum delivery of service with efficience and
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!