I am not able to understand this code

public boolean isBalanced() {
return this.isBalanced(this.root).isBalanced;
}

	private BalancedPair isBalanced(Node node) {
        
		
	}

	private class BalancedPair {
		int height;
		boolean isBalanced;
	}

// i need to write height function??

Hey @Vipin_coder

  • Make a balancedPair which stores information about both the height of a node and whether its balanced or not.
  • Recursively compute the height and isbalanced property for both the left and right subtree.
  • Check if a particular node satisfies the balancing conditions or not.
  • If all the conditions are satisfied, the isbalanced value for the particular node is true. Else false.

i need to write height function ?? or how can i calculate height?

No need to write height function
public int ht() {
return ht(this.root);
}

private int ht(Node root) {
	if (root == null) {
		return -1;
	}
	int lh = ht(root.left);
	int rh = ht(root.right);
	return Math.max(lh, rh) + 1;

	// return 0;
}

without height function , how can i solve this question??

public boolean isBalanced() {
return this.isBalanced(this.root).isBalanced;

	}

	private BalancedPair isBalanced(Node node) {
		// write your code here
        if(node==null){
            BalancedPair bs = new BalancedPair();
            bs.height=-1;
            bs.isBalanced=true;
            return bs;
        }
        BalancedPair lbp = isBalanced(node.left);
        BalancedPair rbp = isBalanced(node.right);
        BalancedPair mp = new BalancedPair();
        mp.height = Math.max(lbp.height, rbp.height) + 1;

        	boolean lb = lbp.isBalanced;
	        boolean rb = rbp.isBalanced;
            int h = Math.abs(lbp.height-rbp.height);
            if(h<=1 && (lb && rb)){
                mp.isBalanced=true;
            }else{
                mp.isBalanced= false;
            }

        return mp;
	}