Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views6 pages

Splay Tree Datastructure

A splay tree is a self-adjusting binary search tree where recently accessed elements are moved to the root through a process called splaying. This structure optimizes access to frequently used elements by rearranging the tree with rotation operations such as Zig, Zag, Zig-Zig, Zag-Zag, Zig-Zag, and Zag-Zig. The insertion operation involves adding a new node and then splaying it to the root, ensuring the tree remains a binary search tree but not necessarily balanced.

Uploaded by

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

Splay Tree Datastructure

A splay tree is a self-adjusting binary search tree where recently accessed elements are moved to the root through a process called splaying. This structure optimizes access to frequently used elements by rearranging the tree with rotation operations such as Zig, Zag, Zig-Zig, Zag-Zag, Zig-Zag, and Zag-Zig. The insertion operation involves adding a new node and then splaying it to the root, ensuring the tree remains a binary search tree but not necessarily balanced.

Uploaded by

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

Splay Tree Datastructure

Splay tree is another variant of a binary search tree. In a splay tree, recently accessed element is placed at the root

of the tree. A splay tree is defined as follows...

Splay Tree is a self - adjusted Binary Search Tree in which every operation on element rearranges the tree so

that the element is placed at the root position of the tree.

In a splay tree, every operation is performed at the root of the tree. All the operations in splay tree are involved with a

common operation called "Splaying".

Splaying an element, is the process of bringing it to the root position by performing suitable rotation

operations.

In a splay tree, splaying an element rearranges all the elements in the tree so that splayed element is placed at the

root of the tree.

By splaying elements we bring more frequently used elements closer to the root of the tree so that any operation on

those elements is performed quickly. That means the splaying operation automatically brings more frequently used

elements closer to the root of the tree.

Every operation on splay tree performs the splaying operation. For example, the insertion operation first inserts the

new element using the binary search tree insertion process, then the newly inserted element is splayed so that it is

placed at the root of the tree. The search operation in a splay tree is nothing but searching the element using binary

search process and then splaying that searched element so that it is placed at the root of the tree.

In splay tree, to splay any element we use the following rotation operations...

Rotations in Splay Tree

 1. Zig Rotation

 2. Zag Rotation
 3. Zig - Zig Rotation

 4. Zag - Zag Rotation

 5. Zig - Zag Rotation

 6. Zag - Zig Rotation

Example

Zig Rotation

The Zig Rotation in splay tree is similar to the single right rotation in AVL Tree rotations. In zig rotation, every node

moves one position to the right from its current position. Consider the following example...

Zag Rotation

The Zag Rotation in splay tree is similar to the single left rotation in AVL Tree rotations. In zag rotation, every node

moves one position to the left from its current position. Consider the following example...
Zig-Zig Rotation

The Zig-Zig Rotation in splay tree is a double zig rotation. In zig-zig rotation, every node moves two positions to the

right from its current position. Consider the following example...

Zag-Zag Rotation

The Zag-Zag Rotation in splay tree is a double zag rotation. In zag-zag rotation, every node moves two positions to

the left from its current position. Consider the following example...
Zig-Zag Rotation

The Zig-Zag Rotation in splay tree is a sequence of zig rotation followed by zag rotation. In zig-zag rotation, every

node moves one position to the right followed by one position to the left from its current position. Consider the

following example...
Zag-Zig Rotation

The Zag-Zig Rotation in splay tree is a sequence of zag rotation followed by zig rotation. In zag-zig rotation, every

node moves one position to the left followed by one position to the right from its current position. Consider the

following example...

Every Splay tree must be a binary search tree but it is need not to be balanced tree.

Insertion Operation in Splay Tree

The insertion operation in Splay tree is performed using following steps...

 Step 1 - Check whether tree is Empty.

 Step 2 - If tree is Empty then insert the newNode as Root node and exit from the operation.

 Step 3 - If tree is not Empty then insert the newNode as leaf node using Binary Search tree insertion logic.

 Step 4 - After insertion, Splay the newNode

You might also like