SlideShare a Scribd company logo
1 of 29
Splay Trees
https://docs.google.com/presentation/d/1J8sIJDKi9DfnZJ5-VMeGtPqQ8nFfJ_mQVxz4oPEj-KA/edit#slide=id.p
Fundamental Concept
Carefully rearrange (using tree rotation
operation) the tree so that the recently
accessed elements are brought to the top and
at the same time, the tree is also
approximately balanced.
Splay Tree
Splay is a binary search tree in which recently accessed
keys are quick to access again.
When an element is accessed, it is moved to the root using
series of rotation operations so that it is quick to access
again.
The tree is also approximately balanced while rearranging.
The process of rearranging is called splaying.
Operations
• Splay tree includes all the operations of BST along with splay
operation.
• Splay operation rearranges the tree so that the element is placed
at the top of the tree.
• Let x be the accessed node and let p be the parent node of x.
Three types of splay steps:
• Zig step (one left rotation or one right rotation)
o carried out when p is the root (last step in the splay operation)
• Zig-Zig step (left-left rotation or right-right rotation)
o carried out when p is not the root and both x,p are either right
or left children.
• Zig-Zag step (left-right rotation or right-left rotation)
o carried out when p is not the root and x is left and p is right or
vice versa
Operations (contd)
Insertion
•Insert the node using the normal BST insert procedure
•splay the newly inserted node to the root
Deletion
•delete using normal BST delete procedure
•splay the parent of removed node to the root
Search
•Search using normal BST search procedure
•splay the accessed item to the root
Splay Operation - Pseudo code
void splay(struct node *x)
{
struct node *p,*g;
/*check if node x is the root node*/
if (x->parent == NULL) { root = x; return; }
/*Performs Zig step*/
else if ( x->parent == root)
{
if(x == x->parent->left) rightrotation(root);
else
leftrotation(root);
}
else
{
p = x->parent; /*now points to parent of x*/
g = p->parent; /*now points to grand parent of x*/
/*when x is left and x's parent is left*/
if(x==p->left and p==g->left) //Zig-zig
{ rightrotation(g); rightrotation(p); }
/*step when x is right and x's parent is right*/
else if (x==p->right and p==g->right) //Zig-zig
{ leftrotation(g); leftrotation(p); }
/*when x's is right and x's parent is left*/
else if (x==p->right and p==g->left) // Zig-zag
{ leftrotation(p); rightrotation(g); }
/*when x's is left and x's parent is right*/
else if (x==p->left and p==g->right) //Zig-zag
{ rightrotation(p); leftrotation(g); }
splay(x);
}
Splay Trees and B-Trees - Lecture 9
8
• Let X be a non-root node with ≥ 2 ancestors.
• P is its parent node.
• G is its grandparent node.
P
G
X
G
P
X
G
P
X
G
P
X
Splay Tree Terminology
Zig-Zig and Zig-Zag
Splay Trees and B-Trees - Lecture 9
9
4
G 5
1 P
Zig-zag
G
P 5
X 2
Zig-zig
X
Parent and grandparent
in same direction.
Parent and grandparent
in different directions.
Zig at depth 1 (root)
“Zig” is just a single rotation, as in an AVL tree
Let R be the node that was accessed (e.g. using
Find)
ZigFromLeft moves R to the top →faster access
next time
Splay Trees and B-Trees - Lecture 9
10
ZigFromLeft
root
Zig at depth 1
Suppose Q is now accessed using Find
ZigFromRight moves Q back to the top
Splay Trees and B-Trees - Lecture 9
11
ZigFromRight
root
Zig-Zag operation
“Zig-Zag” consists of two rotations of the opposite
direction (assume R is the node that was accessed)
Splay Trees and B-Trees - Lecture 9
12
(ZigFromRight) (ZigFromLeft)
ZigZagFromLeft
Zig-Zig operation
 “Zig-Zig” consists of two single rotations of the same direction (R
is the node that was accessed)
Splay Trees and B-Trees - Lecture 9
13
(ZigFromLeft) (ZigFromLeft)
ZigZigFromLeft
Decreasing depth - "autobalance"
Splay Trees and B-Trees - Lecture 9
14
Find(T) Find(R)
Splay Tree Insert and Delete
Insert x
Insert x as normal then splay x to root.
Delete x
Splay x to root and remove it. (note: the node
does not have to be a leaf or single child node
like in BST delete.) Two trees remain, right
subtree and left subtree.
Splay the max in the left subtree to the root
Attach the right subtree to the new root of the left
subtree.
Splay Trees and B-Trees - Lecture 9
15
Example Insert
 Inserting in order 1,2,3,…,8
 Without self-adjustment
Splay Trees and B-Trees - Lecture 9
16
1
2
3
4
5
6
7
8
O(n2
) time for n Insert
With Self-Adjustment
Splay Trees and B-Trees - Lecture 9
17
1
2
1 2
1
ZigFromRight
2
1 3
ZigFromRight
2
1
3
1
2
3
With Self-Adjustment
Splay Trees and B-Trees - Lecture 9
18
ZigFromRight
2
1
34
4
2
1
3
4
Each Insert takes O(1) time therefore O(n) time for n Insert!!
Example Deletion
Splay Trees and B-Trees - Lecture 9
19
10
155
201382
96
10
15
5
2013
8
2 96
splay
10
15
5
2013
2 96
remove
10
15
5
2013
2 9
6
Splay (zig)
attach
(Zig-Zag)
Advantages
 Simple implementation (self optimizing)
 Average case performance is as efficient as other trees
 No need to store any bookkeeping data
 Allows access to both the previous and new versions after an
update(Persistent data structure)
 Stable sorting
How many squares can you create in this figure by connecting any 4 dots (the corners of a
square must lie upon a grid dot?
TRIANGLES:
How many triangles are located in the image below?
There are 11 squares total; 5 small, 4 medium, and 2 large.
27 triangles. There are 16 one-cell triangles, 7 four-cell triangles, 3 nine-cell
triangles, and 1 sixteen-cell triangle.
GUIDED READING
ASSESSMENT
After inserting 56,87,56,43,98 and 77 the
element 22 is inserted. Then the root node of
the resultant splay tree is
1. 87
2. 56
3. 22
4. 77
CONTD..
The Zig-zig corresponds to
1.left rotation followed by right rotation
2.right rotation followed by left rotation
3.left rotation followed by left rotation
4.only left rotation.
CONTD..
After inserting, 7,6,5,4,3,2 and 1 into a normal
binary search tree, a splay operation is
performed at node 1. Then, the left and right
child of the root node of the resultant tree are
1.6 and null respectively
2.null and 6 respectively
3.5 and null respectively
4.null and 5 respectively
CONTD..
Let x be the accessed node and p be the parent
node of x. Then Zig-Zag operation is performed
When
1.p is the root
2.p is not the root and both x,p are left child nodes
3.p is not the root and both x,p are right child nodes
4.p is not the root and x is left and p is right or vice versa
CONTD..
After inserting, 7,6,5,4,3,2 and 1 into splay tree,
a search operation is performed at
node1. Then, the left and right child of the root
node of the resultant tree are
1. null and 3 respectively
2. null and 4 respectively
3. null and 6 respectively
4. 2 and 5 respectively

More Related Content

What's hot (20)

Lecture 14 splay tree
Lecture 14 splay treeLecture 14 splay tree
Lecture 14 splay tree
 
Queues
QueuesQueues
Queues
 
Splay Tree Presentation Slides
Splay Tree Presentation SlidesSplay Tree Presentation Slides
Splay Tree Presentation Slides
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Red black tree
Red black treeRed black tree
Red black tree
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Splay tree
Splay treeSplay tree
Splay tree
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Splay trees
Splay treesSplay trees
Splay trees
 
Binary trees
Binary treesBinary trees
Binary trees
 
Expression trees
Expression treesExpression trees
Expression trees
 

Viewers also liked

stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.CIIT Atd.
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Adam Mukharil Bachtiar
 
1.9 b trees 02
1.9 b trees 021.9 b trees 02
1.9 b trees 02Krish_ver2
 
1.9 b trees eg 03
1.9 b trees eg 031.9 b trees eg 03
1.9 b trees eg 03Krish_ver2
 
2.4 mst prim &kruskal demo
2.4 mst  prim &kruskal demo2.4 mst  prim &kruskal demo
2.4 mst prim &kruskal demoKrish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
nhận thiết kế clip quảng cáo giá tốt
nhận thiết kế clip quảng cáo giá tốtnhận thiết kế clip quảng cáo giá tốt
nhận thiết kế clip quảng cáo giá tốtraul110
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithmKrish_ver2
 
문제는 한글이 잘 구현되는가?
문제는 한글이 잘 구현되는가?문제는 한글이 잘 구현되는가?
문제는 한글이 잘 구현되는가?Choi Man Dream
 

Viewers also liked (20)

Splay tree
Splay treeSplay tree
Splay tree
 
B tree &
B tree &B tree &
B tree &
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
B tree long
B tree longB tree long
B tree long
 
B tree
B treeB tree
B tree
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
stack & queue
stack & queuestack & queue
stack & queue
 
1.9 b trees 02
1.9 b trees 021.9 b trees 02
1.9 b trees 02
 
4.2 bst 02
4.2 bst 024.2 bst 02
4.2 bst 02
 
4.1 webminig
4.1 webminig 4.1 webminig
4.1 webminig
 
1.9 b trees eg 03
1.9 b trees eg 031.9 b trees eg 03
1.9 b trees eg 03
 
2.4 mst prim &kruskal demo
2.4 mst  prim &kruskal demo2.4 mst  prim &kruskal demo
2.4 mst prim &kruskal demo
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
nhận thiết kế clip quảng cáo giá tốt
nhận thiết kế clip quảng cáo giá tốtnhận thiết kế clip quảng cáo giá tốt
nhận thiết kế clip quảng cáo giá tốt
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
문제는 한글이 잘 구현되는가?
문제는 한글이 잘 구현되는가?문제는 한글이 잘 구현되는가?
문제는 한글이 잘 구현되는가?
 
Top Forex Brokers
Top Forex BrokersTop Forex Brokers
Top Forex Brokers
 
RESUME-ARITRA BHOWMIK
RESUME-ARITRA BHOWMIKRESUME-ARITRA BHOWMIK
RESUME-ARITRA BHOWMIK
 

Similar to 1.8 splay tree

5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docxfredharris32
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptxRedHeart11
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAdityaK92
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
Skiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treesSkiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treeszukun
 
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
 
1.2 operations of tree representations
1.2 operations of tree representations 1.2 operations of tree representations
1.2 operations of tree representations Krish_ver2
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNratnapatil14
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil duttAnil Dutt
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms CourseHunt
 

Similar to 1.8 splay tree (20)

5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx5220191CS146 Data Structures and AlgorithmsC.docx
5220191CS146 Data Structures and AlgorithmsC.docx
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptx
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Skiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treesSkiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure trees
 
C12 bst
C12 bstC12 bst
C12 bst
 
C12 bst
C12 bstC12 bst
C12 bst
 
Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)
 
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)
 
Chapter 9 ds
Chapter 9 dsChapter 9 ds
Chapter 9 ds
 
Leftlist Heap-1.pdf
Leftlist Heap-1.pdfLeftlist Heap-1.pdf
Leftlist Heap-1.pdf
 
UNIT II.ppt
UNIT II.pptUNIT II.ppt
UNIT II.ppt
 
HeapSort
HeapSortHeapSort
HeapSort
 
Binary tree
Binary treeBinary tree
Binary tree
 
1.2 operations of tree representations
1.2 operations of tree representations 1.2 operations of tree representations
1.2 operations of tree representations
 
Short dec
Short decShort dec
Short dec
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
Binary Tree - Algorithms
Binary Tree - Algorithms Binary Tree - Algorithms
Binary Tree - Algorithms
 
Heapsort
HeapsortHeapsort
Heapsort
 

More from Krish_ver2

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back trackingKrish_ver2
 
5.5 back track
5.5 back track5.5 back track
5.5 back trackKrish_ver2
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructuresKrish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructuresKrish_ver2
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03Krish_ver2
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-iKrish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02Krish_ver2
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing extKrish_ver2
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashingKrish_ver2
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal searchKrish_ver2
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sortingKrish_ver2
 

More from Krish_ver2 (20)

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

1.8 splay tree

  • 2. Fundamental Concept Carefully rearrange (using tree rotation operation) the tree so that the recently accessed elements are brought to the top and at the same time, the tree is also approximately balanced.
  • 3. Splay Tree Splay is a binary search tree in which recently accessed keys are quick to access again. When an element is accessed, it is moved to the root using series of rotation operations so that it is quick to access again. The tree is also approximately balanced while rearranging. The process of rearranging is called splaying.
  • 4. Operations • Splay tree includes all the operations of BST along with splay operation. • Splay operation rearranges the tree so that the element is placed at the top of the tree. • Let x be the accessed node and let p be the parent node of x. Three types of splay steps: • Zig step (one left rotation or one right rotation) o carried out when p is the root (last step in the splay operation) • Zig-Zig step (left-left rotation or right-right rotation) o carried out when p is not the root and both x,p are either right or left children. • Zig-Zag step (left-right rotation or right-left rotation) o carried out when p is not the root and x is left and p is right or vice versa
  • 5. Operations (contd) Insertion •Insert the node using the normal BST insert procedure •splay the newly inserted node to the root Deletion •delete using normal BST delete procedure •splay the parent of removed node to the root Search •Search using normal BST search procedure •splay the accessed item to the root
  • 6. Splay Operation - Pseudo code void splay(struct node *x) { struct node *p,*g; /*check if node x is the root node*/ if (x->parent == NULL) { root = x; return; } /*Performs Zig step*/ else if ( x->parent == root) { if(x == x->parent->left) rightrotation(root); else leftrotation(root); }
  • 7. else { p = x->parent; /*now points to parent of x*/ g = p->parent; /*now points to grand parent of x*/ /*when x is left and x's parent is left*/ if(x==p->left and p==g->left) //Zig-zig { rightrotation(g); rightrotation(p); } /*step when x is right and x's parent is right*/ else if (x==p->right and p==g->right) //Zig-zig { leftrotation(g); leftrotation(p); } /*when x's is right and x's parent is left*/ else if (x==p->right and p==g->left) // Zig-zag { leftrotation(p); rightrotation(g); } /*when x's is left and x's parent is right*/ else if (x==p->left and p==g->right) //Zig-zag { rightrotation(p); leftrotation(g); } splay(x); }
  • 8. Splay Trees and B-Trees - Lecture 9 8 • Let X be a non-root node with ≥ 2 ancestors. • P is its parent node. • G is its grandparent node. P G X G P X G P X G P X Splay Tree Terminology
  • 9. Zig-Zig and Zig-Zag Splay Trees and B-Trees - Lecture 9 9 4 G 5 1 P Zig-zag G P 5 X 2 Zig-zig X Parent and grandparent in same direction. Parent and grandparent in different directions.
  • 10. Zig at depth 1 (root) “Zig” is just a single rotation, as in an AVL tree Let R be the node that was accessed (e.g. using Find) ZigFromLeft moves R to the top →faster access next time Splay Trees and B-Trees - Lecture 9 10 ZigFromLeft root
  • 11. Zig at depth 1 Suppose Q is now accessed using Find ZigFromRight moves Q back to the top Splay Trees and B-Trees - Lecture 9 11 ZigFromRight root
  • 12. Zig-Zag operation “Zig-Zag” consists of two rotations of the opposite direction (assume R is the node that was accessed) Splay Trees and B-Trees - Lecture 9 12 (ZigFromRight) (ZigFromLeft) ZigZagFromLeft
  • 13. Zig-Zig operation  “Zig-Zig” consists of two single rotations of the same direction (R is the node that was accessed) Splay Trees and B-Trees - Lecture 9 13 (ZigFromLeft) (ZigFromLeft) ZigZigFromLeft
  • 14. Decreasing depth - "autobalance" Splay Trees and B-Trees - Lecture 9 14 Find(T) Find(R)
  • 15. Splay Tree Insert and Delete Insert x Insert x as normal then splay x to root. Delete x Splay x to root and remove it. (note: the node does not have to be a leaf or single child node like in BST delete.) Two trees remain, right subtree and left subtree. Splay the max in the left subtree to the root Attach the right subtree to the new root of the left subtree. Splay Trees and B-Trees - Lecture 9 15
  • 16. Example Insert  Inserting in order 1,2,3,…,8  Without self-adjustment Splay Trees and B-Trees - Lecture 9 16 1 2 3 4 5 6 7 8 O(n2 ) time for n Insert
  • 17. With Self-Adjustment Splay Trees and B-Trees - Lecture 9 17 1 2 1 2 1 ZigFromRight 2 1 3 ZigFromRight 2 1 3 1 2 3
  • 18. With Self-Adjustment Splay Trees and B-Trees - Lecture 9 18 ZigFromRight 2 1 34 4 2 1 3 4 Each Insert takes O(1) time therefore O(n) time for n Insert!!
  • 19. Example Deletion Splay Trees and B-Trees - Lecture 9 19 10 155 201382 96 10 15 5 2013 8 2 96 splay 10 15 5 2013 2 96 remove 10 15 5 2013 2 9 6 Splay (zig) attach (Zig-Zag)
  • 20. Advantages  Simple implementation (self optimizing)  Average case performance is as efficient as other trees  No need to store any bookkeeping data  Allows access to both the previous and new versions after an update(Persistent data structure)  Stable sorting
  • 21. How many squares can you create in this figure by connecting any 4 dots (the corners of a square must lie upon a grid dot? TRIANGLES: How many triangles are located in the image below?
  • 22. There are 11 squares total; 5 small, 4 medium, and 2 large. 27 triangles. There are 16 one-cell triangles, 7 four-cell triangles, 3 nine-cell triangles, and 1 sixteen-cell triangle.
  • 24.
  • 25. ASSESSMENT After inserting 56,87,56,43,98 and 77 the element 22 is inserted. Then the root node of the resultant splay tree is 1. 87 2. 56 3. 22 4. 77
  • 26. CONTD.. The Zig-zig corresponds to 1.left rotation followed by right rotation 2.right rotation followed by left rotation 3.left rotation followed by left rotation 4.only left rotation.
  • 27. CONTD.. After inserting, 7,6,5,4,3,2 and 1 into a normal binary search tree, a splay operation is performed at node 1. Then, the left and right child of the root node of the resultant tree are 1.6 and null respectively 2.null and 6 respectively 3.5 and null respectively 4.null and 5 respectively
  • 28. CONTD.. Let x be the accessed node and p be the parent node of x. Then Zig-Zag operation is performed When 1.p is the root 2.p is not the root and both x,p are left child nodes 3.p is not the root and both x,p are right child nodes 4.p is not the root and x is left and p is right or vice versa
  • 29. CONTD.. After inserting, 7,6,5,4,3,2 and 1 into splay tree, a search operation is performed at node1. Then, the left and right child of the root node of the resultant tree are 1. null and 3 respectively 2. null and 4 respectively 3. null and 6 respectively 4. 2 and 5 respectively