Balanced two-pronged tree

Source: Internet
Author: User
Balanced binary tree Balanced binary tree also known as AVL tree. It is either an empty tree or a two-fork tree with the following properties: Its Saozi right subtree is a balanced binary tree, and the difference in depth of the Saozi right subtree is no more than 1. If the balance factor BF (Balance) of the two-fork tree node Facter) is defined as the depth of the left subtree of the node minus the depth of its right subtree, the balance factor of all nodes on the balanced binary tree can be only -1,0 and 1. As long as the absolute value of the balance factor of a node on a two-fork tree is greater than 1, the two-tree is unbalanced. The rule of adjustment after loss of balance can be summed up in the following 4 cases: (1) Unidirectional right-balance treatment: Because the Zogen node in the *a of the left sub-tree inserted node, *a balance factor from 1 to 2, resulting in the *a as the root of the subtree out of balance, you need to do a clockwise rotation to the right. (2) One-way left-balance processing: Due to the right subtree node in the *a of the right sub-tree insert node, *a balance factor from 1 to 2, resulting in the *a as the root node of the sub-tree loss of balance, you need to do a left counterclockwise rotation operation. (3) Two-way rotation (first left and right) balance treatment: Due to the Zogen node in the *a of the right sub-tree, the *a balance factor from 1 to 2, resulting in the *a as the root node of the sub-tree loss of balance, it is necessary to carry out two rotations (first right-handed left) operation.

Balanced two-pronged tree

Contact Us

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.