SlideShare a Scribd company logo
CS 6213 –
Advanced
Data
Structures
SPLAY TREES
SELF ORGANIZING
DATA STRUCTURES
Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well
TA
Iswarya Parupudi
iswarya2291@gwmail.gwu.edu
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 2
LOGISTICS
CS 6213
Basics
Record / Struct
Arrays / Linked
Lists / Stacks
/ Queues
Graphs / Trees
/ BSTs
Advanced
Trie, B-Tree
Splay Trees
R-Trees
Heaps and PQs
Union Find
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 3
WHERE WE ARE
David Kaplan @ Washington University
Jay Chen @ NYU Abu Dhabi / NYU Poly
Frank Ruskey @ University of Victoria
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 4
CREDITS
Data structure “self organizes” based on the
sequence of operations invoked on it, and based on
some general rules on what to do with the operation.
Different from having rules on what the data
structure should globally look like.
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 5
SELF ORGANIZING DATA STRUCTURES
Splay Tree
Is a Binary Search Tree, but is not an AVL or RB Tree
Its height is not guaranteed to be O(log(n)). In fact,
it can even be O(n).
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 6
SELF ORGANIZING BINARY SEARCH TREE
splā/ verb
thrust or spread (things, esp. limbs or fingers) out
and apart.
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 7
SPLAY
Relax – let the rules break overall
Don’t be so uptight
Focus on amortized time, not just worst case time.
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 8
MOTIVATION FOR SPLAY TREES
Problems with AVL Trees
 Extra storage/complexity for height fields
 Ugly delete code
Solution: splay trees
 Blind adjusting version of AVL trees
 Amortized time for all operations is O(log n)
 Worst case time is O(n)
 Insert/find always rotates nodes and makes the new/found
node to be the new root, so its future accesses are faster
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 9
MOTIVATION FOR SPLAY TREES (CONT.)
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 10
SPLAY TREE IDEA
17
10
92
5
3
Since the tree does not
have a bounded height,
you may be forced to
make a really deep access:
Since you’re down there anyway,
fix up a lot of deep nodes!
Node being accessed (n) is:
 Root
 Child of root
 Has both parent (p) and grandparent (g)
Zig-zig pattern: g  p  n is left-left or right-right
Zig-zag pattern: g  p  n is left-right or right-left
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 11
SPLAYING CASES
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 12
ACCESS ROOT:
DO NOTHING
X
n
Y
root
X
n
Y
root
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 13
ACCESS CHILD OF ROOT:
ZIG (AVL SINGLE ROTATION)
p
X
n
Y
Z
n
Z
p
Y
X
root root
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 14
ACCESS (LR, RL) GRANDCHILD:
ZIG-ZAG (AVL DOUBLE ROTATION)
g
X
p
Y
n
Z
W
n
Y
g
W
p
ZX
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 15
ACCESS (LL, RR) GRANDCHILD:
ZIG-ZIG
n
Z
Y
p
X
g
W
g
W
X
p
Y
n
Z
Rotate top-down – why?
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 16
SPLAYING EXAMPLE:
FIND(6)
2
1
3
4
5
6
Find(6)
2
1
3
6
5
4
zig-zig
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 17
… STILL SPLAYING …
zig-zig
2
1
3
6
5
4
1
6
3
2 5
4
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 18
… 6 SPLAYED OUT!
zig
1
6
3
2 5
4
6
1
3
2 5
4
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 19
ANOTHER EXAMPLE
FIND (4)
Find(4)
zig-zag
6
1
3
2 5
4
6
1
4
3 5
2
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 20
… 4 SPLAYED OUT!
zig-zag
6
1
4
3 5
2
61
4
3 5
2
If a node n on the access path is at depth d before
the splay, it’s at about depth d/2 after the splay
 Exceptions are the root, the child of the root, and the node
splayed
Overall, nodes which are below nodes on the access
path tend to move closer to the root
Splaying gets amortized O(log n) performance. (Not
easy to prove)
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 21
WHY SPLAYING HELPS
Find the node in normal BST manner
Splay the node to the root
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 22
SPLAY OPERATIONS: FIND
Just do BST insert
Then, splay to the root.
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 23
SPLAY OPERATIONS: INSERT
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 24
SPLIT
split(x)
T L R
splay
OR
L R L R
 x  x> x < x
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 25
SPLAY OPERATIONS: DELETE
find(x)
L R
x
L R
> x< x
delete x
Now what?
Join(L, R): Given two trees such that L < R, merge
them
Splay on the maximum element in L, then attach R
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 26
JOIN
L R R
splay
L
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 27
DELETE COMPLETED
T
find(x)
L R
x
L R
> x< x
delete x
T - x
Join(L,R)
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 28
INSERT EXAMPLE
Insert(5)
91
6
4 7
2
split(5)
9
6
7
1
4
2
1
4
2
9
6
7
1
4
2
9
6
7
5
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 29
DELETE EXAMPLE
91
6
4 7
2
Delete(4)
find(4)
9
6
7
1
4
2
1
2
9
6
7
Find max
2
1
9
6
7
2
1
9
6
7
Unsorted List
 Access(x) – Costs i, if x is at the i-th location.
 Delete(x) – Costs i, if x is at the i-th location.
 Insert(x) – Costs n+1 if list has n elements
Standard Cost Model
 Cost of operation
 Free inversion – Move the element anywhere to the front
 Paid inversion – Swap any two elements
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 30
ANOTHER EXAMPLE OF SELF
ORGANIZING DATA STRUCTURES
Moves the accessed item to the front of the list
 (Other algorithms: Transpose, Frequency Count)
This is the simple idea behind self adjustment.
Similar idea is used in caching algorithms also.
This also introduces us to online algorithms, because
we do not know what the future part of request
sequence will look like.
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 31
SELF ADJUSTMENT: “MOVE TO FRONT”
ALGORITHM
 Amortized Cost Analysis: Consider the worst case cost
over multiple operations
 Different from average cost analysis – over “probabilistically
average case” for one operation
 We compare the performance of MTF algorithm to an
Optimal algorithm which knows the full request sequence
in advance and can use that to organize the list.
 Request sequence: s1, s2, … sn
 Frequently used idea in amortized analysis: Potential
function: f(t).
 In context of MTF, we define f(t) to be the number of
“inversions” between the MTF list and the OPT list.
 Key Result: C_MTF(t) + f(t) – f(t – 1) <= 2 C_OPT(t) – 1
 This leads to: C_MTF <= 2 C_OPT overall. (Impressive.)
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 32
ANALYSIS OF “MOVE TO FRONT”
ALGORITHM
 Self-tuning data structure
 Operations tune the data structure automatically, based on
some rules
 Final state of the data structure depends upon the sequence of
operations
 Splaying Philosophy
 Keeps most-recently used (MRU) nodes higher up
 Main Results
 Any m consecutive operations starting from an empty tree take
at most O(m log(n)) time, where n is the number of inserts.
 That is, all splay tree operations run in amortized O(log n) time
 O(n) operations can occur, but splaying makes them infrequent
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 33
CONCLUSIONS: SPLAY TREE
Splay trees are very effective search trees
Relatively simple: no extra fields required (height
of subtree, color, rank, etc.)
Excellent locality properties:
 Frequently accessed keys are cheap to find (near top of tree)
 Items near an accessed item are also pulled towards the
root.
 Infrequently accessed keys stay out of the way (near bottom
of tree)
L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 34
CONCLUSIONS: SPLAY TREE (CONT.)

More Related Content

What's hot

Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
Trupti Agrawal
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
amna izzat
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
Dwight Sabio
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
Zaid Shabbir
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Zafar Ayub
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
Om Prakash
 
Tree and graph
Tree and graphTree and graph
Tree and graph
Muhaiminul Islam
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
Intro C# Book
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union find
Wei (Terence) Li
 
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
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Abhishek L.R
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
cinterviews
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
Saurabh Mishra
 
Trees
TreesTrees
Trees
9590133127
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 

What's hot (20)

Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
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
 
Tree and graph
Tree and graphTree and graph
Tree and graph
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union find
 
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
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Trees
TreesTrees
Trees
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 

Viewers also liked

Splay Tree
Splay TreeSplay Tree
Splay trees
Splay treesSplay trees
Splay trees
Amaan Shaikh
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
Amrinder Arora
 
Splay tree
Splay treeSplay tree
Splay tree
Rajendran
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
Amrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Trie Data Structure
Trie Data StructureTrie Data Structure
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
 
Knuth–Morris–Pratt Algorithm | Computer Science
Knuth–Morris–Pratt Algorithm | Computer ScienceKnuth–Morris–Pratt Algorithm | Computer Science
Knuth–Morris–Pratt Algorithm | Computer Science
Transweb Global Inc
 
Paper
PaperPaper
Paper
khbsharat
 
Splay tree && euler tour tree
Splay tree && euler tour treeSplay tree && euler tour tree
Splay tree && euler tour tree
Rezwanul Haque
 
Fibonacci Heaps
Fibonacci Heaps Fibonacci Heaps
Fibonacci Heaps
Naseeba P P
 
06. string matching
06. string matching06. string matching
06. string matching
Onkar Nath Sharma
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
Kamal Nayan
 
b+ tree
b+ treeb+ tree
b+ tree
bitistu
 
Masterizing php data structure 102
Masterizing php data structure 102Masterizing php data structure 102
Masterizing php data structure 102
Patrick Allaert
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
ForwardBlog Enewzletter
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
Anshuman Biswal
 

Viewers also liked (20)

Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Splay trees
Splay treesSplay trees
Splay trees
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Splay tree
Splay treeSplay tree
Splay tree
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
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)
 
Knuth–Morris–Pratt Algorithm | Computer Science
Knuth–Morris–Pratt Algorithm | Computer ScienceKnuth–Morris–Pratt Algorithm | Computer Science
Knuth–Morris–Pratt Algorithm | Computer Science
 
Paper
PaperPaper
Paper
 
Splay tree && euler tour tree
Splay tree && euler tour treeSplay tree && euler tour tree
Splay tree && euler tour tree
 
Fibonacci Heaps
Fibonacci Heaps Fibonacci Heaps
Fibonacci Heaps
 
06. string matching
06. string matching06. string matching
06. string matching
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
 
b+ tree
b+ treeb+ tree
b+ tree
 
Masterizing php data structure 102
Masterizing php data structure 102Masterizing php data structure 102
Masterizing php data structure 102
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 

Similar to Splay Trees and Self Organizing Data Structures

Algebra
AlgebraAlgebra
Algebra
Hira Maharjan
 
Wireless sensor network Apriori an N-RMP
Wireless sensor network Apriori an N-RMP Wireless sensor network Apriori an N-RMP
Wireless sensor network Apriori an N-RMP
Amrit Khandelwal
 
Zippers: Derivatives of Regular Types
Zippers: Derivatives of Regular TypesZippers: Derivatives of Regular Types
Zippers: Derivatives of Regular Types
Jay Coskey
 
lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.ppt
mrizwan38
 
Using PostgreSQL with Bibliographic Data
Using PostgreSQL with Bibliographic DataUsing PostgreSQL with Bibliographic Data
Using PostgreSQL with Bibliographic Data
Jimmy Angelakos
 
Pydata talk
Pydata talkPydata talk
Pydata talk
Turi, Inc.
 
Trees
TreesTrees
spark stream - kafka - the right way
spark stream - kafka - the right way spark stream - kafka - the right way
spark stream - kafka - the right way
Dori Waldman
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Meghaj Mallick
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
Krish_ver2
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
Abdul Rehman
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
ratnapatil14
 
cs201-list-stack-queue.ppt
cs201-list-stack-queue.pptcs201-list-stack-queue.ppt
cs201-list-stack-queue.ppt
RahulYadav738822
 
SQL For PHP Programmers
SQL For PHP ProgrammersSQL For PHP Programmers
SQL For PHP Programmers
Dave Stokes
 
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
Anil Dutt
 
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Databricks
 
lecture4.pdf
lecture4.pdflecture4.pdf
lecture4.pdf
ssuser67281d
 
(5) collections algorithms
(5) collections algorithms(5) collections algorithms
(5) collections algorithms
Nico Ludwig
 
An Algorithm for Keyword Search on an Execution Path
An Algorithm for Keyword Search on an Execution PathAn Algorithm for Keyword Search on an Execution Path
An Algorithm for Keyword Search on an Execution Path
Kamiya Toshihiro
 

Similar to Splay Trees and Self Organizing Data Structures (20)

Algebra
AlgebraAlgebra
Algebra
 
Wireless sensor network Apriori an N-RMP
Wireless sensor network Apriori an N-RMP Wireless sensor network Apriori an N-RMP
Wireless sensor network Apriori an N-RMP
 
Zippers: Derivatives of Regular Types
Zippers: Derivatives of Regular TypesZippers: Derivatives of Regular Types
Zippers: Derivatives of Regular Types
 
lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.ppt
 
Using PostgreSQL with Bibliographic Data
Using PostgreSQL with Bibliographic DataUsing PostgreSQL with Bibliographic Data
Using PostgreSQL with Bibliographic Data
 
Pydata talk
Pydata talkPydata talk
Pydata talk
 
Trees
TreesTrees
Trees
 
spark stream - kafka - the right way
spark stream - kafka - the right way spark stream - kafka - the right way
spark stream - kafka - the right way
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
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
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNNsplaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
splaytree-171227043127.pptx NNNNNNNNNNNNNNNNNNNNNNN
 
cs201-list-stack-queue.ppt
cs201-list-stack-queue.pptcs201-list-stack-queue.ppt
cs201-list-stack-queue.ppt
 
SQL For PHP Programmers
SQL For PHP ProgrammersSQL For PHP Programmers
SQL For PHP Programmers
 
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
 
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
Improving SparkSQL Performance by 30%: How We Optimize Parquet Pushdown and P...
 
lecture4.pdf
lecture4.pdflecture4.pdf
lecture4.pdf
 
(5) collections algorithms
(5) collections algorithms(5) collections algorithms
(5) collections algorithms
 
An Algorithm for Keyword Search on an Execution Path
An Algorithm for Keyword Search on an Execution PathAn Algorithm for Keyword Search on an Execution Path
An Algorithm for Keyword Search on an Execution Path
 

More from Amrinder Arora

NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
Amrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Amrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
Amrinder Arora
 

More from Amrinder Arora (17)

NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
NP completeness
NP completenessNP completeness
NP completeness
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
 

Recently uploaded

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 

Recently uploaded (20)

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 

Splay Trees and Self Organizing Data Structures

  • 1. CS 6213 – Advanced Data Structures SPLAY TREES SELF ORGANIZING DATA STRUCTURES
  • 2. Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well TA Iswarya Parupudi iswarya2291@gwmail.gwu.edu L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 2 LOGISTICS
  • 3. CS 6213 Basics Record / Struct Arrays / Linked Lists / Stacks / Queues Graphs / Trees / BSTs Advanced Trie, B-Tree Splay Trees R-Trees Heaps and PQs Union Find L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 3 WHERE WE ARE
  • 4. David Kaplan @ Washington University Jay Chen @ NYU Abu Dhabi / NYU Poly Frank Ruskey @ University of Victoria L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 4 CREDITS
  • 5. Data structure “self organizes” based on the sequence of operations invoked on it, and based on some general rules on what to do with the operation. Different from having rules on what the data structure should globally look like. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 5 SELF ORGANIZING DATA STRUCTURES
  • 6. Splay Tree Is a Binary Search Tree, but is not an AVL or RB Tree Its height is not guaranteed to be O(log(n)). In fact, it can even be O(n). L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 6 SELF ORGANIZING BINARY SEARCH TREE
  • 7. splā/ verb thrust or spread (things, esp. limbs or fingers) out and apart. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 7 SPLAY
  • 8. Relax – let the rules break overall Don’t be so uptight Focus on amortized time, not just worst case time. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 8 MOTIVATION FOR SPLAY TREES
  • 9. Problems with AVL Trees  Extra storage/complexity for height fields  Ugly delete code Solution: splay trees  Blind adjusting version of AVL trees  Amortized time for all operations is O(log n)  Worst case time is O(n)  Insert/find always rotates nodes and makes the new/found node to be the new root, so its future accesses are faster L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 9 MOTIVATION FOR SPLAY TREES (CONT.)
  • 10. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 10 SPLAY TREE IDEA 17 10 92 5 3 Since the tree does not have a bounded height, you may be forced to make a really deep access: Since you’re down there anyway, fix up a lot of deep nodes!
  • 11. Node being accessed (n) is:  Root  Child of root  Has both parent (p) and grandparent (g) Zig-zig pattern: g  p  n is left-left or right-right Zig-zag pattern: g  p  n is left-right or right-left L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 11 SPLAYING CASES
  • 12. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 12 ACCESS ROOT: DO NOTHING X n Y root X n Y root
  • 13. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 13 ACCESS CHILD OF ROOT: ZIG (AVL SINGLE ROTATION) p X n Y Z n Z p Y X root root
  • 14. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 14 ACCESS (LR, RL) GRANDCHILD: ZIG-ZAG (AVL DOUBLE ROTATION) g X p Y n Z W n Y g W p ZX
  • 15. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 15 ACCESS (LL, RR) GRANDCHILD: ZIG-ZIG n Z Y p X g W g W X p Y n Z Rotate top-down – why?
  • 16. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 16 SPLAYING EXAMPLE: FIND(6) 2 1 3 4 5 6 Find(6) 2 1 3 6 5 4 zig-zig
  • 17. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 17 … STILL SPLAYING … zig-zig 2 1 3 6 5 4 1 6 3 2 5 4
  • 18. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 18 … 6 SPLAYED OUT! zig 1 6 3 2 5 4 6 1 3 2 5 4
  • 19. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 19 ANOTHER EXAMPLE FIND (4) Find(4) zig-zag 6 1 3 2 5 4 6 1 4 3 5 2
  • 20. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 20 … 4 SPLAYED OUT! zig-zag 6 1 4 3 5 2 61 4 3 5 2
  • 21. If a node n on the access path is at depth d before the splay, it’s at about depth d/2 after the splay  Exceptions are the root, the child of the root, and the node splayed Overall, nodes which are below nodes on the access path tend to move closer to the root Splaying gets amortized O(log n) performance. (Not easy to prove) L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 21 WHY SPLAYING HELPS
  • 22. Find the node in normal BST manner Splay the node to the root L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 22 SPLAY OPERATIONS: FIND
  • 23. Just do BST insert Then, splay to the root. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 23 SPLAY OPERATIONS: INSERT
  • 24. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 24 SPLIT split(x) T L R splay OR L R L R  x  x> x < x
  • 25. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 25 SPLAY OPERATIONS: DELETE find(x) L R x L R > x< x delete x Now what?
  • 26. Join(L, R): Given two trees such that L < R, merge them Splay on the maximum element in L, then attach R L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 26 JOIN L R R splay L
  • 27. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 27 DELETE COMPLETED T find(x) L R x L R > x< x delete x T - x Join(L,R)
  • 28. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 28 INSERT EXAMPLE Insert(5) 91 6 4 7 2 split(5) 9 6 7 1 4 2 1 4 2 9 6 7 1 4 2 9 6 7 5
  • 29. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 29 DELETE EXAMPLE 91 6 4 7 2 Delete(4) find(4) 9 6 7 1 4 2 1 2 9 6 7 Find max 2 1 9 6 7 2 1 9 6 7
  • 30. Unsorted List  Access(x) – Costs i, if x is at the i-th location.  Delete(x) – Costs i, if x is at the i-th location.  Insert(x) – Costs n+1 if list has n elements Standard Cost Model  Cost of operation  Free inversion – Move the element anywhere to the front  Paid inversion – Swap any two elements L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 30 ANOTHER EXAMPLE OF SELF ORGANIZING DATA STRUCTURES
  • 31. Moves the accessed item to the front of the list  (Other algorithms: Transpose, Frequency Count) This is the simple idea behind self adjustment. Similar idea is used in caching algorithms also. This also introduces us to online algorithms, because we do not know what the future part of request sequence will look like. L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 31 SELF ADJUSTMENT: “MOVE TO FRONT” ALGORITHM
  • 32.  Amortized Cost Analysis: Consider the worst case cost over multiple operations  Different from average cost analysis – over “probabilistically average case” for one operation  We compare the performance of MTF algorithm to an Optimal algorithm which knows the full request sequence in advance and can use that to organize the list.  Request sequence: s1, s2, … sn  Frequently used idea in amortized analysis: Potential function: f(t).  In context of MTF, we define f(t) to be the number of “inversions” between the MTF list and the OPT list.  Key Result: C_MTF(t) + f(t) – f(t – 1) <= 2 C_OPT(t) – 1  This leads to: C_MTF <= 2 C_OPT overall. (Impressive.) L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 32 ANALYSIS OF “MOVE TO FRONT” ALGORITHM
  • 33.  Self-tuning data structure  Operations tune the data structure automatically, based on some rules  Final state of the data structure depends upon the sequence of operations  Splaying Philosophy  Keeps most-recently used (MRU) nodes higher up  Main Results  Any m consecutive operations starting from an empty tree take at most O(m log(n)) time, where n is the number of inserts.  That is, all splay tree operations run in amortized O(log n) time  O(n) operations can occur, but splaying makes them infrequent L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 33 CONCLUSIONS: SPLAY TREE
  • 34. Splay trees are very effective search trees Relatively simple: no extra fields required (height of subtree, color, rank, etc.) Excellent locality properties:  Frequently accessed keys are cheap to find (near top of tree)  Items near an accessed item are also pulled towards the root.  Infrequently accessed keys stay out of the way (near bottom of tree) L5 - Splay Trees CS 6213 - Advanced Data Structures - Arora 34 CONCLUSIONS: SPLAY TREE (CONT.)