AVL (Balance tree)

Source: Internet
Author: User

The balance tree is actually a two-fork tree with a special structure. Because the performance of the binary tree search algorithm depends on the structure of the two-fork tree, if the binary search tree is constructed linearly, the search algorithm is inefficient. If the structure is reasonable, the lookup speed is faster. In fact, the smaller the height of the tree, the faster the lookup rate. You can compare the following two two fork trees which are more efficient when retrieving:

An AVL tree (also called a balanced tree) in which the binary tree structure is approximate to equilibrium. The AVL tree has the following characteristics:

1. The maximum of the height difference of the Saozi right subtree of the root is 1.
2. The Saozi right subtree of the root is an AVL tree.

Supplemental: Duplicate values are not allowed in the AVL tree, which is exactly the same as our purpose.

When inserting operations against the AVL tree, we achieve the goal of ensuring the height difference through "rotation". As shown in figure:

The reconstruction process of AVL tree is "rotation", there are two types of rotation, left-handed and right-handed. The common methods of rotation are as follows:

As an example:

Note: All of the above pictures are from D.s.malik and P.s.nair's "Data Structures Using Java" book.

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.