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]
4 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]4 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
A total stranger is trolling Jack online. He’s offended and annoyed. How can Jack stop the troll in his or her tracks? (5 points
zvonat [6]

Answer:

log off the web page would be the best answer here or explaining why trolling is rude but log off the web page is the best one here

5 0
3 years ago
Read 2 more answers
______ provide visual representations of the options available for a given command
anygoal [31]

The visual representations is provided by the Gallery in the computer system.

Basically, gallery means the collection of pictures in a Computer.

  • Gallery is what enables systematic display and the management of distinct images in the computer.

  • A very good illustration is use of Clipart images. It is a ready made picture gallery available in the computer.

  • Every function on computer are represented with an icon, the icon images are enable through the Gallery.

In conclusion, the Visual representations of the options available for a given command is provided by the Gallery.

Read more about Gallery here

<em>brainly.com/question/2946480</em>

5 0
3 years ago
Plz help me I will mark as the brainlest I only need long answer plz help me ​
xxTIMURxx [149]

Strategy 1

*Testing for timing, high reliability and performance.

Reasons.

Every device and system configuration must be tested including the software setup,definitions and rules must be tested with an attempt to force the system and its intergrals to fail. Every failure(if there are any) must be evaluated and errors corrected.

Strategy 2

*Measuring response levels at the lowest set point of the alarm.

Reasons.

This is to check the trigger points of the alarms in the system and the response must be recorded as well as changing the intervals of alarm triggers so as to evaluate the time taken for the alarm to respond at the lowest point of it to be triggered.

7 0
3 years ago
Which wildcard character replaces a single character in the command-line interface?
pantera1 [17]

Answer:

? (the question mark)

Explanation:

The asterisk (*) matches one or more occurrences of any character, but the question mark matches exactly one.

6 0
3 years ago
Write, compile and test (show your test runs!) program that calculates and returns the fourth root of the number 81, which is 3.
lys-0071 [83]

Answer:

I am writing a JAVA program. Let me know if you want the program in some other programming language.

public class FourthRoot{ //class to calculate fourth root of 81

public static void main(String[] args) { //start of main() function body

   double square_root; //declares to hold the fourth root of 81

   double number=81; // number is assigned the value 81

/* calculates the fourth root of number using sqrt() method twice which means sqrt() of sqrt(). This is equivalent to pow(number,(0.25)) where pow is power function that computes the fourth root by raising the number 81 to the power of 0.25 which is 1/4 */

   square_root=Math.sqrt(Math.sqrt(number));

//displays the fourth root of 81 i.e. 3

     System.out.println("Fourth Root of 81 is "+ square_root); } }

Explanation:

The program is well explained in the comments given along with each statement of the program . Since it was the requirement of the program to user Math.sqrt() method so the fourth root of number= 81 is computed by taking the sqrt() of 81 twice which results in the fourth root of 81 which is 3.

So the first sqrt(81) is 9 and then the sqrt() of the result is taken again to get the fourth root of 81. So sqrt(9) gives 3. So the result of these two computations is stored in square_root variable and the last print statement displays this value of square_root i.e. the fourth root of number=81 which is 3.

Another way to implement the program is to first take sqrt(81) and store the result in a variable i.e. square_root. After this, again take the sqrt() of the result previously computed and display the final result.

public class FourthRoot{

   public static void main(String[] args) {

   double square_root;

   double number=81;

   square_root=Math.sqrt(number);

  System.out.println("Fourth Root of 81 is: "+ Math.sqrt(square_root)); } }

The program along with its output is attached in a screenshot.

5 0
4 years ago
Other questions:
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    5·1 answer
  • How many possible values will an eight bit audio sample have
    14·1 answer
  • A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
    12·1 answer
  • What types of projects require collaboration? en360
    15·1 answer
  • 9.6 Code Practice<br> Instructions<br> 1<br> Declare a 4x 5 array called N<br><br> Please helppp
    9·1 answer
  • Can anyone give me $2 (Reddem code/Promo Code)​
    15·2 answers
  • Which feature helps an edit-test-bug cycle work faster in the python programming language?
    15·2 answers
  • I need help ASP 3rd grade math ​
    11·2 answers
  • (50 POINTS!) Type the correct answer in the box.
    11·1 answer
  • He was called "The father of computing c_______ B_______​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!