Tree Rotation - Illustration

Illustration

The right rotation operation as shown in the image above is performed with Q as the root and hence is a right rotation on, or rooted at, Q. This operation results in a rotation of the tree in the clockwise direction. The inverse operation is the left rotation, which results in a movement in a counter-clockwise direction (the left rotation shown above is rooted at P). The key to understanding how a rotation functions is to understand its constraints. In particular the order of the leaves of the tree (when read left to right for example) cannot change (another way to think of it is that the order that the leaves would be visited in a depth first search must be the same after the operation as before). Another constraint is the main property of a binary search tree, namely that the right child is greater than the parent and the left child is lesser than the parent. Notice that the right child of a left child of the root of a sub-tree (for example node B in the diagram for the tree rooted at Q) can become the left child of the root, that itself becomes the right child of the "new" root in the rotated sub-tree, without violating either of those constraints. As you can see in the diagram, the order of the leaves doesn't change. The opposite operation also preserves the order and is the second kind of rotation.

Assuming this is a binary search tree, as stated above, the elements must be interpreted as variables that can be compared to each other. The alphabetic characters above are used as placeholders for these variables.

Read more about this topic:  Tree Rotation

Famous quotes containing the word illustration:

    An illustration is no argument,—nor do I maintain the wiping of a looking-glass clean, to be a syllogism;Mbut you all, may it please your worships, see the better for it.
    Laurence Sterne (1713–1768)

    Each truth that a writer acquires is a lantern, which he turns full on what facts and thoughts lay already in his mind, and behold, all the mats and rubbish which had littered his garret become precious. Every trivial fact in his private biography becomes an illustration of this new principle, revisits the day, and delights all men by its piquancy and new charm.
    Ralph Waldo Emerson (1803–1882)

    What is character but the determination of incident? What is incident but the illustration of character?
    Henry James (1843–1916)