SlideShare a Scribd company logo
6
Most read
7
Most read
9
Most read
Lecture 14
Splay Tree
Abirami Sivaprasad
Splay Tree
 A splay tree is a self-balancing binary search tree with an additional
property that recently accessed elements can be re-accessed fast.
 It is said to be an efficient binary tree because it performs basic
operations such as insertion, search and deletion operations in
O(log(n)) time.
 When a node in a splay tree is accessed, it is rotated or "splayed" to
the root thereby changing the structure of the tree.
 Since the most frequently accessed node is always moved closer to
the starting point of the search (or the root node), those nodes are
therefore located faster.
 A simple idea behind it is that if an element is accessed, it is likely
that it will be accessed again.
Advantages
 A splay tree gives good performance for search, insert and
delete operations.
 Splay trees are considerably simpler to implement than
other self-balancing binary search trees, such as red-black
trees or AVL trees, while their average-case performance is
just as efficient.
 Splay tree minimizes memory requirements .
 Unlike other types of self balancing trees, splay trees gives
good performance (O(log n)) with nodes containing
identical keys.
Disadvantages
 While sequentially accessing all the nodes of the
tree in a sorted order, the resultant tree becomes
completely unbalanced. This takes n accesses of
the tree in which each access takes O(log n) time.
 For uniform access, the performance of a splay
tree will be considerably worse than a somewhat
balanced simple binary search tree.
Splaying
Factors to consider:
 Whether N is the left or right child of its parent P
 Whether P is the root or not, and if not
 Whether P is the left or right child of its parent, G
(N’s grandparent).
Zig Step
P
N
T
1
T
2
T
3
N
T
1
P
T
2
T
3
 The zig operation is done when P (the parent of N) is the root of
the splay tree.
 In the zig step, the tree is rotated on the edge between N and P.
 Zig step is usually performed as the last step in a splay operation
and only when N has odd depth at the beginning of the
operation.
Zig-zig Step:
 The zig- zig operation is performed when P is not the root. In
addition to this, N and P are either both right children or are
both left children of their parent’s.
 Figure shows the case where N and P are the left children.
During the zig- zig step, first the tree is rotated on the edge
joining P and its parent G, and then again rotated on the edge
joining N and P.
G
P
T
4
N
T
1
T
2
T
3
P
G
T
4
N
T
1
T
2
N
T
1
P
G
T
4
T
2
T
3
Zig-zag Step:
 The zig-zag operation is performed when P is not the root.
 In addition to this, N is a right child of P and P is a left child of
G or vice versa.
 In zig-zag step, the tree is first rotated on the edge between N
and P, and then rotated on the edge between P and G.
G
P
T
4
T
1
N
T
2
T
3
G
N
T
4
P
T
1
T
2
T
3
N
G
P
T
1
T
2 T
1
T
2
Exercise
1. Construct the Splay Tree for the following
sequence
10, 30, 50, 40, 60,70
2. Construct the Splay Tree for the following
sequence
34, 67, 45, 89, 12, 37
Thank U

More Related Content

PDF
Binary search tree operations
PPTX
Depth-First Search
PPTX
Trees in data structures
PPTX
Binary Search Tree in Data Structure
PPTX
Different Sorting tecniques in Data Structure
PPTX
Stack & Queue using Linked List in Data Structure
PPT
Splay trees
PPTX
Queue in Data Structure
Binary search tree operations
Depth-First Search
Trees in data structures
Binary Search Tree in Data Structure
Different Sorting tecniques in Data Structure
Stack & Queue using Linked List in Data Structure
Splay trees
Queue in Data Structure

What's hot (20)

PPSX
Data Structure (Tree)
PPTX
Avl trees
PPT
PPT
1.8 splay tree
PPTX
Polynomial reppresentation using Linkedlist-Application of LL.pptx
PPTX
Splay Tree Presentation Slides
PDF
Re永続データ構造が分からない人のためのスライド
PPTX
Validation based protocol
PPTX
Avl trees final
PPTX
Tree Traversal
PPT
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
PPTX
Tree and graph
PPTX
AVL Tree
PDF
Stack push pop
PDF
論文紹介:The wavelet matrix
PDF
Algorithm and Data Structure - Queue
PPT
Backtracking
PPT
Graphs bfs dfs
Data Structure (Tree)
Avl trees
1.8 splay tree
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Splay Tree Presentation Slides
Re永続データ構造が分からない人のためのスライド
Validation based protocol
Avl trees final
Tree Traversal
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
Tree and graph
AVL Tree
Stack push pop
論文紹介:The wavelet matrix
Algorithm and Data Structure - Queue
Backtracking
Graphs bfs dfs
Ad

More from Abirami A (12)

PPTX
Lecture 3 time complexity
PPTX
Lecture 2 Data Structure Introduction
PPTX
Lecture 1 introduction
PPTX
Lecture 16 graphs traversal
PPTX
Lecture 16 graph introduction
PPTX
Lecture 6 disjoint set
PPTX
Lecture 8 tree traversal
PPTX
Lecture 9 b tree
PPTX
Lecture 7 bst
PPTX
Lecture 6 tree traversal
PPT
Lecture 5 tree.pptx
PPTX
Lecture 1 sorting insertion & shell sort
Lecture 3 time complexity
Lecture 2 Data Structure Introduction
Lecture 1 introduction
Lecture 16 graphs traversal
Lecture 16 graph introduction
Lecture 6 disjoint set
Lecture 8 tree traversal
Lecture 9 b tree
Lecture 7 bst
Lecture 6 tree traversal
Lecture 5 tree.pptx
Lecture 1 sorting insertion & shell sort
Ad

Recently uploaded (20)

PPT
Project quality management in manufacturing
PDF
PPT on Performance Review to get promotions
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
composite construction of structures.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Artificial Intelligence
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
introduction to datamining and warehousing
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Well-logging-methods_new................
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Digital Logic Computer Design lecture notes
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Mechanical Engineering MATERIALS Selection
Project quality management in manufacturing
PPT on Performance Review to get promotions
Internet of Things (IOT) - A guide to understanding
Automation-in-Manufacturing-Chapter-Introduction.pdf
composite construction of structures.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Artificial Intelligence
bas. eng. economics group 4 presentation 1.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
introduction to datamining and warehousing
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Well-logging-methods_new................
R24 SURVEYING LAB MANUAL for civil enggi
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Digital Logic Computer Design lecture notes
Model Code of Practice - Construction Work - 21102022 .pdf
Mechanical Engineering MATERIALS Selection

Lecture 14 splay tree

  • 2. Splay Tree  A splay tree is a self-balancing binary search tree with an additional property that recently accessed elements can be re-accessed fast.  It is said to be an efficient binary tree because it performs basic operations such as insertion, search and deletion operations in O(log(n)) time.  When a node in a splay tree is accessed, it is rotated or "splayed" to the root thereby changing the structure of the tree.  Since the most frequently accessed node is always moved closer to the starting point of the search (or the root node), those nodes are therefore located faster.  A simple idea behind it is that if an element is accessed, it is likely that it will be accessed again.
  • 3. Advantages  A splay tree gives good performance for search, insert and delete operations.  Splay trees are considerably simpler to implement than other self-balancing binary search trees, such as red-black trees or AVL trees, while their average-case performance is just as efficient.  Splay tree minimizes memory requirements .  Unlike other types of self balancing trees, splay trees gives good performance (O(log n)) with nodes containing identical keys.
  • 4. Disadvantages  While sequentially accessing all the nodes of the tree in a sorted order, the resultant tree becomes completely unbalanced. This takes n accesses of the tree in which each access takes O(log n) time.  For uniform access, the performance of a splay tree will be considerably worse than a somewhat balanced simple binary search tree.
  • 5. Splaying Factors to consider:  Whether N is the left or right child of its parent P  Whether P is the root or not, and if not  Whether P is the left or right child of its parent, G (N’s grandparent).
  • 6. Zig Step P N T 1 T 2 T 3 N T 1 P T 2 T 3  The zig operation is done when P (the parent of N) is the root of the splay tree.  In the zig step, the tree is rotated on the edge between N and P.  Zig step is usually performed as the last step in a splay operation and only when N has odd depth at the beginning of the operation.
  • 7. Zig-zig Step:  The zig- zig operation is performed when P is not the root. In addition to this, N and P are either both right children or are both left children of their parent’s.  Figure shows the case where N and P are the left children. During the zig- zig step, first the tree is rotated on the edge joining P and its parent G, and then again rotated on the edge joining N and P. G P T 4 N T 1 T 2 T 3 P G T 4 N T 1 T 2 N T 1 P G T 4 T 2 T 3
  • 8. Zig-zag Step:  The zig-zag operation is performed when P is not the root.  In addition to this, N is a right child of P and P is a left child of G or vice versa.  In zig-zag step, the tree is first rotated on the edge between N and P, and then rotated on the edge between P and G. G P T 4 T 1 N T 2 T 3 G N T 4 P T 1 T 2 T 3 N G P T 1 T 2 T 1 T 2
  • 9. Exercise 1. Construct the Splay Tree for the following sequence 10, 30, 50, 40, 60,70 2. Construct the Splay Tree for the following sequence 34, 67, 45, 89, 12, 37