# Determine if a binary tree is a balanced binary tree __class

Source: Internet
Author: User
Tags static class

```To determine whether a binary tree is balanced binary tree public class avltree{///Two Fork tree node definition public static class node{public int value;
Public Node left;

public Node right;
public Node (int data) {this.value=data; }//Determine whether a binary tree is a balanced binary tree (using the second order traversal of a binary tree) public static Boolean Isavl (Node head) {boolean[]res=new boolean[1]
;
Res[0]=true;

return res[0]; ///Recursive call gets the height of the subtree and whether it is a balanced binary tree public static int getheight (Node head,int level,boolean[]res) {if (head==null) {Retu
RN level;
if (!res[0]) {return level;
}//Right subtree height int rh=getheight (head.right,level+1,res);
if (!res[0]) {return level;
}//Left/right subtree height difference if (math.abs (LH-RH) >1) {res[0]=false;
Return Math.max (LH,RH);   public static void Main (string[] args) {/** 1 2 3 4 5 6 7 */Node head = New Node (1);

/** 1 2 4/Node Node=new node (1);
Node.left=new Node (2);
Node.left.left=new Node (4);

Node.right=new Node (3);

System.out.println (ISAVL (node)); }
}```

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.