SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Central processor organization
Central processor organizationCentral processor organization
Central processor organization
Prof. Dr. K. Adisesha
 
Object detection with deep learning
Object detection with deep learningObject detection with deep learning
Object detection with deep learning
Sushant Shrivastava
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
koolkampus
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
sandeep54552
 
Computer Vision
Computer VisionComputer Vision
Computer Vision
Ameer Mohamed Rajah
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Image super resolution
Image super resolutionImage super resolution
Image super resolution
Akshay Hazare
 
ALU
ALUALU
ALU
Ramasubbu .P
 
K-Nearest Neighbor Classifier
K-Nearest Neighbor ClassifierK-Nearest Neighbor Classifier
K-Nearest Neighbor Classifier
Neha Kulkarni
 
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Beckham000
 
Basics of pixel neighbor.
Basics of pixel neighbor.Basics of pixel neighbor.
Basics of pixel neighbor.
raheel rajput
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formats
Mazin Alwaaly
 
KERNAL ARCHITECTURE
KERNAL ARCHITECTUREKERNAL ARCHITECTURE
KERNAL ARCHITECTURE
lakshmipanat
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
sandeep54552
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Introduction to ML (Machine Learning)
Introduction to ML (Machine Learning)Introduction to ML (Machine Learning)
Introduction to ML (Machine Learning)
SwatiTripathi44
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
prabhakar jalasutram
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set Computing
Tushar Swami
 
9.bst(contd.) avl tree
9.bst(contd.) avl tree9.bst(contd.) avl tree
9.bst(contd.) avl tree
Chandan Singh
 
Object detection with deep learning
Object detection with deep learningObject detection with deep learning
Object detection with deep learning
Sushant Shrivastava
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
koolkampus
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
sandeep54552
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Image super resolution
Image super resolutionImage super resolution
Image super resolution
Akshay Hazare
 
K-Nearest Neighbor Classifier
K-Nearest Neighbor ClassifierK-Nearest Neighbor Classifier
K-Nearest Neighbor Classifier
Neha Kulkarni
 
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...Solutions manual for logic and computer design fundamentals 5th edition by ma...
Solutions manual for logic and computer design fundamentals 5th edition by ma...
Beckham000
 
Basics of pixel neighbor.
Basics of pixel neighbor.Basics of pixel neighbor.
Basics of pixel neighbor.
raheel rajput
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formats
Mazin Alwaaly
 
KERNAL ARCHITECTURE
KERNAL ARCHITECTUREKERNAL ARCHITECTURE
KERNAL ARCHITECTURE
lakshmipanat
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Introduction to ML (Machine Learning)
Introduction to ML (Machine Learning)Introduction to ML (Machine Learning)
Introduction to ML (Machine Learning)
SwatiTripathi44
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set Computing
Tushar Swami
 
9.bst(contd.) avl tree
9.bst(contd.) avl tree9.bst(contd.) avl tree
9.bst(contd.) avl tree
Chandan Singh
 

Similar to Lecture 14 splay tree (9)

Splay Tree Presentation Slides
Splay Tree Presentation SlidesSplay Tree Presentation Slides
Splay Tree Presentation Slides
Muhammad Shahbaz
 
Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)
nikhilarora2211
 
Splay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptxSplay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
Splay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptxSplay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay tree
Krish_ver2
 
Splay trees
Splay treesSplay trees
Splay trees
beenish24
 
Splay tree && euler tour tree
Splay tree && euler tour treeSplay tree && euler tour tree
Splay tree && euler tour tree
Rezwanul Haque
 
Splay trees
Splay treesSplay trees
Splay trees
Amaan Shaikh
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
Splay Tree Presentation Slides
Splay Tree Presentation SlidesSplay Tree Presentation Slides
Splay Tree Presentation Slides
Muhammad Shahbaz
 
Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)
nikhilarora2211
 
Splay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptxSplay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
Splay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptxSplay Trees Data Structure and Algorithm (DSA).pptx
Splay Trees Data Structure and Algorithm (DSA).pptx
NicoleAngelaGilaRamo
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay tree
Krish_ver2
 
Splay tree && euler tour tree
Splay tree && euler tour treeSplay tree && euler tour tree
Splay tree && euler tour tree
Rezwanul Haque
 
B Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay treeB Tree, Introduction ,example,Splay tree
B Tree, Introduction ,example,Splay tree
VikasNirgude2
 
Ad

More from Abirami A (12)

Lecture 3 time complexity
Lecture 3 time complexityLecture 3 time complexity
Lecture 3 time complexity
Abirami A
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure Introduction
Abirami A
 
Lecture 1 introduction
Lecture 1 introductionLecture 1 introduction
Lecture 1 introduction
Abirami A
 
Lecture 16 graphs traversal
Lecture 16 graphs traversalLecture 16 graphs traversal
Lecture 16 graphs traversal
Abirami A
 
Lecture 16 graph introduction
Lecture 16 graph introductionLecture 16 graph introduction
Lecture 16 graph introduction
Abirami A
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
Abirami A
 
Lecture 8 tree traversal
Lecture 8 tree traversalLecture 8 tree traversal
Lecture 8 tree traversal
Abirami A
 
Lecture 9 b tree
Lecture 9 b treeLecture 9 b tree
Lecture 9 b tree
Abirami A
 
Lecture 7 bst
Lecture 7 bstLecture 7 bst
Lecture 7 bst
Abirami A
 
Lecture 6 tree traversal
Lecture 6 tree traversalLecture 6 tree traversal
Lecture 6 tree traversal
Abirami A
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 
Lecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sortLecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sort
Abirami A
 
Lecture 3 time complexity
Lecture 3 time complexityLecture 3 time complexity
Lecture 3 time complexity
Abirami A
 
Lecture 2 Data Structure Introduction
Lecture 2 Data Structure IntroductionLecture 2 Data Structure Introduction
Lecture 2 Data Structure Introduction
Abirami A
 
Lecture 1 introduction
Lecture 1 introductionLecture 1 introduction
Lecture 1 introduction
Abirami A
 
Lecture 16 graphs traversal
Lecture 16 graphs traversalLecture 16 graphs traversal
Lecture 16 graphs traversal
Abirami A
 
Lecture 16 graph introduction
Lecture 16 graph introductionLecture 16 graph introduction
Lecture 16 graph introduction
Abirami A
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
Abirami A
 
Lecture 8 tree traversal
Lecture 8 tree traversalLecture 8 tree traversal
Lecture 8 tree traversal
Abirami A
 
Lecture 9 b tree
Lecture 9 b treeLecture 9 b tree
Lecture 9 b tree
Abirami A
 
Lecture 7 bst
Lecture 7 bstLecture 7 bst
Lecture 7 bst
Abirami A
 
Lecture 6 tree traversal
Lecture 6 tree traversalLecture 6 tree traversal
Lecture 6 tree traversal
Abirami A
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 
Lecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sortLecture 1 sorting insertion & shell sort
Lecture 1 sorting insertion & shell sort
Abirami A
 
Ad

Recently uploaded (20)

Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink DisplayHow to Build a Desktop Weather Station Using ESP32 and E-ink Display
How to Build a Desktop Weather Station Using ESP32 and E-ink Display
CircuitDigest
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 

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
  翻译: