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

What's hot (20)

PDF
Binary search tree operations
Kamran Zafar
 
PPTX
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
PPTX
Trees data structure
Sumit Gupta
 
PPTX
Trees (data structure)
Trupti Agrawal
 
PPT
1.8 splay tree
Krish_ver2
 
PPTX
B+ tree
ramya marichamy
 
PDF
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
8.binry search tree
Chandan Singh
 
PPTX
Quick sort
Jehat Hassan
 
PPT
17. Trees and Graphs
Intro C# Book
 
PDF
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
PPT
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
PPT
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
PPTX
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
ishawrb
 
PDF
LR Parsing
Eelco Visser
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPSX
Data structure stack&queue basics
Selvin Josy Bai Somu
 
Binary search tree operations
Kamran Zafar
 
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
Trees data structure
Sumit Gupta
 
Trees (data structure)
Trupti Agrawal
 
1.8 splay tree
Krish_ver2
 
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Queue in Data Structure
Janki Shah
 
8.binry search tree
Chandan Singh
 
Quick sort
Jehat Hassan
 
17. Trees and Graphs
Intro C# Book
 
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
ishawrb
 
LR Parsing
Eelco Visser
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Data structure stack&queue basics
Selvin Josy Bai Somu
 

Similar to Lecture 14 splay tree (20)

PPTX
Splay trees
beenish24
 
PPTX
Splay Tree Presentation Slides
Muhammad Shahbaz
 
PPT
Splay trees
Amaan Shaikh
 
PPTX
Splay trees by NIKHIL ARORA (www.internetnotes.in)
nikhilarora2211
 
PPT
Splay Tree Algorithm
sathish sak
 
PPTX
Detailed Data structures in splay tree .pptx
nagulanaveen2
 
PPTX
Splay tree && euler tour tree
Rezwanul Haque
 
PPT
Splay tree
Rajendran
 
PPTX
Splay tree
hina firdaus
 
PPTX
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
PPTX
Splay tree C++
Dewan Farhat AL-Jami
 
PPT
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
RAtna29
 
DOCX
Splay trees balance trees in a different way from AVL trees. A.docx
mckellarhastings
 
PPTX
Advanced Trees
Selvaraj Seerangan
 
DOCX
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
mary772
 
PDF
DOC-20240604-WA0010..htbevscdvrhegexrgvrv
parvathireddy2670
 
PDF
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
PPTX
Trees in data structure
Anusruti Mitra
 
Splay trees
beenish24
 
Splay Tree Presentation Slides
Muhammad Shahbaz
 
Splay trees
Amaan Shaikh
 
Splay trees by NIKHIL ARORA (www.internetnotes.in)
nikhilarora2211
 
Splay Tree Algorithm
sathish sak
 
Detailed Data structures in splay tree .pptx
nagulanaveen2
 
Splay tree && euler tour tree
Rezwanul Haque
 
Splay tree
Rajendran
 
Splay tree
hina firdaus
 
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
Splay tree C++
Dewan Farhat AL-Jami
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
RAtna29
 
Splay trees balance trees in a different way from AVL trees. A.docx
mckellarhastings
 
Advanced Trees
Selvaraj Seerangan
 
Coding Assignment 3CSC 330 Advanced Data Structures, Spri.docx
mary772
 
DOC-20240604-WA0010..htbevscdvrhegexrgvrv
parvathireddy2670
 
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
Trees in data structure
Anusruti Mitra
 
Ad

More from Abirami A (12)

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

Recently uploaded (20)

PPTX
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPT
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPT
inherently safer design for engineering.ppt
DhavalShah616893
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
PPTX
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PDF
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
PDF
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PDF
A presentation on the Urban Heat Island Effect
studyfor7hrs
 
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Oxygen Co2 Transport in the Lungs(Exchange og gases)
SUNDERLINSHIBUD
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
inherently safer design for engineering.ppt
DhavalShah616893
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
POWER PLANT ENGINEERING (R17A0326).pdf..
haneefachosa123
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Thermal runway and thermal stability.pptx
godow93766
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
A presentation on the Urban Heat Island Effect
studyfor7hrs
 

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