Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA : Recursively complete the IsPerfectlyBalancedS method using one helper fun

ID: 3876012 • Letter: J

Question

JAVA : Recursively complete the IsPerfectlyBalancedS method using one helper function for a binary tree.

  

public class MyIntSET {

   private Node root;

   private static class Node {

       public final int key;

       public Node left, right;

       public Node(int key) { this.key = key; }

   }

   // tree is perfect if for every node, size of left == size of right

   // hint: in the helper, return -1 if the tree is not perfect, otherwise return the size

   public boolean isPerfectlyBalancedS() {

       return false;

   }

  

  

Explanation / Answer

A binary search tree is a binary tree with values at the nodes arranged such that the values at the nodes in the right subtree of a node is at least the value of the node and the values at nodes in the left subtree of the node is at most the value of the node.

It supports three operations:(Insert, Delete and Find). A balanced binary search tree performs all three operations in O(log n) time where n is the total number of nodes in the tree. The height is the maximum number of edges on a root-leaf path.

program ios given below :

}

public int size()

{

return 0;

}

}

}

Calling the main function the program will run properly. By using the test method you can test your tree .