SlideShare a Scribd company logo
1 of 28
Download to read offline
Persistent Search Trees
Presentation from the article
Planar Point Location Using Persistent Search Trees
of Neil Sarnak and Robert E. Tarjan
Olivier Pirson
INFO-F413 Data structures and algorithms
December 8, 2016
(Some corrections November 26, 2017)
Last version:
https://bitbucket.org/OPiMedia/persistent-search-trees/
Persistent
Search Trees
Quick
summary
Persistance
References
1 Quick summary about binary search trees
2 Persistent Search Trees
3 References
Persistent Search Trees 2 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Binary search trees
12
23 54
76
9
14 19
67
50
17
72
Figure: Intgr, Wikipedia
Each node contains a key (a
value, and in general an
associated data).
All keys in the left subtree are
less than the key’s root.
All keys in the right subtree are
greater than the key’s root.
And recursively.
Persistent Search Trees 3 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Binary search trees
12
23 54
76
9
14 19
67
50
17
72
Figure: Intgr, Wikipedia
A binary search tree constructs a set
and provides these operations:
access(x): find and return the
item with the greatest key less than
or equal to x (or a NIL value if
doesn’t exist). So if x is in the tree,
then return the item with x.
insert(x)
delete(x)
Persistent Search Trees 4 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Binary search trees
12
23 54
76
9
14 19
67
50
17
72
Figure: Intgr, Wikipedia
The problem with this tree...
Persistent Search Trees 5 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Balanced binary search trees
12
23 54
76
9
14 19
67
50
17
72
Figure: Intgr, Wikipedia
height of the tree ∈ O(n), so
access(x): O(n) in time
insert(x): O(n)
delete(x): O(n)
in worst case
(n = size of the tree = number of nodes)
12 23 54 76
9 14 19 67
50
17 72
Figure: Mikm, Wikipedia
With a balanced binary search tree:
height of the tree ∈ O(logn), so
access(x): O(logn)
insert(x): O(logn)
delete(x): O(logn)
And (n) for space.
(Of course, all these complexities depend on the
implementation, but it is possible.)
Persistent Search Trees 6 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Red–black trees
One way to ensure a good balancing and have good complexities:
add extra-information in each node
rearrange after each modification (with some specific local rotations)
13
8 17
1 25
6 22
NILNIL
27
NILNIL
15
NILNIL
11
NILNILNIL
NILNIL
Figure: Cburnett, Wikipedia
(All NIL can are an unique sentinel.)
Red–black trees:
(The type of binary search trees used in the article.)
A color red or black for each
node (in fact 1 bit of
information).
Add (pseudo)-leaves NIL.
Some constraints on colors:
every leaf (NIL) is black
children of red node are black
all descending path contain
same number of black nodes
These constraints ensure a height in
O(logn), with some rotations and
recoloring when we insert or delete.
Persistent Search Trees 7 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Red–black trees
Insertions and deletions require
only O(1) rotations
and O(logn) recoloring
(in worst case, and only O(1) in amortized case).
In summary,
with some requirements, we have a balanced binary search tree with:
Operations in O(logn)
and space in Θ(n).
Persistent Search Trees 8 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
1 Quick summary about binary search trees
2 Persistent Search Trees
3 References
Persistent Search Trees 9 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Volatile data structures
If we modify these kind of data structures,
we lost the previous versions.
Those are volatile data structures.
In general, it is exactly what we want.
But not always.
Persistent Search Trees 10 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent data structures
A persistent data structure, it is a data structure that
preserve all old versions after any modification.
It is also an immutable data structure.
That is the old structures are never modified.
(From an external point of view. Maybe the internal data are modified, but is not visible.)
Instead the structure is modified in place; a new updated structure is build.
These two notions are close.
Persistence is about all the new updated structure,
and immutability is about the old not modified structure.
Persistent Search Trees 11 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
And now. . . a digression!
Immutable data structures are a foundation of functional paradigm
languages (like Lisp, ML, Haskell, Scala... and progressively more and
more other languages add functional aspects).
It was my motivation to choose this subject. I would like more understand
immutable data structures. (Maybe soon, I will understand how deal with
immutable graphs!)
I think it is an important paradigm, and it will more important in the
future.
First, because it have a mathematical elegance. It is important.
But mostly because our computers today, and more after, must be use
multiple cores and for that programs must become parallelized
programs.
Persistent Search Trees 12 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Trivial and stupid way
Go back to the persistence.
How build a persistent data structure?
Persistent Search Trees 13 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Trivial and stupid way
Go back to the persistence.
How build a persistent data structure?
Copy all the current version, and apply the modification on the copy.
It works.
But it is inefficient! Waste time and space.
So, it does not works.
Persistent Search Trees 14 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Linked-list example
I will show you on a linked-list a better idea
and after that we will do the same with binary search tree.
Start with a list (2,7,1)
And push front 4, and next 0. We obtain a new list, (0,4,2,7,1)
Persistent Search Trees 15 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Linked-list example
I will show you on a linked-list a better idea
and after that we will do the same with binary search tree.
Start with a list (2,7,1)
And push front 4, and next 0. We obtain a new list, (0,4,2,7,1)
If we preserve links to previous versions,
we have a persistent data structure.
Persistent Search Trees 16 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Very simple
And now... let’s do that on a binary search tree...
Persistent Search Trees 17 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
Persistent red–black tree with path copying.
Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 18 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
We have now a notion
of time. We can access
to current tree, but
also to all past trees.
access(x, t)
insert(x)
delete(x)
Only the current tree
is modifiable.
And each modification
implies a path
copying.
Persistent red–black tree with path copying.
Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 19 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
Restart from time = 0,
with A, B, D, F, G, H, I,
J, K and L in the tree.
Persistent red–black tree with path copying.
Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 20 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
Restart from time = 0,
with A, B, D, F, G, H, I,
J, K and L in the tree.
Add E, in the time 1.
Note that J was
changed of color.
(Colors are only used
for update, so they
useless for past
version.)
Persistent red–black tree with path copying.
Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 21 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
Restart from time = 0,
with A, B, D, F, G, H, I,
J, K and L in the tree.
Add E, in the time 1.
Note that J was
changed of color.
(Colors are only used
for update, so they
useless for past
version.)
Add M, in the time 2.
Persistent red–black tree with path copying.
Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 22 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with path copying
Restart from time = 0,
with A, B, D, F, G, H, I,
J, K and L in the tree.
Add E, in the time 1.
Note that J was
changed of color.
(Colors are only used
for update, so they
useless for past
version.)
Add M, in the time 2.
Add C, in the time 3.
We have preserved the
O(logn) complexity of
operations.
Maybe O(logn + t) for the
access operation
(it depends on
implementation).
But we copy a lot of paths.
Persistent red–black tree with path copying.
Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 23 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with no node copying
We can do better,
with no node copying.
Instead copying path, we will
add links in nodes.
Each insertion or deletion
cost O(1) space.
But we have a time penalty.
Access become O(logn logm)
(with m maximum number
of links in nodes).
Persistent red–black tree with no node copying.
Figure: Figure 7 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 24 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree with limited node copying
We mix the two ways.
In each node we allow
k extra links.
And if no empty link is
available then we copy the
node.
The article of Sarnak and
Tarjan study the amortized
space cost and conclude that
is linear: O(n).
The good choice of k depend
of what we want (speed or
space economy).
k = 1 is a good choice by
default.
Previous methods path
copying and no node copying
are specific cases of the
limited node copying
method (corresponding to
k = 0 and k = ∞).
Persistent red–black tree limited node copying
with only one extra link (k = 1).
Figure: Figure 8 of Neil Sarnak, Robert E. Tarjan (Ref. 28)
Persistent Search Trees 25 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
Persistent search tree
In summary,
with a red–black tree we have built
a persistent binary search tree with good complexities:
Operations in O(logn) in worst case
and space in O(n) in amortized space cost.
Applications (of this persistent data structure, or similar):
In computational geometry (planar point location problem)
Functional languages
Incremental backup system
Versioning system (like Git, Mercurial, SVN...)
...
Persistent Search Trees 26 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
1 Quick summary about binary search trees
2 Persistent Search Trees
3 References
Persistent Search Trees 27 / 28
Persistent
Search Trees
Quick
summary
Persistance
References
References
Thank you!
References:
Neil Sarnak, Robert E. Tarjan (1986).
Planar Point Location Using Persistent Search Trees.
Communications of the ACM. 29 (7) pp.669–679
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein.
Introduction to Algorithms.
MIT Press, 3rd 2009
draw.io
LATEX with beamer class
Questions time...
Persistent Search Trees 28 / 28

More Related Content

What's hot

Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)Akshay soni
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 
2.2 decision tree
2.2 decision tree2.2 decision tree
2.2 decision treeKrish_ver2
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
Introduction to Clustering algorithm
Introduction to Clustering algorithmIntroduction to Clustering algorithm
Introduction to Clustering algorithmhadifar
 
Data mining Measuring similarity and desimilarity
Data mining Measuring similarity and desimilarityData mining Measuring similarity and desimilarity
Data mining Measuring similarity and desimilarityRushali Deshmukh
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 
05 Clustering in Data Mining
05 Clustering in Data Mining05 Clustering in Data Mining
05 Clustering in Data MiningValerii Klymchuk
 
5.2 mining time series data
5.2 mining time series data5.2 mining time series data
5.2 mining time series dataKrish_ver2
 
Active attacks in social networks
Active attacks in social networksActive attacks in social networks
Active attacks in social networksAlberto Ragonese
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searchingKawsar Hamid Sumon
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 

What's hot (20)

Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 
Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
2.2 decision tree
2.2 decision tree2.2 decision tree
2.2 decision tree
 
Cluster analysis
Cluster analysisCluster analysis
Cluster analysis
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
Introduction to Clustering algorithm
Introduction to Clustering algorithmIntroduction to Clustering algorithm
Introduction to Clustering algorithm
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Data mining Measuring similarity and desimilarity
Data mining Measuring similarity and desimilarityData mining Measuring similarity and desimilarity
Data mining Measuring similarity and desimilarity
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Clustering
ClusteringClustering
Clustering
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Uninformed search
Uninformed searchUninformed search
Uninformed search
 
05 Clustering in Data Mining
05 Clustering in Data Mining05 Clustering in Data Mining
05 Clustering in Data Mining
 
5.2 mining time series data
5.2 mining time series data5.2 mining time series data
5.2 mining time series data
 
Active attacks in social networks
Active attacks in social networksActive attacks in social networks
Active attacks in social networks
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 

Similar to Persistent Search Trees

17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like StructuresIntro C# Book
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
OXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringOXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringMariano Rodriguez-Muro
 
Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Erik Bernhardsson
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)pushpalathakrishnan
 
e computer notes - Binary search tree
e computer notes - Binary search treee computer notes - Binary search tree
e computer notes - Binary search treeecomputernotes
 
Path compression
Path compressionPath compression
Path compressionDEEPIKA T
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversalIntro C# Book
 
Dictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix FactorizationDictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix FactorizationArthur Mensch
 
lecture 11
lecture 11lecture 11
lecture 11sajinsc
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.pptplagcheck
 
Home Page Live(Www2007)
Home Page Live(Www2007)Home Page Live(Www2007)
Home Page Live(Www2007)tomelf2007
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
Zippers: Derivatives of Regular Types
Zippers: Derivatives of Regular TypesZippers: Derivatives of Regular Types
Zippers: Derivatives of Regular TypesJay Coskey
 
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
 
Fusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with ViewsFusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with ViewsPhilip Schwarz
 
ensembles_emptytemplate_v2
ensembles_emptytemplate_v2ensembles_emptytemplate_v2
ensembles_emptytemplate_v2Shrayes Ramesh
 

Similar to Persistent Search Trees (20)

17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Red black trees
Red black treesRed black trees
Red black trees
 
OXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringOXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriring
 
Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)
 
e computer notes - Binary search tree
e computer notes - Binary search treee computer notes - Binary search tree
e computer notes - Binary search tree
 
Path compression
Path compressionPath compression
Path compression
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
unit06-3-Trees.pdf
unit06-3-Trees.pdfunit06-3-Trees.pdf
unit06-3-Trees.pdf
 
Dictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix FactorizationDictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix Factorization
 
lecture 11
lecture 11lecture 11
lecture 11
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Home Page Live(Www2007)
Home Page Live(Www2007)Home Page Live(Www2007)
Home Page Live(Www2007)
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Zippers: Derivatives of Regular Types
Zippers: Derivatives of Regular TypesZippers: Derivatives of Regular Types
Zippers: Derivatives of Regular Types
 
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
 
Fusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with ViewsFusing Transformations of Strict Scala Collections with Views
Fusing Transformations of Strict Scala Collections with Views
 
ensembles_emptytemplate_v2
ensembles_emptytemplate_v2ensembles_emptytemplate_v2
ensembles_emptytemplate_v2
 

More from 🌳 Olivier Pirson — OPi 🇧🇪🇫🇷🇬🇧 🐧 👨‍💻 👨‍🔬

More from 🌳 Olivier Pirson — OPi 🇧🇪🇫🇷🇬🇧 🐧 👨‍💻 👨‍🔬 (9)

Parallel Numerical Verification of the σ_odd problem
Parallel Numerical Verification of the σ_odd problemParallel Numerical Verification of the σ_odd problem
Parallel Numerical Verification of the σ_odd problem
 
An Efficient and Parallel Abstract Interpreter in Scala — 3x3 Parallel Implem...
An Efficient and Parallel Abstract Interpreter in Scala — 3x3 Parallel Implem...An Efficient and Parallel Abstract Interpreter in Scala — 3x3 Parallel Implem...
An Efficient and Parallel Abstract Interpreter in Scala — 3x3 Parallel Implem...
 
An Efficient and Parallel Abstract Interpreter in Scala — First Algorithm
An Efficient and Parallel Abstract Interpreter in Scala — First AlgorithmAn Efficient and Parallel Abstract Interpreter in Scala — First Algorithm
An Efficient and Parallel Abstract Interpreter in Scala — First Algorithm
 
An Efficient and Parallel Abstract Interpreter in Scala — Second Presentation
An Efficient and Parallel Abstract Interpreter in Scala — Second PresentationAn Efficient and Parallel Abstract Interpreter in Scala — Second Presentation
An Efficient and Parallel Abstract Interpreter in Scala — Second Presentation
 
An Efficient and Parallel Abstract Interpreter in Scala — Presentation
An Efficient and Parallel Abstract Interpreter in Scala — PresentationAn Efficient and Parallel Abstract Interpreter in Scala — Presentation
An Efficient and Parallel Abstract Interpreter in Scala — Presentation
 
An Efficient and Parallel Abstract Interpreter in Scala — Preparatory Work — ...
An Efficient and Parallel Abstract Interpreter in Scala — Preparatory Work — ...An Efficient and Parallel Abstract Interpreter in Scala — Preparatory Work — ...
An Efficient and Parallel Abstract Interpreter in Scala — Preparatory Work — ...
 
Dualité lagrangienne
Dualité lagrangienneDualité lagrangienne
Dualité lagrangienne
 
Brief journey in the big world of Integer Programming with the Knapsack
Brief journey in the big world of Integer Programming with the KnapsackBrief journey in the big world of Integer Programming with the Knapsack
Brief journey in the big world of Integer Programming with the Knapsack
 
Disjoint Compatible Perfect Matchings
Disjoint Compatible Perfect MatchingsDisjoint Compatible Perfect Matchings
Disjoint Compatible Perfect Matchings
 

Recently uploaded

Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡anilsa9823
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsSumit Kumar yadav
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
DIFFERENCE IN BACK CROSS AND TEST CROSS
DIFFERENCE IN  BACK CROSS AND TEST CROSSDIFFERENCE IN  BACK CROSS AND TEST CROSS
DIFFERENCE IN BACK CROSS AND TEST CROSSLeenakshiTyagi
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRDelhi Call girls
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 

Recently uploaded (20)

Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
 
Botany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questionsBotany krishna series 2nd semester Only Mcq type questions
Botany krishna series 2nd semester Only Mcq type questions
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
DIFFERENCE IN BACK CROSS AND TEST CROSS
DIFFERENCE IN  BACK CROSS AND TEST CROSSDIFFERENCE IN  BACK CROSS AND TEST CROSS
DIFFERENCE IN BACK CROSS AND TEST CROSS
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCRStunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
Stunning ➥8448380779▻ Call Girls In Panchshil Enclave Delhi NCR
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 

Persistent Search Trees

  • 1. Persistent Search Trees Presentation from the article Planar Point Location Using Persistent Search Trees of Neil Sarnak and Robert E. Tarjan Olivier Pirson INFO-F413 Data structures and algorithms December 8, 2016 (Some corrections November 26, 2017) Last version: https://bitbucket.org/OPiMedia/persistent-search-trees/
  • 2. Persistent Search Trees Quick summary Persistance References 1 Quick summary about binary search trees 2 Persistent Search Trees 3 References Persistent Search Trees 2 / 28
  • 3. Persistent Search Trees Quick summary Persistance References Binary search trees 12 23 54 76 9 14 19 67 50 17 72 Figure: Intgr, Wikipedia Each node contains a key (a value, and in general an associated data). All keys in the left subtree are less than the key’s root. All keys in the right subtree are greater than the key’s root. And recursively. Persistent Search Trees 3 / 28
  • 4. Persistent Search Trees Quick summary Persistance References Binary search trees 12 23 54 76 9 14 19 67 50 17 72 Figure: Intgr, Wikipedia A binary search tree constructs a set and provides these operations: access(x): find and return the item with the greatest key less than or equal to x (or a NIL value if doesn’t exist). So if x is in the tree, then return the item with x. insert(x) delete(x) Persistent Search Trees 4 / 28
  • 5. Persistent Search Trees Quick summary Persistance References Binary search trees 12 23 54 76 9 14 19 67 50 17 72 Figure: Intgr, Wikipedia The problem with this tree... Persistent Search Trees 5 / 28
  • 6. Persistent Search Trees Quick summary Persistance References Balanced binary search trees 12 23 54 76 9 14 19 67 50 17 72 Figure: Intgr, Wikipedia height of the tree ∈ O(n), so access(x): O(n) in time insert(x): O(n) delete(x): O(n) in worst case (n = size of the tree = number of nodes) 12 23 54 76 9 14 19 67 50 17 72 Figure: Mikm, Wikipedia With a balanced binary search tree: height of the tree ∈ O(logn), so access(x): O(logn) insert(x): O(logn) delete(x): O(logn) And (n) for space. (Of course, all these complexities depend on the implementation, but it is possible.) Persistent Search Trees 6 / 28
  • 7. Persistent Search Trees Quick summary Persistance References Red–black trees One way to ensure a good balancing and have good complexities: add extra-information in each node rearrange after each modification (with some specific local rotations) 13 8 17 1 25 6 22 NILNIL 27 NILNIL 15 NILNIL 11 NILNILNIL NILNIL Figure: Cburnett, Wikipedia (All NIL can are an unique sentinel.) Red–black trees: (The type of binary search trees used in the article.) A color red or black for each node (in fact 1 bit of information). Add (pseudo)-leaves NIL. Some constraints on colors: every leaf (NIL) is black children of red node are black all descending path contain same number of black nodes These constraints ensure a height in O(logn), with some rotations and recoloring when we insert or delete. Persistent Search Trees 7 / 28
  • 8. Persistent Search Trees Quick summary Persistance References Red–black trees Insertions and deletions require only O(1) rotations and O(logn) recoloring (in worst case, and only O(1) in amortized case). In summary, with some requirements, we have a balanced binary search tree with: Operations in O(logn) and space in Θ(n). Persistent Search Trees 8 / 28
  • 9. Persistent Search Trees Quick summary Persistance References 1 Quick summary about binary search trees 2 Persistent Search Trees 3 References Persistent Search Trees 9 / 28
  • 10. Persistent Search Trees Quick summary Persistance References Volatile data structures If we modify these kind of data structures, we lost the previous versions. Those are volatile data structures. In general, it is exactly what we want. But not always. Persistent Search Trees 10 / 28
  • 11. Persistent Search Trees Quick summary Persistance References Persistent data structures A persistent data structure, it is a data structure that preserve all old versions after any modification. It is also an immutable data structure. That is the old structures are never modified. (From an external point of view. Maybe the internal data are modified, but is not visible.) Instead the structure is modified in place; a new updated structure is build. These two notions are close. Persistence is about all the new updated structure, and immutability is about the old not modified structure. Persistent Search Trees 11 / 28
  • 12. Persistent Search Trees Quick summary Persistance References And now. . . a digression! Immutable data structures are a foundation of functional paradigm languages (like Lisp, ML, Haskell, Scala... and progressively more and more other languages add functional aspects). It was my motivation to choose this subject. I would like more understand immutable data structures. (Maybe soon, I will understand how deal with immutable graphs!) I think it is an important paradigm, and it will more important in the future. First, because it have a mathematical elegance. It is important. But mostly because our computers today, and more after, must be use multiple cores and for that programs must become parallelized programs. Persistent Search Trees 12 / 28
  • 13. Persistent Search Trees Quick summary Persistance References Trivial and stupid way Go back to the persistence. How build a persistent data structure? Persistent Search Trees 13 / 28
  • 14. Persistent Search Trees Quick summary Persistance References Trivial and stupid way Go back to the persistence. How build a persistent data structure? Copy all the current version, and apply the modification on the copy. It works. But it is inefficient! Waste time and space. So, it does not works. Persistent Search Trees 14 / 28
  • 15. Persistent Search Trees Quick summary Persistance References Linked-list example I will show you on a linked-list a better idea and after that we will do the same with binary search tree. Start with a list (2,7,1) And push front 4, and next 0. We obtain a new list, (0,4,2,7,1) Persistent Search Trees 15 / 28
  • 16. Persistent Search Trees Quick summary Persistance References Linked-list example I will show you on a linked-list a better idea and after that we will do the same with binary search tree. Start with a list (2,7,1) And push front 4, and next 0. We obtain a new list, (0,4,2,7,1) If we preserve links to previous versions, we have a persistent data structure. Persistent Search Trees 16 / 28
  • 17. Persistent Search Trees Quick summary Persistance References Very simple And now... let’s do that on a binary search tree... Persistent Search Trees 17 / 28
  • 18. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying Persistent red–black tree with path copying. Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 18 / 28
  • 19. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying We have now a notion of time. We can access to current tree, but also to all past trees. access(x, t) insert(x) delete(x) Only the current tree is modifiable. And each modification implies a path copying. Persistent red–black tree with path copying. Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 19 / 28
  • 20. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying Restart from time = 0, with A, B, D, F, G, H, I, J, K and L in the tree. Persistent red–black tree with path copying. Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 20 / 28
  • 21. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying Restart from time = 0, with A, B, D, F, G, H, I, J, K and L in the tree. Add E, in the time 1. Note that J was changed of color. (Colors are only used for update, so they useless for past version.) Persistent red–black tree with path copying. Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 21 / 28
  • 22. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying Restart from time = 0, with A, B, D, F, G, H, I, J, K and L in the tree. Add E, in the time 1. Note that J was changed of color. (Colors are only used for update, so they useless for past version.) Add M, in the time 2. Persistent red–black tree with path copying. Figure: Partial figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 22 / 28
  • 23. Persistent Search Trees Quick summary Persistance References Persistent search tree with path copying Restart from time = 0, with A, B, D, F, G, H, I, J, K and L in the tree. Add E, in the time 1. Note that J was changed of color. (Colors are only used for update, so they useless for past version.) Add M, in the time 2. Add C, in the time 3. We have preserved the O(logn) complexity of operations. Maybe O(logn + t) for the access operation (it depends on implementation). But we copy a lot of paths. Persistent red–black tree with path copying. Figure: Figure 6 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 23 / 28
  • 24. Persistent Search Trees Quick summary Persistance References Persistent search tree with no node copying We can do better, with no node copying. Instead copying path, we will add links in nodes. Each insertion or deletion cost O(1) space. But we have a time penalty. Access become O(logn logm) (with m maximum number of links in nodes). Persistent red–black tree with no node copying. Figure: Figure 7 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 24 / 28
  • 25. Persistent Search Trees Quick summary Persistance References Persistent search tree with limited node copying We mix the two ways. In each node we allow k extra links. And if no empty link is available then we copy the node. The article of Sarnak and Tarjan study the amortized space cost and conclude that is linear: O(n). The good choice of k depend of what we want (speed or space economy). k = 1 is a good choice by default. Previous methods path copying and no node copying are specific cases of the limited node copying method (corresponding to k = 0 and k = ∞). Persistent red–black tree limited node copying with only one extra link (k = 1). Figure: Figure 8 of Neil Sarnak, Robert E. Tarjan (Ref. 28) Persistent Search Trees 25 / 28
  • 26. Persistent Search Trees Quick summary Persistance References Persistent search tree In summary, with a red–black tree we have built a persistent binary search tree with good complexities: Operations in O(logn) in worst case and space in O(n) in amortized space cost. Applications (of this persistent data structure, or similar): In computational geometry (planar point location problem) Functional languages Incremental backup system Versioning system (like Git, Mercurial, SVN...) ... Persistent Search Trees 26 / 28
  • 27. Persistent Search Trees Quick summary Persistance References 1 Quick summary about binary search trees 2 Persistent Search Trees 3 References Persistent Search Trees 27 / 28
  • 28. Persistent Search Trees Quick summary Persistance References References Thank you! References: Neil Sarnak, Robert E. Tarjan (1986). Planar Point Location Using Persistent Search Trees. Communications of the ACM. 29 (7) pp.669–679 Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. Introduction to Algorithms. MIT Press, 3rd 2009 draw.io LATEX with beamer class Questions time... Persistent Search Trees 28 / 28