Balance binary tree for interview training Adjustment

Source: Internet
Author: User

There are four ways to balance a binary tree.

Respectively

Ll type

One-way right-hand balance processing: as the left subtree of the Left subtree of A is inserted into a node, the balance factor of A is increased from 1 to 2, which means the subtree of the root of a is out of balance, a clockwise rotation is required.

Rr type

One-way left-hand balance processing: As a is inserted to the right tree of the right child root node of A, the balance of a is changed from-1 to-2, which makes a out of balance. Perform a clockwise rotation to the left.

LR type

The right subtree of the Left subtree of a loses its balance because it is inserted to a node in the right subtree of the root. Rotate twice, first left and then right

RL type

The left subtree of the right subtree of A is not balanced because it is inserted into the node. Rotate twice, first right, then left.

The advantage of using the Balance Tree is that the structure of the tree is better, thus improving the search operation speed. The disadvantage is that the insert and delete operations become complicated, reducing their computing speed. Operations on the imbalance caused by the deletion of nodes in the binary search tree are more complex than the insertion of nodes.

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.