The rotation of the tree of Learning notes of a binary tree

Source: Internet
Author: User

Tree rotation is a seed-tree adjustment operation in a two-fork tree, and each rotation does not affect the result of a mid-order traversal of the two-forked tree.
Tree rotations are typically applied where the local balance of the tree needs to be adjusted.

>> L-and right-handed

The rotation of the tree has two basic operations, namely the left-hand (counterclockwise rotation) and the right-handed (clockwise rotation).

The tree rotation consists of two different ways, namely the left rotation (with p as the hinge) and the right rotation (with Q as the hinge). The two rotations are mirrored, and the inverse of each other.

The initial and final states of the subtree are indicated during the rotation of two kinds of trees.

        +---+                          +---+        | Q |                          | P |        +---+                          +---+       /     \ Right     rotation     /         +---+   +---+  ------------->  +---+   +---+    | P |   | Z |                  | X |   | Q |    +---+   ---+  <-------------  +---+   +---+   /\ Left          rotation         /     +--- +   +---+                          +---+   +---+| X |   | Y |                          | Y |   | Z |+---+   +---+                          +---+   +---+

Where you rotate the detailed steps such as R0, R1, R2 as shown in three steps, the left rotation is as shown in the three steps of L0, L1, L2.

                                                                  __                                     /                                       +---+                      /  +---+ |                     Q | /   |                           Q | +---+     +---+              +---+ /    +---+        +---+              |    P | /\ R1 | P |//\ +---+ |     Q | R0 +---+/+---+-----> +---+/+---+ R2 |        P | +---+----->/\/|         Z | /        /      | Z |   -----> +---+/\ +---+ +---+ +---+ +---+ +---+ +---+/+---+ +---+      |   X | |                Y | |    X | |                 Y | +---+   +---+    |   P | |      Z | +---+   +---+                +---+    +---+                 |   X | |    Q |                                              +---+   +---+              __    +---+   +---+   /     \                    /  \                                                        /     +---+   + ---+ L2 +---+ \ +---+ L0 +---+ +---+|   X | |   Y | <-----|   P | \                      |              P | <-----|   Y | |                          Z |+---+ +---+ +---+ \ +---+ L1 +---+ +---+ +---+ +---+ /     \    \|    Q | <-----/\ |                       Q | +---+     \    +---+           +---+     \   +---+                       |      X | \        \          |      X | \ /                            +---+     +---+    +---+       +---+     +---+   +---+                                 |    Y | |                 Z | |   Y | |                                 Z | +---+    +---+                 +---+   +---+
adjustment of the >>avl tree

The basic operations of the AVL tree generally involve the same algorithms that operate in an unbalanced two-fork search tree. But to do one or more of the so-called "AVL rotations" beforehand or later.

Organized from wikipedia

The rotation of the tree of Learning notes of a binary 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.