0% found this document useful (0 votes)
20 views3 pages

Operations in A Splay Tree

Uploaded by

Abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Operations in A Splay Tree

Uploaded by

Abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Operations in a splay tree:

 Insertion: To insert a new element into the tree, start by performing a regular binary search tree insertion.
Then, apply rotations to bring the newly inserted element to the root of the tree.
 Deletion: To delete an element from the tree, first locate it using a binary search tree search. Then, if the
element has no children, simply remove it. If it has one child, promote that child to its position in the tree.
If it has two children, find the successor of the element (the smallest element in its right subtree), swap its
key with the element to be deleted, and delete the successor instead.
 Search: To search for an element in the tree, start by performing a binary search tree search. If the
element is found, apply rotations to bring it to the root of the tree. If it is not found, apply rotations to the
last node visited in the search, which becomes the new root.
 Rotation: The rotations used in a splay tree are either a Zig or a Zig-Zig rotation. A Zig rotation is used to
bring a node to the root, while a Zig-Zig rotation is used to balance the tree after multiple accesses to
elements in the same subtree.

Here’s a step-by-step explanation of the rotation operations:


 Zig Rotation: If a node has a right child, perform a right rotation to bring it to the root. If it has a left
child, perform a left rotation.
 Zig-Zig Rotation: If a node has a grandchild that is also its child’s right or left child, perform a double
rotation to balance the tree. For example, if the node has a right child and the right child has a left child,
perform a right-left rotation. If the node has a left child and the left child has a right child, perform a left -
right rotation.
 Note: The specific implementation details, including the exact rotations used, may vary depending on the
exact form of the splay tree.

Rotations in Splay Tree


 Zig Rotation
 Zag Rotation
 Zig – Zig Rotation
 Zag – Zag Rotation
 Zig – Zag Rotation
 Zag – Zig Rotation

1) Zig Rotation:
The Zig Rotation in splay trees operates in a manner similar to the single right rotation in AVL Tree rotations.
This rotation results in nodes moving one position to the right from their current location. For example,
consider the following scenario:

Zig Rotation (Single Rotation)

2) Zag Rotation:
The Zag Rotation in splay trees operates in a similar fashion to the single left rotation in AVL Tree rotations.
During this rotation, nodes shift one position to the left from their current location. For instance, consider the
following illustration:

Zag Rotation (Single left Rotation)

3) Zig-Zig Rotation:
The Zig-Zig Rotation in splay trees is a double zig rotation. This rotation results in nodes shifting two
positions to the right from their current location. Take a look at the following example for a better
understanding:

Zig-Zig Rotation (Double Right Rotation)

4) Zag-Zag Rotation:
In splay trees, the Zag-Zag Rotation is a double zag rotation. This rotation causes nodes to move two
positions to the left from their present position. For example:

Zag-Zag Rotation (Double left rotation)


5) Zig-Zag Rotation:

The Zig-Zag Rotation in splay trees is a combination of a zig rotation followed by a zag rotation. As a result
of this rotation, nodes shift one position to the right and then one position to the left from their current
location. The following illustration provides a visual representation of this concept:

Zig- Zag rotation

6) Zag-Zig Rotation:

The Zag-Zig Rotation in splay trees is a series of zag rotations followed by a zig rotation. This results in
nodes moving one position to the left, followed by a shift one position to the right from their current location.
The following illustration offers a visual representation of this concept:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy