S AARLAND U NIVERSITY

Binary Search Trees,
Rectangles and Patterns

László KOZMA

Dissertation for obtaining the title ofDoctor rerum naturalium (Dr. rer. nat.)of the Faculty of Natural Sciences and Technology
of Saarland University

Saarbrücken, Germany
July 2016

iii

Colloquium Information

Date and place:

Friday 16th September, 2016
Saarbrücken, Germany

Dean:

Prof. Dr. Frank-Olaf Schreyer
Saarland University

Chair:

Prof. Dr. Dr. h.c. Wolfgang Paul
Saarland University

Reviewers:

Prof. Dr. Raimund Seidel
Saarland University
Prof. Dr. Dr. h.c. mult. Kurt Mehlhorn
Max Planck Institute for Informatics
Prof. Robert E. Tarjan, Ph.D.
Princeton University

Scientific assistant:

Dr. Tobias Mömke
Saarland University

v

Abstract
The topic of this thesis is the classical problem of searching for a sequence of keys ina binary search tree (BST), allowing the re-arrangement of the tree after every search. Ourcurrent understanding of the power and limitations of this model is incomplete, despite
decades of research. The proven guarantees for the best known algorithms are far fromthe conjectured ones. We cannot efficiently compute an optimal sequence of rotations forserving a sequence of queries (even approximately and even with advance knowledge of the
input), but we also cannot show this problem to be difficult. Sleator and Tarjan conjectured
in 1983 that a simple online strategy for tree re-arrangement is as good, up to a constantfactor, as the theoretical optimum, for every input. This is the famous dynamic optimality
conjecture. In this thesis we make the following contributions to the topic.
• We define in various ways the computational models in which BST algorithms aredescribed and analyzed. We clarify some of the assumptions that are made in theliterature (often implicitly), and survey known results about the BST model. (§ 2)• We generalize Splay, a popular BST algorithm that has several proven efficiencyproperties, and define a set of sufficient (and, in a limited sense, necessary) criteria thatguarantee the efficient behavior of a BST algorithm. The results give new insights into
the behavior and efficiency of Splay (a topic that is generally considered intriguing).
(§ 3)• We study query sequences in terms of their avoided patterns, a natural and general
structural property from combinatorics. We show that pattern-avoiding sequences
can be served much faster than what the logarithmic worst-case guarantees would
suggest. The result complements classical structural bounds such as dynamic finger
and working set. The study of pattern-avoiding inputs generalizes known examples ofeasy sequences, introduces new barriers towards dynamic optimality, and addresses
open questions in the BST model. (§ 4)• We introduce a novel interpretation of searching in BSTs in terms of rectangulations, awell-studied combinatorial structure also known as mosaic floorplan. The connection
to rectangulations gives a new perspective on the BST model. Furthermore, it answers
open questions from the literature about rectangulations and gives simplified proofs
for known results. The relation of BSTs and rectangulations to other structures such
as Manhattan networks is also explored. We see the main value of the presented connections in the fact that they bring new techniques to the study of dynamic optimality.
(§ 5)
Throughout the thesis we state a number of open problems (some well-known, some new).
The purpose of this is to collect in one place information that is scattered throughout theliterature. Furthermore, we attempt to identify intermediate questions (easier than the
dynamic optimality conjecture). The list of problems may help an interested reader instarting research on this family of problems.

vii

Zusammenfassung
Das Thema dieser Dissertation ist das klassisches Problem, Schlüssel in einem binären
Suchbaum (BS) zu suchen. Zurzeit ist unser Verständnis dieses Problems, trotz jahrzehntelanger Forschung, begrenzt. Die beweisbaren Garantien für die bekanntesten Algorithmensind weit von den vermuteten Garantien. Wir können keine optimale Sequenz von Rotationen effizient berechnen, um eine Folge von Abfragen zu bedienen. (Auch dann nicht wenn
wir das Optimum nur approximieren wollen und wenn wir die Angabe im Voraus kennen.)
Wir können auch nicht beweisen dass dieses Problem schwer ist. Sleator und Tarjan haben
1983 vermutet, dass eine einfache online-Strategie für die Reorganisierung eines BS, füralle Eingaben, bis auf einen konstanten Faktor, optimal ist. Dies ist die berühmte Dynamic
Optimality Vermutung. In dieser Dissertation leisten wir zu diesem Thema die Folgende
Beiträge.
• Wir definieren auf verschiedene Weise die Rechenmodelle in denen BS-Algorithmenbeschrieben und analysiert werden. Wir versuchen, manche Annahmen aus der Literatur explizit zu machen, und wir geben einen Überblick über bekannte Ergebnisseüber das BS-Modell. (§ 2)• Wir verallgemeinern Splay, einen berühmten BS Algorithmus, der viele beweisbare
Effizienz-eigenschaften hat, und wir definieren eine Menge von hinreichenden (ineinem gewissen Sinn auch notwendigen) Kriterien, die die Effizienz eines BS-Algorithmus
garantieren. Die Ergebnisse gewähren ein neuen Einblick in das Verhalten des Splay
Algorithmus, ein Thema das oft als verblüffend angesehen wird. (§ 3)• Wir studieren Abfragefolgen bezüglich ihrer Muster-Vermeidung Eigenschaften, eine
generelle und natürliche Familie von Eigenschaften aus der Kombinatorik. Wir zeigen,dass Abfragefolgen die Muster-vermeidend sind, viel schneller bedient werden können
als von den logarithmischen Worstcase-Garantien zu erwarten wäre. Diese Ergebnisseverhalten sich komplementär zu den klassischen strukturalen Grenzen wie “dynamic
finger” oder “working set”. Unser Untersuchung der Muster-vermeidenden Eingaben
generalisiert bekannte Beispielen von einfachen Abfragefolgen, führt neue Barrieren
zur Dynamic Optimality Vermutung ein und wirft neue Fragen im BS Modell auf. (§ 4)• Wir führen neue Interpretationen des BS-Modells ein, die in Beziehung zu Rectangulierungen stehen. Rectangulierungen sind gut untersuchte, auch als Mosaik Tesselierung bekannte Kombinatorische Strukturen. Der Zusammenhang zwischen binären
Suchbäumen und Rectangulierungen gibt einen neuen Einblick ins BS-Modell. Weiterhin beantwortet er offene Fragen aus der Literatur über Rectangulierungen, und gibt
vereinfachte Beweise für bekannte Ergebnisse. Die Beziehungen des BS-Modells undder Rectangulierungen mit anderen Strukturen wie Manhattan-Netzwerke ist aucherforscht. Der wichtigsten Beitrag der dargelegten Beziehungen liegt darin, dass sie
neue Methoden zum Studium der Dynamic Optimality Vermutung bringen. (§ 5)
In der gesamten Dissertation stellen wir zahlreiche offenen Fragen (manche neue, manche
wohlbekannt). Unser Ziel ist es damit, Informationen an einem Ort zu sammeln, die zurzeit
in der Literatur verstreut sind. Außerdem ermitteln wir dazwischenliegende Fragen, dieeinfacher als Dynamic Optimality sind. Die Liste der Fragen kann ein Hilfsmittel für die interresierte Leserin sein, die Forschung über diese Familie von Problemen beginnen möchtet.

ix

Note on collaboration
In § 1 and § 2 mostly known results from the literature are described. The chapters also
contain definitions, examples, and observations that are new to the thesis.
Most of the results in § 3 and § 4 were obtained in collaboration with Parinya Chalermsook,
Mayank Goswami, Kurt Mehlhorn, and Thatchaphol Saranurak. These were published in2015 in conference proceedings [25] and [24]. The presentation was adapted for the thesis
and some strengthened results and new observations were added.
The results in § 5 were obtained in joint work with Thatchaphol Saranurak and were
published in manuscript form in 2016 [62].

xiAcknowledgements
I am grateful to my advisor, Raimund Seidel, for the trust and freedom he afforded me
throughout my doctoral studies. I especially thank him for patiently answering every random
question I asked him over the years (whether or not related to the thesis), and for not insistingthat I should be more focused. He is a role model in both research and teaching, throughhis intuition for important problems and elegant solutions, as well as his kind and friendly
attitude.
I am as well deeply thankful to Kurt Mehlhorn for starting a project on binary search trees
in which I was happy to participate. Besides his many insights and ideas on the topic, thedeepest influence on me were his efficient and systematic approach to research, his precisionand his limitless enthusiasm.
Likewise, I express my gratitude to Robert Tarjan for being on the thesis committee, forreviewing the thesis, and for thoughtful feedback.
The work presented here benefits from many ideas of Parinya Chalermsook, from whom
I also learnt a lot about research in general and efficient presentation of results in particular.
Perhaps the best part of my PhD was working with Thatchaphol Saranurak. Due toour different and complementary ways of thinking, our collaboration was always intensive,productive, and enjoyable. The contributions of Thatchaphol can be found throughout thethesis. Besides his concrete ideas, he also contributed indirectly, via his BST simulator thatwas indispensable for quickly testing (and usually discarding) conjectures.
I found Saarbrücken to be a vibrant center of computer science research, and I wasfortunate to discuss various interesting topics, whether or not research-related, with a diverse
group of people. Besides those already mentioned, I would especially like to name Victor
Alvarez, Karl Bringmann, Radu Curticapean, Lavinia Dinu, Christian Engels, Gorav Jindal,
Shay Moran, Tobias Mömke, Sascha Parduhn, Alexey Pospelov, Raghavendra Rao, Karteek
Srinivasajan. I also thank Meena Mahajan, Nikhil Bansal, and Saurabh Ray, for hosting me
for stimulating research visits.
I gratefully acknowledge the generous financial support from the Department of Computer Science at Saarland University, and at an earlier time from the Graduate School ofComputer Science, and for a connecting three months from the Max-Planck Research School.
I thank Michelle Carnell for wide-ranging advice – especially at the beginning of my stayin Saarbrücken. I also thank Sandra Neumann for her help with all kinds of practical andadministrative matters.
My thanks are due to Rodica Potolea for first showing me the beauty of algorithms
and data structures during my undergraduate studies, and to Eva Cotar for teaching me
programming and thereby steering me towards this field more than two decades ago.
I thank my mother, Zsuzsa Szabó for raising me and my sister Ágnes, and for showing us
the value of learning. I thank my wife Judit for her love, encouragement, and for putting up
with my absence – as well as with my presence – all this time. I am grateful to our children
Sámuel and Mirjam for every moment we spend together, even if they haven’t helped withthe thesis. (To be fair, Samu did offer to help.)

xiiiIn memory of my grandparents
Kozma Mihály and Dr. Szabó Lenke

xv

Contents
Colloquium Informationiii

Abstractv

Zusammenfassungvii

Note on collaborationix

Acknowledgements

xi

1 Introduction
1.1 Binary search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Dynamic optimality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
1
3
6

2 The binary search tree model
11
2.1 The static BST problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 The dynamic BST access problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.1 Offline BST algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.2 Online BST algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2.3 A simple algorithm: Rotate-once . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Other models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.1 Meta-algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.2 Other models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Upper bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.5 More advanced algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.5.1 Move-to-root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.5.2 Splay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.5.3 GreedyFuture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.5.4 Other algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.6 Lower bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.6.1 Wilber’s first lower bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.6.2 Wilber’s second lower bound . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.6.3 Algorithms based on Wilber’s first lower bound . . . . . . . . . . . . . . . 39
2.7 The geometric view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.7.1 Algorithms in geometric view . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.7.2 A closer look at GeometricGreedy . . . . . . . . . . . . . . . . . . . . . . . 48
2.7.3 Lower bounds in geometric view . . . . . . . . . . . . . . . . . . . . . . . . 50
3 Splay tree: variations on a theme
53
3.1 Splay revisited: a local view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.2 Splay revisited: a global view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.3 Sufficient conditions for efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

xvi

3.5
3.6
3.7
3.8
3.9

Monotonicity and locality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
On the necessity of locality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
On the necessity of many leaves . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Depth-halving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Discussion and open questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

63
65
66
68
71

4 Pattern-avoiding access75
4.1 Sequences and patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.2.1 Hidden elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.2.2 Forbidden submatrix theory . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.3 Sequential and traversal access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.4 The main result for Greedy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.4.1 An aside: adaptive sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
W
4.5
-avoiding sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.6 Block-decomposable sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.7 Upper bounds on the lower bounds . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.7.1 Bound on MIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.7.2 Bound on Wilber’s bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.8 Comparisons with other bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.9 Discussion and open questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
5 Binary search trees and rectangulations
99
5.1 Rectangulations and Manhattan networks . . . . . . . . . . . . . . . . . . . . . . 99
5.2 The main equivalences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.2.1 Rectangulation problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.2.2 A tree relaxation problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.2.3 Signed satisfied supersets and rectangulations . . . . . . . . . . . . . . . . 108
5.3 Consequences for rectangulations . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.4 Consequences for Manhattan networks . . . . . . . . . . . . . . . . . . . . . . . . 113
5.5 Consequences for BSTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.6 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
List of open problems

121

List of figures

126

Bibliography

127

1

Chapter 1

Introduction
This thesis is about the binary search tree (in short: BST), a fundamental and ubiquitous data
structure for storing and retrieving data with the help of computers. The statement that the
BST is one of the simplest concepts in computer science is essentially true, but misleading inat least two ways.
First, the idea of a BST is implicitly contained in the problem of searching in sorted
lists, a problem that predates computers by centuries if not millenia (Knuth traces theorigins of searching in sorted lists to the ancient Babilonians [60, § 6.2.1]). The idea ofbalanced binary search is itself very old, appearing in disguise in the bisection method forroot-finding in mathematical analysis (see e.g. the 19th century work of Bolzano [36, p. 308]).
The combinatorial study of structures equivalent to BSTs goes back at least to Euler [79].
Second, behind the apparent simplicity of the humble BST lies a deep well of mathematical complexity. There is a rich literature on various combinatorial, statistical, and algorithmic
aspects of BSTs. Nevertheless, several basic questions are still open, in spite of the intensive
effort of the research community. Perhaps the most intriguing of these questions is the
dynamic optimality conjecture of Sleator and Tarjan from 1983. This question and some of its(easier) relatives are the main motivation for the present work.

1.1 Binary search
While the first binary search was published in 1946, the firstbinary search that works correctly for all values of n did notappear until 1962.

— J ON B ENTLEY, Programming Pearls (1986)
I was shocked to learn that the binary search program that
Bentley proved correct and subsequently tested in Programming
Pearls contains a bug.

— J OSHUA B LOCH (2006)
The [. . . ] proposed fix for C and C++ (Line 6) is not guaranteed
to work by the relevant C99 standard.

— A NTOINE T RUX (2008)

Suppose we need to store a set S of n elements from some ordered universe U and weneed to answer queries of the form: Is a certain element x ∈ U contained in S? In practice,in case the answer is Y ES, we would also want to retrieve some additional data associatedwith x that has been previously stored. However, in this thesis we focus only on answering
membership queries of the above kind, which we also call searching for x.
We refer to elements of U as keys. The fact that they can be ordered is the only assumption
we make on keys – therefore, the only operation we may perform with them are pairwise
comparisons that yield one of the three outcomes (<, >, or =). The search for x consists of a2

Chapter 1. Introduction

sequence of comparisons between x and elements in S. (All comparisons among elementsof S can be performed in advance, before the query.) Clearly, as soon as we find out thatt < x for some key t in S, it becomes pointless to compare x with elements smaller than t ,as the outcomes of such comparisons yield no new information. A symmetric argument
holds if t > x. Therefore, in this model, any reasonable strategy of searching for x in S can be
described as follows.
Search(S, x)
If S is empty, answer N O. Otherwise select some element t ∈ S and compare x with t . If x = t ,answer Y ES. If x < t , remove from consideration all keys greater or equal with t and repeat. If
x > t , remove from consideration all keys smaller or equal with t and repeat.
This process is called binary search. The only remaining detail is the order in whichelements of S are selected for comparison with the searched key x.

O
Q

I
J

D
C

P
S

L

G
E

H

K

M

D

E

F

R
N

F

C

T

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

Figure 1.1: Example of a binary search. We search for the letter E in an alphabetically sorted list of letters. Above is the binary search tree corresponding
to the search strategy.

The order in which elements are selected for comparison (depending on the outcomesof previous comparisons) can be visualized as a binary search tree (Figure 1.1). More than avisualization, the BST can be thought of as the internal representation of the search strategy,
i.e. how it is stored inside a computer.
In informal language, binary search often means balanced binary search, referring to thestrategy in which we compare the search key with (roughly) the median of the remaining
keys, thereby (roughly) halving the number of candidate keys after each comparison.
When searching for a key, we would like to perform as few comparisons as possible.
Typically, we need to perform more than one search, i.e. we want to serve a sequence of
search queries for the same set S. For now we assume that for each search we make a “fresh
start”, i.e. we search from the root of the BST. Without making any assumption on the search
queries (or alternatively, assuming that they are adversarially selected), our best choice is abalanced BST, corresponding to the balanced binary search strategy mentioned before. The
number of comparisons in this case is at most logarithmic in terms of the size of S for eachquery, and simple arguments show that this cannot be improved. On the other hand, given1.2. Dynamic optimality

3

some information about the distribution of queries, we may be able to perform searches withsignificantly fewer comparisons. As an extreme example, if a certain key is queried all thetime, we should compare with that key first (placing that key in the root of the BST), always
obtaining the Y ES answer with one comparison.
So far, we have assumed that the strategy for searching keys is fixed – in other words, thatthe BST underlying the search strategy is a static tree. This is not necessarily the case. In fact,
for some query sequences we can reduce the total number of comparisons by changing thesearch strategy (i.e. the underlying BST) after each search. This is true even if we account forthe cost of changing the tree. The model in which the BST is adapted in response to queries
is called the dynamic BST model, to contrast it with the static BST model in which the BST is
kept unchanged. The “rules” of these models are defined more precisely in § 2.
Finding the best static tree for a given sequence of queries is a well-studied and wellunderstood problem. By contrast, our current understanding of the dynamic BST model isincomplete, despite decades of effort.
A note on terminology. The choice of the term “dynamic” in the above sense is due tohistorical reasons, and we adopt it for compatibility with the literature, although “adaptive”
is perhaps a better term. Unfortunately, “dynamic” has another well-established meaning,
one that is also relevant in the study of BSTs. Informally, a data structure is dynamic if
it supports insertions, deletions, and possibly other operations. This type of “dynamism”
raises a range of interesting questions that have been the main driving force behind the early
development of the BST field. For instance, the question of whether logarithmic query time
can be maintained while allowing efficient insertions and deletions has lead to the invention(or discovery) of AVL trees, red-black trees and other interesting data structures [30]. In thisthesis we use the term “dynamic” only in the first sense and we ignore insertions, deletions,and other operations, focusing only on search queries. This means that the set S is unchanged
throughout the process. As a matter of fact, we only consider successful search queries, which
we also call an access. While this may seem overly reductive, there are reasons to believe thatthe restricted problem already captures most of the complexity of the BST model. In any case,the restricted problem is sufficiently difficult to be worthy of study on its own.

1.2 Dynamic optimality
What is the best way to re-arrange a BST in response to search queries? Intuitively, if anelement is queried again and again, it should be brought closer to the root. The Move-to-root
heuristic of Allen and Munro [7] from 1978 achieves this in a straightforward way. However, as
simple examples show, Move-to-root can be very inefficient, even when compared to a static
BST. The Splay tree algorithm of Sleator and Tarjan [91] from 1983 is a more sophisticated(but still very simple) strategy for BST re-arrangement.
Splay is known to be very efficient and able to adapt to various kinds of useful structure
in sequences of queries. Among its attractive properties, the following stands out: for all
sufficiently long access sequences, the total cost of Splay for serving the sequence (including
both the search and re-arrangement costs) is at most a small constant factor greater than thecost of the best static tree for serving the same sequence. This is called the static optimality
property. The famous dynamic optimality conjecture of Sleator and Tarjan speculates thatfor all sufficiently long access sequences Splay is as good as any dynamic algorithm (again,
allowing the loss of a constant factor). Since 1983, other algorithms have also been proposed
as candidates for dynamic optimality, but it is still not known whether any algorithm meets
this criterion.

4

Chapter 1. Introduction

Let us observe that the dynamic optimality conjecture consists of (at least) three, moreor less distinct questions. The first question is that of computing the best sequence of BST
re-arrangements for serving a given sequence of accesses. Even with advance knowledgeof the access sequence, we currently have no efficient method for solving this problem. If
the dynamic optimality of Splay were true, then we would have on our hands a particularly
simple and efficient method for computing an optimal (up to a constant factor) sequence of
re-arrangements – a task for which we currently have only exponential-time algorithms.
The second difficult question hidden in the dynamic optimality conjecture is whether
there is a significant gap between online and offline algorithms in the BST model. We callalgorithms such as Splay online to stress that they react to search queries one by one, without
advance knowledge of future queries. An offline algorithm is necessarily more powerful,since it can prepare in advance for the entire sequence of queries. How much advantage
does such a knowledge of the future confer to an offline algorithm? The dynamic optimality
conjecture suggests that the answer is: (essentially) none.
The existence of an online algorithm as good as the best offline algorithm is not a priori
guaranteed. Such an algorithm would be optimal not only in the usual worst-case sense,
but on every single input (up to a constant factor). Even if we restrict ourselves to online
algorithms, it is possible that for every input, some different heuristic works well. A third
component of the dynamic optimality conjecture is the suggestion that this is not the case,and that some online algorithm – in fact, one with a very concise description – behaves
well uniformly (i.e. on every single access sequence). The fact that such an optimal online
algorithm (if indeed there exists one) adapts to every possible structure (in the BST model)
can also be seen as a powerful form of learning.
Arguments from information theory show that for most access sequences, no dynamic
BST algorithm can achieve better than logarithmic cost per access, a performance that ismatched even by a static balanced BST. The quest for dynamic optimality can thus be seen
as a hunt for “exotic” sequences, i.e. those that exhibit some kind of structure that can be
exploited in the BST model. Several different kinds of structure have been described in theliterature, but a full characterization remains elusive.
A further reason why the dynamic optimality conjecture is interesting (besides the possible practical relevance) is that the BST model appears to be in the sweet spot where optimality
might be possible, but not obviously so. In computational models more flexible than the
BST model, dynamic optimality is usually impossible: this is because an offline algorithm
can optimally prepare for the future, for instance, by “memorizing” the answer for every
possible input – something an online algorithm can hardly compete with. In models with lessflexibility (e.g. the list update problem [90]), dynamic optimality is possible, but much easierto achieve. If even offline algorithms are weak, then it may be easier for online algorithms to
be competitive.
For an overview of dynamic optimality and the state of our knowledge (as of 2013) werefer to the short survey of Iacono [53]. Needless to say, partly due to its composite nature, thedynamic optimality conjecture seems formidably difficult, and we do not settle it in any of its
forms. Instead, we study certain specific aspects and related questions. We also attempt tountangle some of the questions comprising dynamic optimality, with the goal of identifying
specific easier questions that might inspire further research on the problem. The broader
topics addressed in this thesis are the following:• What is the reason that an algorithm like Splay is efficient and others like Move-to-root
are inefficient? What other algorithms may have the proven attractive characteristicsof Splay? These questions are discussed in § 3. We identify simple and easily verifiable1.2. Dynamic optimality

5

conditions that are sufficient for a BST algorithm to match several of the propertiesof Splay, in other words, to be efficient in a broad sense. We also study to what extent
are these conditions necessary. Our purpose with this study is (i) to better understandthe connection between the relatively simple operations that Splay performs and its
adaptability to sophisticated structure – a connection that is generally considered
mysterious (see e.g. [31]), and (ii) to generalize Splay to a broader “design space” ofefficient algorithms.
• Efficiency of a BST algorithm is understood as good performance on input sequenceswith a certain structure. What are the structures that facilitate fast access in the BST
model? Earlier work has mostly focused (apart from some ad-hoc examples) on abroadly understood “locality of reference”. This means that a query sequence shouldbe easy if the queries have some temporal or spatial (i.e. in key-space) coherence. We
identify a different kind of structural criterion that captures a more global property ofaccess sequences. The new criterion is defined in a negative way: an access sequenceis easy, if it avoids a certain arbitrary finite pattern as subsequence. This criterion
generalizes some previously studied classes of sequences, which can be defined as
avoiding a particular pattern. Some of these special cases are the subject of longstanding open questions, which our results partially address. We also show that there
are online algorithms from the literature that perform well on sequences with such
pattern-avoiding properties. This topic is explored in § 4. Besides the new insighton what makes access sequences efficient, the purpose of studying such structuralproperties is that they serve as concrete intermediate steps towards dynamic optimality.
For instance, it is not currently known whether Splay is efficient on pattern-avoiding
inputs, but we show that it must be, if it is to satisfy dynamic optimality.
• Recent progress on the BST problem has come from a surprising geometric interpretation in which many of the BST concepts and questions can be cleanly reformulated.
This geometric view is due to Demaine, Harmon, Iacono, Kane, and Pǎtraşcu [31]. (Asomewhat similar model was described earlier by Derryberry, Sleator, and Wang [34].)
The results of § 4 also rely on this view. In § 5 we introduce a novel geometric view of the
BST problem. This view connects binary search tree executions with rectangulations, awell-studied combinatorial structure with many uses in computer science, for example
in the context of planar point location. Connections of BSTs and rectangulations withother structures, such as Manhattan networks are also presented. These connections
are explored in § 5. The presented findings are still somewhat preliminary. Besides thegeneral interest in observing hidden connections, the motivation behind these results
is the hope that they lead to new angles of attack on the dynamic optimality problem.
In the remainder of this chapter we review some mathematical terminology, as well as
the basic definitions and facts about binary search trees. In § 2 we define more carefully thedifferent BST models and the algorithmic problem of serving access sequences with a BST(static or dynamic, online or offline). We review known results in this model, including BST
algorithms and known lower and upper bounds on the cost of algorithms. After discussing
the BST model in the classical tree-view, we also describe the geometric view of Demaine etal. and related results.
Throughout the thesis we include short pointers to relevant literature and we mention
open questions, many of them long-standing. However, the work is not intended as acomprehensive survey of even this admittedly restricted topic – rather, it is a biased selectionof problems and results.

6

Chapter 1. Introduction

1.3 Preliminaries
We review some rather standard mathematical notation used throughout the thesis. Further
notation is described when needed.
• Given two almost everywhere positive functions f , g : N → R, we use the usual asymptotic notation: both f (n) = O(g (n)) and g (n) = Ω( f (n)) denote the fact that there exists
a constant c > 0, such that f (n) ≤ c · g (n) almost everywhere. We write f (n) = Θ(g (n)) if
both f (n) = O(g (n)) and f (n) = Ω(g (n)) hold. Both f (n) = o(g (n)) and g (n) = ω( f (n))
denote the fact that for all constants c > 0, we have f (n) ≤ c · g (n) almost everywhere.
• For a positive integer n, we denote [n] = {1, . . . , n}.
• Given x ∈ R, we denote by bxc the greatest integer not greater than x, and by dxe thesmallest integer not less than x.
• By log n we denote the logarithm of n to base 2. Whenever another base is used, it
is explicitly written, e.g. log 3 · log3 2 = 1. By Hn we denote the nth harmonic number,Pi.e. Hn = nk=1 k1 . The approximation Hn = loge (n) + γ + O(1/n) is well-known, wheree ≈ 2.7183 and γ ≈ 0.5772.
• We let [n]m denote the set of all sequences of length m with entries from [n]. S n is theset of all permutations of length n. We often write permutations and other sequences
in inline notation, i.e. we refer to π ∈ S n as (π1 , π2 , . . . , πn ), where πi denotes π(i ). Whenthe entries are small and there is no chance of confusion, we omit the commas, andsometimes the brackets as well, e.g. {231, 213} ⊂ S 3 .
• A subsequence is not necessarily contiguous, i.e. A is a subsequence of B , if it can beobtained from B by deleting an arbitrary number of entries. Given a sequence A and avalue x, we denote by A <x , A ≥x , A =x , etc. the subsequences consisting of all elements
smaller, not smaller, or equal to x respectively.
• Two sequences A = (a 1 , . . . , a n ) and B = (b 1 , . . . , b n ) of the same length are orderisomorphic, if their entries have the same relative order, i.e. a i < a j ⇐⇒ b i < b j
for all i and j . For example, (581) is order-isomorphic with (231).
• A sequence A is π-avoiding, if it has no subsequence that is order-isomorphic with π,
otherwise we say that A contains π. For example, the sequence (4, 7, 5, 2) contains 231
and is 123-avoiding. It is easy to show that if A is π-avoiding, then all subsequences of
A are π-avoiding, and that A is σ-avoiding, for all permutations σ that contain π.
Next, we define the main concepts related to binary search trees and review some basic
results. Results given without reference can be considered folklore.
A binary tree T is a tree with a designated root node denoted root(T ), in which every node
has zero, one, or two child nodes. The children of an arbitrary node x are denoted left(x)and right(x) (referred to as left child or right child). If the left, respectively, right child of x is
missing, we set left(x) = null, resp. right(x) = null. A node whose both children are missing isa leaf. For an arbitrary node x in T we denote by parent(x) the unique node y in T , such thatx is a child of y. By definition, parent(root(T )) = null.
Occasionally we also use T to denote the set of nodes in T . The size of a tree T , denoted|T |, is the number of nodes in T . Observe that in a binary tree of size n, exactly n + 1 of all1.3. Preliminaries

7

the left(·) and right(·) pointers are null. This can be seen as saying that there are n + 1 “slots”
where subtrees can be attached to the tree.
The depth of a node x in a binary tree T , denoted d T (x) or simply d (x) is the number ofedges on the (unique) simple path from x to root(T ). Nodes on this path, including x androot(T ), are called ancestors of x. A node x is a descendant of y exactly if y is an ancestor of x.
We call descendants and ancestors of x other than x itself proper. The subtree consisting of
all descendants of x is called the subtree rooted at x, denoted subtree(x). The subtree rooted
at left(x) is the left subtree of x, and the subtree rooted at right(x) is the right subtree of x.
The depth of a binary tree T is the maximum depth of a node in T . A binary tree of size n isbalanced if its depth is at most c · log n, for some constant c (we may assume c = 2).
With each node we associate a key, usually assumingthat for a tree of size n, the set of keys is [n]. We call sucha tree a tree over [n] and we refer interchangeably to anode and its associated key. A binary search tree (BST)
additionally satisfies the following ordering condition: forevery node x all nodes in the left subtree of x have keys
smaller than x and all nodes in the right subtree of x havekeys greater than x.
The lowest common ancestor of nodes x and y, deFigure 1.2: Example BST over [8] with depth
3. Node 5 is the root, nodes 1, 4, 6 are leafs, noted lca(x, y) is the unique common ancestor of bothd (3) = 2, d (6) = 3, and lca(1, 4) = 2.
x and y that has maximum depth. Observe that x < yimplies x ≤ lca (x, y) ≤ y. See Figure 1.2 for illustration.
The following simple observations express relations between the size and depth of a BST.
Lemma 1.1. For every n ∈ N there is a BST over [n] with depth at most blog nc.
Proof. We prove the following equivalent statement. Let k be such that 2k ≤ n < 2k+1 . Then
there is a BST T of size n, with depth k. Indeed, let 2k be the root of T , and let a BST TL over
L = [2k − 1] be the left subtree of the root, and a BST TR over R = {2k + 1, . . . , n} be the rightsubtree of the root. By induction, both TL and TR can be built such as to have depth at mostk − 1, and thus the depth of T is at most k. (At the base of the induction we have that from asingle element we can build a BST of depth 0.)
Lemma 1.2. In a BST of size n, the depth of more than half of the nodes is at least blog nc − 1.
Proof. For each node x the path from the root to x can be encoded as a unique binary stringof length d (x), where a 0 corresponds to a step to a left child and a 1 corresponds to a stepto a right child. Since for all k ∈ N there are 2k − 1 unique binary strings of length at mostk − 1 (including the empty string), the depth of more than n − 2k nodes is at least k. Setting
k = blog nc − 1 finishes the proof.
Lemma 1.3. The average depth of a node is one less than the average size of a subtree.
Proof. Let T be an arbitrary BST, and let I be the set of proper ancestor-descendant pairs in T ,©
ªi.e. I = (x, y) : x, y ∈ T and x is a proper ancestor of y . The indicator function 1I (x) equals 1
if x ∈ I and 0 otherwise. We count I in two ways.
Xy∈T

d T (y) =X X
y∈T x∈T¡¢ X X ¡¢ X
1I (x, y) =1I (x, y) =(| subtree(x)| − 1).
x∈T y∈Tx∈T

Let C n denote the number of different BSTs over [n]. The numbers C n are the famous¡ ¢1 2n
Catalan numbers [93, 98, 96, 79], given by the formula C n = n+1. Using Stirling’s approxi¡¡n1 ¢¢
4np
mation, one obtains the well-known estimate C n = n 3/2 π 1 + O n .

8Chapter 1. Introduction

Catalan numbers are ubiquitous in mathematics. Stanley [96] lists over 200 different
combinatorial interpretations. Besides BSTs, we mention one other Catalan structure that isused in the thesis.
Lemma 1.4. The number of different 231-avoiding permutations of length n is C n .
Proof. We define a bijection that maps an arbitrary 231-avoiding permutation π ∈ S n to a
BST T over [n]. Let L = (π2 , . . . , πk ) be the longest contiguous subsequence of π after π1 ,consisting of elements smaller than π1 . Observe that all elements in R = (πk+1 , . . . , πn ) are
greater than π1 , for otherwise π would have a subsequence order-isomorphic to 231. (One orboth of L and R may be empty.) Furthermore, the sequences L and R are also 231-avoiding.
By induction, we build a BST with π1 as root and the BSTs recursively built of L and R as theleft, respectively right subtree of the root. (The BST built of an empty sequence is empty.)
The reverse mapping is as follows: given a BST T , build a permutation π, with π1 =root(T ), followed by the sequences πL and πR built recursively from the left, respectively,
right subtree of root(T ). (The sequence built of an empty BST is empty.) The resulting
permutation π is known as the preorder sequence of T .
We argue that π is 231-avoiding. By induction, πL and πR are 231-avoiding. Suppose forcontradiction that π contains a subsequence (x, y, z), such that z < x < y. If x = π1 , then ycannot be in πL , since entries of πL are smaller than x. But then z is in πR , contradicting z < x.
If x is in πL , then z must be in πR (since otherwise πL would contain 231), again contradictingz < x. Thus, x, y, and z are in πR , contradicting that πR is 231-avoiding.
Next, we describe the elementary rotation operation that effects a small local change
in the structure of a BST, while preserving the ordering condition. Rotations in BSTs wereperhaps first used by Adelson-Velskiı̆ and Landis [4] in 1962.
Suppose x and y are neighboring nodes in a BST andx < y. Then either x = left(y) or y = right(x) holds, i.e.
the direction of the edge x y is either  or . A rotation
at the edge x y transforms the BST from one case to theother, re-attaching the children of x and y in the uniqueCA
way determined by the ordering condition, leaving theremainder of the tree unchanged. A rotation requires a
B
B
CA
constant number of pointer-changes, can therefore be
executed in constant time. Rotating twice at the same
Figure 1.3: Rotation in a BST at edge x y.
edge restores the original state of the tree. See Figure 1.3
A, B , C denote subtrees that are unaffected byfor illustration. We choose this definition instead of thethe rotation.
common way of refering to left and right rotations to avoid
confusion about whether clockwise and counter-clockwise correspond to left and right or
the other way around.
The following observation (Culik and Wood [55], 1982) shows that with at most a linear
number of rotations it is always possible to re-arrange one BST into another.
Lemma 1.5 ([55]). Given two BSTs over [n], there is a sequence of at most 2n − 2 rotations
that transforms one into the other. Such a sequence can be found in time O(n).
Proof. We show that with a sequence of at most n − 1 rotations any BST can be transformed
into the right-leaning path, i.e. a tree in which no node has a left child. Start with an arbitrary
BST and consider the right spine of the tree, i.e. the longest path starting from the root,
consisting only of  edges. (As a special case, the right spine may consist of only the root.)
Repeatedly take x, the node of smallest depth on the right spine with the property thatleft(x) 6= null. (If there is no such x, then we are done.) Rotate the edge (x, left(x)). Each such

1.3. Preliminaries

9

rotation increases the length of the right spine by one. Therefore, after at most n − 1 rotations
we reach the canonical tree.
Observe that once a node on the right spine has no left child, it never gains a new one.
Therefore, we can find the rotation sequence by starting a cursor at the root, in each step
performing either a rotation, or moving the cursor one step down on the right spine. The
time for the process is thus O(n). Clearly, the obtained rotation sequence is reversible.
We call the minimum number of rotations necessary to transform one BST into anotherthe rotation distance between the two BSTs. The following stronger result was shown by
Sleator, Tarjan, and Thurston [92] in 1986.
Lemma 1.6 ([92]). The rotation distance between two BSTs of size n is at most 2n − 6. This istight for sufficiently large n.
The proof of the second part of Lemma 1.6 is difficult. Recently, Pournin [84] gave a
combinatorial proof and showed that the bound is in fact tight for n ≥ 11. The following is an
outstanding open question already raised implicitly in 1982 by Culik and Wood.
Problem 1. Can the rotation-distance between two BSTs be computed in polynomial time?
Questions about rotation-distance in BSTs are often studied in an equivalent setting thatinvolves flips in triangulated convex polygons [92, 97]. Certain geometric generalizations of
this problem have been shown to be NP-hard [5, 83, 67], but Problem 1 remains open.
At the end of this chapter we review a useful method for building binary search trees.
Besides the BST ordering condition described earlier, we define the heap-order conditionof a binary tree as follows. A binary tree is in heap-order if for every non-root node x wehave parent(x) ≤ x. Consider a sequence of distinct integers π, and a sequence of integers
τ, both of length n. Let T be a binary tree of size n, where node i is associated with thepair (πi , τi ), for all i ∈ [n]. We say that T is a treap over (π, τ), denoted as T = treap(π, τ), if
T satisfies the BST ordering condition with respect to the first entry of each node, and theheap-order condition with respect to the second entry of each node. To simplify notation,if π = (1, . . . , n), we denote treap(τ) = treap(π, τ). Given π and τ, constructing treap(π, τ) is
straightforward. Treaps were studied by Seidel and Aragon [88] in 1996 and shown to be an
efficient data structure if the sequence τ is chosen randomly. Essentially the same structure(sans randomness) was called Cartesian tree and described in 1980 by Vuillemin [104].
It is easy to see that if all elements of τ are distinct (e.g. if τ is a permutation), thentreap(π, τ) is unique: by the heap-order condition, the node with the minimum τ-entry must
be the root, which splits the remaining nodes into left and right subtrees, according to theordering condition on the π-entries. We can continue the process recursively. On the other
hand, fixing the π-entries, the permutation τ that generates a given BST as a treap is notunique. This can be seen by comparing the number of different permutations (n!) with thenumber of different BSTs (C n ). An example treap is shown in Figure 1.4.

10Chapter 1. Introduction

Figure 1.4: Treap constructed from the sequences π = (1, 2, 3, 4, 5, 6, 7, 8) andτ = (7, 4, 8, 6, 1, 3, 5, 2).

11Chapter 2

The binary search tree model
The reason for this geometry is so that every militant will know
only three members in the entire organization: his commander
who has chosen him, and the two members that he himself has
chosen.

— C OL . M ATHIEU, The Battle of Algiers (1966)

In this chapter we define the BST access problem and we describe various known algorithms for this problem. A BST algorithm can be static or dynamic, and it can be offline oronline. We define suitable computational models in which such algorithms can be studied,
and we survey various results and questions about these models. The definitions are relied
upon in all subsequent chapters.
In all cases, the problem we want to solve is to execute a sequence of accesses in a BST,
each access starting from the root. In the static model the BST is fixed throughout the process,whereas in the dynamic model, the BST can be restructured between accesses, paying acertain extra cost in the present, in order to reduce the cost of future accesses. Dynamic BST
algorithms can be online or offline. Both online and offline algorithms execute the sequenceof accesses in the given order. The difference between the two is that online algorithms
process an access sequence one element at a time, without advance knowledge of future
queries, whereas offline algorithms read the entire access sequence at once and compute thestrategy for the entire sequence.
In the static and the dynamic offline cases the definition of the underlying cost model isstraightforward. In the case of dynamic online algorithms the situation is murkier: currently,
certain statements about online algorithms can be shown only if the underlying model issufficiently flexible. Ideally, our model should be simple and mathematically clean (to allow
us to argue concisely about it), as well as realistic (i.e. close to capturing how an algorithm
is plausibly implemented in a real programming language, on a real computer). As it often
happens, it is difficult to satisfy both goals at the same time.

2.1 The static BST problem
Let T be a BST over [n]. Accessing a key x ∈ [n] in T means starting at root(T ) and following
left(·) and right(·) pointers until node x is reached.
Access(T, x)
1. Let r = root(T ).
2. If r = x, return Y ES. If r > x, let r = left(r ), otherwise let r = right(r ). Repeat 2.
Recall that we are making the (non-trivial) assumption, that x is eventually found in
T . For this reason, we can assume that the assignments in step 2 always succeed. The
correctness of the algorithm follows easily from the ordering condition of the BST.

12

Chapter 2. The binary search tree model

We call the path between root(T ) and the accessed node x the search path of x. We takethe cost of accessing x in T , denoted costT (x) to be the number of times step 2 is executed,
which equals the number of nodes on the search path, or equivalently, one more than thedepth of x in T . We thus define costT (x) = d T (x) + 1.
Let X = (x 1 , . . . , x m ) ∈ [n]m be a sequence of accesses. In the standard static BST problem
we assume that every access starts from the root (a.k.a. root-access model). The total cost ofaccessing X in T , denoted costT (X ) is then simply
costT (X ) =

m
X
i =1

costT (x i ) = m +mXd T (x i ).

i =1

If T is a balanced BST, then for all x ∈ [n] we have costT (x) = O(log n), and therefore,
costT (X ) = m · O(log n). For certain sequences X a significantly better performance canbe achieved with a well-chosen tree T .
Let us denote OPTstat (X ) = minT costT (X ). In words, OPTstat is the cost of accessing
sequence X with the best static BST for this sequence. The term static refers to the fact thatthe tree T does not change during the execution. The quantity OPTstat (X ) is called the static
optimum for X . Observe that OPTstat (X ) depends only on the frequencies of elements in X ,and not on the exact ordering of entries. In fact, OPTstat is known to be asymptotically equal
to the Shannon entropy of the frequency-distribution. (Intuitively, this quantity captures how“uniform” is the distribution – the quantity is maximized if all frequencies are equal.)
The best static BST for a given sequence can be found efficiently. The dynamic programming algorithm given by Knuth [58] in 1971 achieves this in time O(n 2 ). Mehlhorn [72] gavein 1975 a linear time algorithm that computes a solution with cost at most a small constantfactor away from the optimum. Let us summarize these results.
Theorem 2.1. For an arbitrary access sequence X ∈ [n]m let n i be given for every i ∈ [n],denoting the number of times key i appears in X .
(i) [58] There is an algorithm that finds in O(n 2 ) time a BST T with costT (X ) = OPTstat (X ).
¡¢(ii) [72] There is an algorithm that finds in O(n) time a BST T with costT (X ) = O OPTstat (X ) .
³P´(iii) [72] OPTstat (X ) = O ni=1 n i log nim+1 .
As far as we know, it is open whether the running time of Knuth’s algorithm can be
improved. Note that the Hu-Tucker and Garsia-Wachs algorithms have O(n log n) runningtime, but solve a variant of the problem where all keys need to be placed in the leaves of thetree [60, § 6.2.2].
Problem 2. Given the access frequencies of n elements, can the optimum static BST becomputed in time o(n 2 )?

2.2. The dynamic BST access problem

13

2.2 The dynamic BST access problem
Suppose again, that we want to access a sequence of keys X = (x 1 , . . . , x m ) ∈ [n]m in a BST. Let
us always require m ≥ n. Again, we assume that every access starts from the root of the tree.
This time, however, we allow the tree to be re-arranged during the process by performing therotation described in § 1.3 in various parts of the tree. The purpose of the re-arrangement
is to adapt the BST to the access sequence, in order to reduce the total access cost. (Forinstance, elements that are accessed very frequently should be brought closer to the root.)
The question of how to do this efficiently is the dynamic BST problem.
In this case, we can no longer describe a canonical algorithm for accessing keys as we
did in the static model. Instead, we define in a more generic way the input and output of a
dynamic BST algorithm. We call such a description a BST model. A model can be thoughtof as a family of algorithms. There are different ways to formalize the various BST models,
and the fact that we afford to lose small constant factors in the cost makes the task easier.
For example, we need not worry about the exact cost of a rotation compared to the cost offollowing a pointer in the tree, as long as we can assume that the ratio between the two costs
is constant.

2.2.1 Offline BST algorithms
First, we define the offline BST model. From several possible alternative definitions we
present two, loosely following Wilber [106] and Demaine et al. [32, 31]. The first definition isperhaps more intuitive and closer to how a BST algorithm might be implemented in practice.
The second definition is mathematically cleaner, and illustrates the point that the particular
way in which rotations are performed does not significantly affect the cost model. Later weprove that the two models are equivalent, up to a small constant factor.
Offline BST algorithm A for serving X(first model)
1. Read the sequence X = (x 1 , . . . , x m ) ∈ [n]m .
2. Output an initial BST T0 over [n].
3. Output a valid sequence S = (S 1 , . . . , S | S | ) of operations, consisting of elements from©
ªmoveleft, moveright, moveup, rotate, find .
We say that S is valid, if the operations S 1 , . . . , S | S | can be executed sequentially, startingwith the BST T0 , as follows. Let a cursor initially point to the root of T0 . If at step i we haveS i ∈ {moveleft, moveright, moveup}, then move the cursor from its current node to the leftchild, right child, respectively parent node. If S i = rotate, then perform a rotation on the edge
between the node of the cursor and its parent. If S i = find, then move the cursor to the rootof the current tree. In addition, we require that find appears exactly m times in S and when it
is issued the j th time, for all j , the cursor must point to the node x j .
The cost of accessing X by algorithm A, denoted costA (X ) is defined to be the total
number of operations output by A, i.e. costA (X ) = | S |.

14

Chapter 2. The binary search tree model

Offline BST algorithm A for serving X(second model)m
1. Read the sequence X = (x 1 , . . . , x m ) ∈ [n] .
2. Output an initial BST T0 over [n].
3. Output a valid sequence Q = (Q 1 , . . . ,Q m ) of BSTs, each over some subset of [n].
We say that Q is valid, if the trees Q 1 , . . . ,Q m can be interpreted as a sequence of transformations applied to the initial BST T0 , with the following rules. For all i ∈ [m], the keys in Q iform a subtree of Ti −1 , and we have x i ∈ Q i , and root(Ti −1 ) ∈ Q i .
The BST Ti is obtained by replacing the subtree of Ti −1 consisting of the keys of Q i withthe tree Q i . Observe that Q i contains the search path of x i in Ti −1 (and possibly other nodes).
As the exchanged subtrees are over the same set of keys, the subtrees hanging from themcan be re-attached in the unique way determined by the ordering condition. We say that thenodes of Q i are touched at time i .
The cost of accessing X by algorithm A, denoted costA (X ) is defined to be the sum ofP
the sizes of all trees in the sequence output by A, i.e. costA (X ) = m
i =1 |Q i |.
The term offline in the previous two definitions refers to the fact that the algorithms readthe entire access sequence at once. We now define the most important quantity of this thesis.
Definition 2.2. The offline optimum for a sequence X , denoted OPT (X ) is defined as
OPT (X ) = minA costA (X ), where A is an offline BST algorithm.
The definition of OPT depends on whether we use the first or the second model. Let us de©
ªnote the respective quantities by OPT1 and OPT2 , and let OPT(X ) = min OPT1 (X ), OPT2 (X ) .
This distinction is not essential, as we will show that the two quantities differ by a small constant factor only. Let us first observe the following fact.
Theorem 2.3. For all X , we have OPT1 (X ) ≤ OPTstat (X ) and OPT2 (X ) ≤ OPTstat (X ).
Proof. In both dynamic offline models we can simulate static access by restricting ourselves:
In the first model, by not using rotate operations, and in the second model, by letting Q i be
the search path to x i in T0 , for all i . The claim follows.
As mentioned before, the quantity OPT is rather mysterious. It is not known, for instance,
if it is possible to efficiently compute it, or to approximate it by a constant (or slightly superconstant) factor.
Problem 3. Given X ∈ [n]m is it possible to compute OPT (X ) in polynomial time? What isthe best approximation computable in polynomial time?
Currently the best upper bound for OPT(X ) is the cost of the Tango tree algorithm of
Demaine, Harmon, Iacono, and Pǎtraşcu [32] from 2004, which overestimates OPT(X ) by afactor of O(log log n). (See § 2.6.3.)
Computing OPT exactly is possible, if we can afford exponential-time. Observe that eventhe existence of an exponential-time algorithm is not obvious. As the length of the optimal
sequence of operations may be m · Ω(log n), the naïve way of trying every possible sequenceof pointer-moves and rotations (according to the first model) would take, for some inputs,
time c m·Ω(log n) , for some constant c. The following algorithm was suggested to the author by
Raimund Seidel.
Theorem 2.4. Given X = (x 1 , . . . , x m ) ∈ [n]m , we can compute OPT1 (X ) in time O ∗ (4n ), whereO ∗ (·) hides a factor polynomial in m and n.

2.2. The dynamic BST access problem

15

Proof. Build a directed graph whose vertices are all C n possible BSTs over [n], annotated bya value from [n] indicating the location of the cursor, and a value from [m] ∪ {0} indicating
which of the m accesses have already been performed (if any). From each vertex we add edges
to other vertices according to the operations moveleft, moveright, moveup, rotate, find fromthe first offline BST model. Recall that moveleft, moveright, moveup, and find change thelocation of the cursor, and rotate changes the structure of the tree. The edges corresponding
to these operations will thus point to vertices where the cursor location or the tree are updated
accordingly. Edges for find are used only if the cursor in the current vertex points to the next
key to be accessed. A find-edge points to a vertex in which the second indicator value isincremented and the cursor is moved to the root. We also add a start vertex with edges to all
vertices that have the cursor at the root and the second indicator value 0, and an end vertex
with edges from all vertices that have second indicator value m. The execution of an offline
algorithm with a certain cost on X is mapped now to a path from start to end of the samelength, and vice versa. Finding the optimal sequence is thus reduced to finding a shortest
path in an unweighted directed graph with m · O(n · C n ) vertices and edges (every vertex has
constant outdegree). Using breadth-first search, we get a total running time of O ∗ (4n ).
Theorem 2.5.
(i) Given an offline BST algorithm A in the first model, we can simulate it with a BST
algorithm B in the second model, such that costB (X ) ≤ costA (X ), for all X .
(ii) Given an offline BST algorithm B in the second model, we can simulate it with a BST¡¢
algorithm A in the first model, such that costA (X ) = O costB (X ) , for all X .
Proof.
(i) Let algorithm B output the same initial tree that A outputs. Let f i denote the index
in S of the find operation corresponding to the access x i . For all i ∈ [m] consider thecontiguous subsequences S i = (S f (i −1)+1 , . . . , S f (i ) ), with the convention that f (0) = 0.
Observe that A executes S i starting with the tree Ti −1 , and ending with the tree Ti . Let
R i denote all the nodes to which the cursor points at least once while A executes S i . The
nodes R i form a subtree of Ti , which we denote by Q i . (This can be seen by induction,and easily verified for all five types of operations in S i .) Furthermore, R i contains theroot of Ti −1 (since the cursor is there at the start of S i ), and R i contains the accessed
key x i (since the cursor is there before executing the find operation S f (i ) ). We can now
define a sequence of trees Q = (Q 1 , . . . ,Q m ) that are a valid sequence of transformations
by the rules of the second model, and which produce exactly the behavior of algorithm
A. We conclude B by outputting Q.
P
The cost of B is m
i =1 |Q i |, which is exactly the number of nodes visited by the cursor
during the execution of A. Since only moveleft and moveright operations can makethe cursor visit a new node, and at most one new node is visited for either of these
operations, we have costB (X ) ≤ costA (X ).
(ii) Let algorithm A output the same initial tree that B outputs. In A we have to simulate
the transformation from the subtree of Ti −1 with the nodes of Q i to Q i . First we rotate
the subtree with nodes of Q i to a right-leaning path. Starting with the cursor from theroot, we can achieve this with at most |Q i | − 1 rotations and at most |Q i | − 1 moveright
operations (following the process described in the proof of Lemma 1.5). Since the rotate
operation is defined between a node and its parent, and we need to rotate between anode and its left child, we need an additional moveleft operation before each rotate.
Then we execute the reverse process, transforming the right-leaning path over the nodes

16

Chapter 2. The binary search tree modelof Q i into the tree Q i . Again, the number of operations is proportional to |Q i |. After thetransformation is finished, we need to move the cursor from the root to the element x i ,and issue the find operation.
By Lemma 1.5, the total number of operations we issue to simulate the transformation¡¢and the access is O |Q i | . The claim follows.
We finish our discussion of the offline model by mentioning two natural restrictions on
offline BST algorithms. The first is to require that for all i , the accessed key x i is moved to
the root during the re-arrangement, before x i +1 is accessed. We call this the access-to-root
restriction. (In the context of the second model, this means that for all i , node x i is theroot of Q i .) Denote by OPTroot (X ) the cost of the best algorithm for X that conforms to thisrestriction.
The second restriction is to perform re-arrangements in the BST only on the search pathof the current access. We call this the search-path-only restriction. (In the context of thesecond model, this means that Q i contains only nodes of the search path for x i in Ti −1 .)Denote by OPTsp (X ) the cost of the best algorithm for X that conforms to this restriction.
Let OPTsp,root (X ) denote the cost of the best algorithm for X that conforms to both theaccess-to-root and the search-path-only restrictions. The following observation is due toWilber [106].
¡¢
Lemma 2.6 ([106]). OPTroot (X ) = Θ OPT (X ) , for all X .
Proof. Let A be an offline algorithm in the first model that does not necessarily move theaccessed element to the root. For all i , before issuing the i th find operation, if the cursor(pointing to x i ) is not at the root already, we rotate it to the root with a number of rotations
equal to one less than the depth of x i . Observe that this is at most the number of operations
that were used for moving the cursor from the root to x i . We start the next access x i +1 by
undoing the rotations we performed to bring x i to the root, and moving the cursor back to
the root. We then proceed normally to access x i . We increased the total cost only by a small
constant factor.
The relations OPTsp,root (X ) ≥ OPTsp (X ) ≥ OPT (X ) hold by definition, since the minimum cost can not decrease if we compute it over a more restricted set of algorithms. With thesearch-path-only restriction, the argument of Lemma 2.6 does not seem to work, therefore
the following basic question is open.
¡¢
Problem 4. Does it hold for all X that OPTsp,root (X ) = O OPTsp (X ) ?
Lucas [68] describes an ever stronger restriction on BST algorithms: allow only thoserotations that cause the depth of the current access x i to strictly decrease. She conjecturesthat the optimum can be assumed to take this kind of canonical form. We remark that theSplay algorithm (described in § 2.5.2) meets all the restrictions described, therefore, if the costof Splay matches OPT (as conjectured by Sleator and Tarjan), then the answer to Problem 4(as well as to the conjecture of Lucas) is Y ES.

2.2. The dynamic BST access problem

17

2.2.2 Online BST algorithms
Next, we describe the online BST model. We present a number of alternative definitions thatdiffer in the amount of restrictions they place on an online BST algorithm. In contrast to theoffline models, in the online case it is not clear whether there is a significant difference inpower between the various models.
Our first definition is a strict model, inspired by the Splay algorithm, which is seen in§ 2.5.2 and § 3.2 to conform to this model.
Online BST algorithm A for serving X(strict model)
1. Output an initial BST T0 over [n].
2. For each i = 1, . . . , m:
2.1. Read key x i ∈ [n].
2.2. Let P i be the encoding of the search path to x i in Ti −1 .
2.3. Let Q i = Γ(P i ), and compute Ti by replacing the search path to x i in Ti −1 by Q i .
In step 2.2, by an encoding P i of the search path to x i we mean a binary string of thesame length as the search path, whose j th entry is 0 if the j th edge on the path from the root
to x i is to the left (i.e. ), and 1 if the edge is to the right (i.e. ). The binary string P i fully
describes the ordering of the keys on the search path, but ignores the actual key values. The
search path P i is mapped in step 2.3 to a BST Q i = Γ(P i ) of size |P i | + 1, according to a fixed
function Γ. We call Γ the transition function of algorithm A and require Γ to be defined for all
binary strings of length at most n − 1. The BST Q i = Γ(P i ) is over [|P i | + 1], i.e. it may containdifferent keys than those of the search path. The keys from the search path can, however, bemapped in a unique way to the nodes of Q i , governed by the ordering condition. After thisrelabeling, the replacement of the search path with the new tree is done similarly as in thesecond model of offline algorithms.
The cost of accessing X by algorithm A, denoted costA (X ) is defined as the total numberPof nodes in all search paths, or equivalently as costA (X ) = m
i =1 |Q i |.
The definition of the strict model is not standard, let us therefore make some remarkson the particular choices. First, observe that an algorithm in the strict model (called a strict
online algorithm) is rather mechanistic: it consists of an initial BST T0 and a fixed transition
function Γ from search paths to BSTs. Such an algorithm lives in an “eternal present” – asit carries no internal state from one access to another, it has no “knowledge” of previous or
future accesses, or even of its position within the access sequence.
The reader may wonder why we restrict the algorithm to replace (re-arrange) the search
path only, instead of a possibly larger subtree, as in the case of offline algorithms. The main
reason is to stay fully within a comparison-only model: to wander away from the search pathwould mean that the algorithm must base its decisions on administrative details such aswhether a pointer is null or not. The second reason is that we want strict algorithms to operate
only on the keys, forbidding them to the extent possible from “taking notes”, i.e. of carrying
state from one access to the other. If we allow an algorithm to inspect and modify arbitrary
parts of the tree, then it might encode some information in the particular re-arrangements it
makes in certain “out-of-view” parts of the tree. We feel such cleverness to be out of place inthe strict model, since we want the algorithm to behave “uniformly”, i.e. to react the same way
under the same circumstances. Finally, re-arranging only the search path is natural because
a cost proportional to its length is already incurred by the access, so we can conveniently
forget about the cost of re-arrangement, which is (asymptotically) subsumed by the cost of

18

Chapter 2. The binary search tree model

access. (Recall that a BST re-arrangement can be done with a linear number of operations,by Lemma 1.5.)
For an access sequence X we define OPTstr (X ) to be the cost of the best strict online
BST algorithm for X , i.e. OPTstr (X ) = minA costA (X ), where A conforms to the strict online
model. The following observation holds.
Theorem 2.7. For all X , we have OPTstr (X ) ≤ OPTstat (X ).
Proof. In the strict online model we can simulate static access by restricting ourselves, letting
Q i be the unchanged search path to x i in T0 , for all i .
Remark. For a strict online algorithm to be practical, we should require it to compute Γ(P i )using only polynomial time and space. This may seem contradictory, since the size of Γ isclearly exponential. (There are 2n binary strings of length n.) Nonetheless, Γ may have aconcise implicit description, for instance, as a set of rules, e.g. “if there are three consecutive
left-edges, then rotate the one in the middle”, and so on. While a polynomial bound on thedescription of Γ seems reasonable, we can not rule out the possibility that the most efficientalgorithm in this model may have a large and incompressible transition function. Such analgorithm may be interesting theoretically, although possibly unwieldy to argue about. In
this thesis we mostly ignore this aspect of the problem.
Let us also define a few variants of the strict model. First, we can further restrict astrict online algorithm to require that the accessed key is moved to the root during the rearrangement. (This means that x i is the root of Q i , for all i .) We denote by OPTstr,root (X ) the
cost of the best strict online algorithm for X that conforms to this restriction.
The following inequalities result simply from the fact that the optimum over a more
restricted family of algorithms cannot be smaller.
Theorem 2.8. For arbitrary X , we have

OPTstr,root (X ) ≥ OPTstr (X ) ≥ OPTsp (X ) ≥ OPT(X ).
We remark that Splay (§ 2.5.2) conforms to the strict online model even with the restrictionthat the accessed key is moved to the root. Therefore, if Splay is dynamically optimal, thenthe inequalities in Theorem 2.8 collapse to equalities (up to a constant factor). However, each
inequality poses a meaningful (easier) question in itself, and settling any of them would yieldinsight such as whether it is ever worth not bringing the accessed element to the root, whether
there is an online-offline gap in the BST model, and whether it is ever worth wandering off
the search path.
Problem 5. Do any of the following statements hold for all X ?
¡¢• OPTstr,root (X ) = O OPTstr (X ) ,¡¢• OPTstr (X ) = O OPTsp (X ) ,¡¢• OPTsp (X ) = O OPT(X ) .
Theorem 2.8 and Problem 5 concern the cost of the optimum algorithm for a given sequence. We do not know however, if there are concrete algorithms that match these optima
for all sequences. The original dynamic optimality conjecture asks essentially the following.
Problem 6. Is there a strict online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?

2.2. The dynamic BST access problem

19

Based on the previous discussion, we can formulate different questions that are similarly
open, which could however be significantly easier than dynamic optimality. In particular, thefollowing question seems interesting.
Problem 7. Is there a strict online algorithm A such that for all X we have costA (X ) =¡¢O OPTstr,root (X ) ?

We now define an online model that is less restricted than the previous one. We call it
the lenient model. It is in some sense closer to the capabilities of a real implementation andit also captures some of the known algorithms from the literature that fall outside the strictmodel. The main differences of the lenient model compared to the strict model are thatin the lenient model an algorithm may store a small number of bits of annotation at eachnode and it may also perform operations outside the search path. Algorithms with similarcapabilities are sometimes called real-world BST algorithms in the literature [53].
Online BST algorithm A for serving X(lenient model)
1. Output an initial BST T0 over [n].
2. Output initial annotations f : [n] → {0, 1}L , where L = o(log n).
3. For each i = 1, . . . , m:
3.1. Read key x i ∈ [n].
3.2. Output a valid sequence S i of operations, consisting of elements from©
ªmoveleft, moveright, moveup, rotate, read, write(·), compare .
We say that S i = (S 1 , . . . , S | S i | ) is valid, if the operations in S i can be executed sequentially,
starting with the BST Ti −1 and resulting in the BST Ti as follows. For all i , just after reading
key x i (a.k.a. “at time i ”), let a cursor point to the root of Ti −1 . If at step j of executing S i , wehave S j ∈ {moveleft, moveright, moveup}, then move the cursor from its current node to theleft child, right child, respectively parent node. If S j = rotate, then perform a rotation on theedge between the node of the cursor and its parent.
If S j = write(s), for some bit string s of length at most L, then set the value of the annotation f (·) at the cursor to s. If S j = read, then read out the annotation at the cursor into avariable. If S j = compare, then compare the current key value x i with the key value at the
cursor and save the result in a variable.
The algorithm can maintain internal variables, but it is not allowed to carry any stateover from one iteration to the next (i.e. its internal variables are reset at each time i , in step3.1), except via the annotations on the nodes. The annotations read from the nodes and theoutcomes of the comparisons can influence the future operations generated in the sequence
S i . In addition, we require that in each sequence S i there is a compare operation issued
when the cursor points to the node x i . (This plays the same role as the find operation in thefirst offline model.)The cost of accessing X by algorithm A, denoted costA (X ) is defined to be the totalP
number of operations output by A, i.e. costA (X ) = m
i =1 | S i |.
Again, we ignore the computational cost of producing the outputs S i , although we should
expect any reasonable algorithm to perform its computations in polynomial time and space.
The intention in allowing annotations is to let the algorithm maintain simple balancing
and other bookkeeping information. Indeed, some BST algorithms from the literature such

20

Chapter 2. The binary search tree model

as red-black trees or Tango do exactly this. By using annotations, we also avoid the issueof comparing with null pointers, since we can keep track (using a few bits and a small extracost) of which neighbors of a node are present. We can thus assume that the issued moveleft,
moveright, moveup, and rotate operations are always valid.
We limit the number of bits to o(log n), in order to disallow the storage of global depths,
counts of nodes, and other complex information that would require a logarithmic numberof bits. Another motivation for this choice is that in this way, the cost of comparing keys
(which may take Ω(log n) time in realistic models) still dominates other bookkeeping andannotation costs.
The reason for resetting the internal state before every access is to forbid the algorithm
from remembering the structure of the tree. In this way, except for the limited help given by
the annotations, the structure of the tree can be inferred only by exploring it with pointermoves starting from the root (and by paying a proportional cost).
All in all, we tried to define the lenient model such as to be as limited possible, while still
capturing the best known online algorithms.
We define the optimum over algorithms conforming to the lenient model (called lenientonline algorithms) in a similar way as before: for a given X , let OPTlen (X ) = minA costA (X ),where A is a lenient online algorithm. A lenient algorithm can simulate a strict algorithm
restricting itself to re-arranging only the search path, and not using annotations. Thus wehave the following.
Theorem 2.9. For arbitrary X , we have

OPTstr (X ) ≥ OPTlen (X ) ≥ OPT(X ).
Intuitively, OPTlen seems closer to OPT than to OPTstr . This is because a lenient online
algorithm is able to perform the same re-arrangements that an offline algorithm does, apartfrom the fact that an offline algorithm might choose to do different re-arrangements at
different times, even if the current tree and the accessed key are the same (such as to prepare
for future queries). To some extent, a lenient algorithm that is lucky enough to “guess what itshould do” can also simulate this with the use of annotations. However, for arbitrarily longaccess sequences (i.e. if m is very large), an online algorithm cannot encode all sequences ofpossible re-arrangements even if we allow space and time resources superpolynomial in n.
Thus the following are open.
Problem 8. Do any of the following statements hold for all X ?
¡¢• OPTstr (X ) = O OPTlen (X ) ,¡¢• OPTlen (X ) = O OPT(X ) .
If the second statement of Problem 8 holds, then the lenient model is rich enough tocontain a good algorithm for every access sequence. This statement seems quite plausible.
However, even in this case, it does not immediately follow that there is a single lenient online
algorithm that is good for all sequences.
The following question asks exactly this (again, this is simply the dynamic optimality
question for lenient algorithms).
Problem 9. Is there a lenient online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?

2.2. The dynamic BST access problem

21

Finally, we describe an online model with even more capabilities than the lenient model.
We call this the unlimited online model, and we define it such as to differ as little as possible
from the offline model.
Recall that an algorithm conforming to the second offline model outputs an initial tree T0 ,and a sequence of BSTs Q 1 , . . . ,Q m encoding the re-arrangement of the tree, as a function of
the query sequence (x 1 , . . . , x m ). Let us restrict an algorithm only in the fact that T0 ,Q 1 , . . . ,Q m
must not depend on the future.
Online BST algorithm A for serving X(unlimited model)
1. Output an initial BST T0 over [n].
2. Read the sequence X = (x 1 , . . . , x m ) ∈ [n]m .
¡¢3. Output a valid sequence Q = (Q 1 , . . . ,Q m ) of BSTs, where Q i = Λi (x 1 , . . . , x i ) .
The sequence Q encodes tree-rearrangements in the exact same way as in the offlinecase. The cost of an algorithm is also computed the same way. An algorithm conforming to
the unlimited online model is uniquely determined by the initial tree T0 and by the mappings
Λi from access sequences to trees.
We may define the optimum in this model as minA costA (X ), for a given X , where A
conforms to the unlimited online model. Observe, however, that this quantity is exactly thesame as the offline optimum OPT(X ). This is because for every particular sequence X , there
is an unlimited online algorithm that “happens to do the same” for X as the offline optimum.
(Such an algorithm may perform arbitrarily badly on inputs other than X .) This does not
imply, however, that there is an unlimited online algorithm that matches the optimum forevery sequence. This is, in fact, another variant of the dynamic optimality conjecture.
Problem 10. Is there an unlimited online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?
We may ask the easier question of whether there exists an unlimited online algorithm A
competitive with the online optimum, e.g. with OPTstr . Such a result is implied by work of
Iacono [53], which we describe in § 2.3.
The unlimited online model is intended only as a theoretical construction. We find it
interesting that even in such a strong model, the dynamic optimality question is unresolved.
Otherwise, the model is highly unrealistic. First, we have not placed any restriction on how
the functions Λi are stored or computed. To explicitly store Λ1 , Λ2 , . . . , for an arbitrarily longsequence of accesses would require unbounded memory. It would be reasonable, therefore,
to restrict the functions Λi to depend only on the current tree Ti and access x i , instead ofthe entire history of accesses. For an optimal online algorithm to behave differently in two
identical states (depending on the history of accesses) seems to amount to a gambler’s fallacy.
More importantly, even if the action of the algorithm depends only on the current tree, it
is unreasonable that the algorithm should “know” the entire structure of the tree without
paying for its exploration. The lenient model described earlier was designed to address
exactly these issues of the unlimited model.
Initial trees. A somewhat subtle issue for online algorithms (and one that is often swept
under the rug) is that of the initial tree T0 . Observe that all models defined so far leave it to
the discretion of the algorithm to choose an initial tree before serving an access sequence.
The initial tree can therefore be thought of as being a part of the description of the algorithm(i.e. independent of the input). We can think of an algorithm A as a family of algorithms {AT },one algorithm for each choice of the initial tree T . (Note however, that for certain dynamic

22

Chapter 2. The binary search tree model

algorithms not every BST T over [n] may be a valid state, and thus, a valid initial tree. Thiscan not happen in the strict model, where every tree is valid.)
Whenever we say that algorithm A has property P , we should specify which version
AT of the algorithm we are referring to, i.e. with which initial tree the property holds. In
some cases we would like to make the stronger statement that P holds for AT for all choicesof valid initial trees T , i.e. we may say that A has property P even with the worst initialtree. Indeed, most known results for Splay hold in this form, and dynamic optimality is also
conjectured to hold regardless of initial tree. (Intuitively, the effect of the initial tree should
wane for sufficiently long access sequences, although a precise characterization of such abehavior is still missing.)
The question of initial trees is largely irrelevant for offline algorithms, since an offline
algorithm can always start by rotating the initial tree into a tree of its choosing. By Lemma 1.5,
this contributes only a linear additive term to the total cost. With unlimited and lenientonline algorithms, it may seem that we can similarly sidestep the issue of the initial tree,
since a certain agreed-upon initial pattern of annotations can alert the algorithm that it has
just begun accessing the sequence, and it can thus transform the tree into an arbitrary initialtree, again, only with a linear additive term in the cost. However, even if we may choose
an arbitrary initial tree, we may not choose one depending on the (future) access sequence.
What we may nevertheless assume about unlimited and lenient online algorithms is thatthey have no particularly “bad” initial trees – if there were such a tree, then the algorithm
would start by changing it.
For strict online algorithms the issue of initial trees is crucial, since these algorithms do
not know at what stage they are within the access sequence. The choice of initial tree cansignificantly affect the total cost of the algorithm, especially if the access sequence is short.
Therefore, in the strict online model we do not find satisfactory a statement that algorithm A
has property P with an initial tree that depends on P , i.e. on the sequence to be read. (Even
if in some cases the best results we currently have are of this type.)
We define what it means for an online algorithm to be competitive (this is merely adifferent name for approximation-ratio).
Definition 2.10. For some c (possibly depending on n), we say that an online algorithm(strict, lenient, or unlimited) A is c-competitive, if for every access sequence X ∈ [n]m withm ≥ n, we have costA (X ) ≤ c · OPT (X ).
We require m ≥ n, only to avoid the uninteresting case of short sequences where OPT
can be very small, but an otherwise good online algorithm may have high cost (due to the
choice of a bad initial tree). Needless to say, a competitiveness-result is still highly interesting
if it holds only for m ≥ f (n), for some f (n) = ω(n).
The following are perhaps the most important open questions in the online BST model.
Problem 11. Is there an o(log n)-competitive strict online algorithm? Is there an o(log log n)competitive lenient or unlimited online algorithm?
From the previous discussion, it is clear that for every algorithm A in any of the definedmodels, with every initial tree T0 , and for every access sequence X , it holds that OPT (X ) ≤costA (X ). We repeat that the original form of the dynamic optimality conjecture statesthat Splay, a particularly simple algorithm in the strict online model with the access-to-root
restriction has cost proportional to OPT for every access sequence. Proving this conjecture
would be highly desirable, as this would settle Problems 3–11, and would let us avoid further
questions about various models with particular subsets of restrictions and capabilities.

2.2. The dynamic BST access problem

23

2.2.3 A simple algorithm: Rotate-once
To make the discussion more concrete, we describe a simple online BST algorithm called
Rotate-once, introduced by Allen and Munro [7] in 1978. The algorithm is well-defined forany initial BST, and it works in the strict online model (a proof of this fact is left as exercise).
We only specify the operation when accessing a key x i , assuming that the state of the BST
before the current access is T .
Rotate-once(T, x i )1. Access(T ,x i )¡¢2. If parent(x i ) 6= null, then rotate the edge x i , parent (x i ) .
Step 1 is an access as in a static tree, following the search path from root(T ) to x i . Step 2 isa single rotation that brings x i closer to the root (unless x i is already the root). The rotation
can be implemented with only constant additional cost, since after finishing step 1 we have acursor pointing to x i . In any case, since we are in the strict model, we only re-arrange thesearch path, so we can ignore the cost of rotation, as it is subsumed by the cost of access.
We show an example where Rotate-once works very well. Suppose we start with theright-leaning path over [n] as initial tree, and we access the sequence S = (1, 2, . . . , n). The
cost is easily seen to be constant for each access. (At the time of its access, each key isat depth at most 1.) Since we need at least a constant cost per access, the obtained costis asymptotically optimal, i.e. cost(S) = OPTstr (S) = O(n). From Lemma 1.2 it follows that
OPTstat (S) = Ω(n log n), in fact the same would hold for any permutation sequence S. We
have thus shown a separation between OPTstr and OPTstat , illustrating that a dynamic
algorithm can be significantly more efficient than even the best static tree.

Figure 2.1: Rotate-once execution.
(left) Good example after accessing (1, 2, 3, 4), before accessing (5, . . . , n).
(right) Bad example after accessing (n, n − 1, n), before accessing (n − 1, n, . . . ).

Rotate-once is in general, however, not very efficient. Consider the previous exampleof accessing S, with the left-leaning path over [n] as initial tree. The total cost can be seen
to be Ω(n 2 ). As a different example, consider the access sequence S 0 alternating between
accessing n and n − 1 for a sufficiently long time, i.e. S 0 = (n, n − 1, n, n − 1, . . . ), again withthe right-leaning path over [n] as initial tree. Now each access takes time Ω(n), whereas a
simple static tree with n and n − 1 placed close to the root would achieve O(1) cost per access.
Thus we have shown that Rotate-once is not c-competitive for any c = o(n). See Figure 2.1 forillustration. We remark that the choice of a bad initial tree is not essential in either of the twobad examples. It is easy to think of a sequence of accesses that forces Rotate-once into thestate of a right-leaning path or left-leaning path (or any other state), regardless of the initial
tree.

24

Chapter 2. The binary search tree model

2.3 Other models
We describe further ideas and techniques from the literature and we speculate about their
possible relevance to the dynamic optimality question. Some of the described results stretch
the limits of the BST model by requiring an “unreasonable” amount of memory or running
time (in the spirit of the unlimited online model described in § 2.2.2), or they augment the BST
model with further capabilities. Studying such extended models is interesting theoretically,
but ultimately we would like to be able to “simulate” them in a more realistic BST model.

2.3.1 Meta-algorithms
Multiple authors have suggested the application of general techniques from machine learningthat can “simulate” and “combine” multiple algorithms from a broad family.
The best online algorithm. Iacono [53] describes an online BST algorithm that essentially“simulates” all possible online BST algorithms. This “meta-algorithm” is based on the “multiplicative weights update” (MWU) technique.
Informally, MWU solves the following problem: a sequence of events are revealed one by
one (e.g. by nature or by the stock market). In every round, before the event is revealed, we are
to choose an appropriate response for it. Depending on the suitability of our response, we
receive a certain payoff (or penalty). Before every choice, we can consult a number of experts,
each of whom reveal their own responses (likewise, before the event), and we can decide
which one to follow. After each event, we can evaluate how each of the experts performed.
The MWU technique allows us to make our choices such that our total payoff over the longterm is not far from that of the best expert (with essentially no further assumptions). This isachieved by maintaining “scores” (a.k.a. “weights”) for the experts based on their past performance, suitably updated after every event (this is when “multiplication of weights” takes
place). Experts with higher score are more likely followed in the future. For a comprehensive
treatment of the MWU technique, we refer to the survey of Arora, Hazan, and Kale [8].
Let us sketch the idea of Iacono’s approach for an online BST meta-algorithm. We consider
the input access sequence in epochs (i.e. contiguous subsequences) and for each epoch wechoose one of the possible online algorithms to execute, using the MWU technique. (Herethe access sequence within the epoch is the “event”, and the various online algorithms are
the “experts”.) We also evaluate how the other online algorithms would have done on theepoch, and update their scores according to the MWU rules.
To correctly simulate an online algorithm A within an epoch, the meta-algorithm has tobring the tree at the beginning of the epoch into the state in which A would be, if it had beenrunning from the beginning. (Our description differs here from the one in [53].) Assumingthat the epochs are sufficiently long, i.e. of length Ω(n), the cost of this transformation at the
beginning of the epoch does not affect the total cost by more than a small constant factor.
The known bounds for the MWU technique tell us that over a sufficiently long sequence,
the meta-algorithm does not perform much worse than “the best expert in hindsight”, i.e. it
is competitive with the best online algorithm in the simulated class of algorithms. In this way,
we can obtain an unlimited online algorithm whose cost matches OPTstr or even OPTlen .
We stress that the cost of the meta-algorithm includes a huge additive term, so the result
holds only for sufficiently long access sequences.
The result implies that if we had a non-constructive argument for the existence of a
dynamically optimal online algorithm, then we could turn it into a constructive result, i.e.
into an actual online algorithm, as impractical as it may be. (Problem 7 asks whether a similar
result can be shown in a more restricted online model.)2.3. Other models

25

We have not specified the exact online BST model assumed for this result. From the above
description it is clear that the meta-algorithm needs to reside in a model with vastly moreresources than the “simulated” model. The unlimited model is clearly sufficient to simulate
e.g. the strict or the lenient model. In fact, we do not need the full power of the unlimited
model: as the number of possible strict or lenient online algorithms is a function of n only,
the meta-algorithm can also be implemented with time and space requirement depending
on n only (i.e. not on m).
Dynamic optimality? We observe that if the meta-algorithm outlined above could simulate
unlimited online algorithms, then it would be dynamically optimal (since the optimum overunlimited online algorithms matches OPT, see § 2.2.2). We cannot directly do this, however,since unlimited online algorithms require unbounded memory.
Let us instead consider a more restricted family of online algorithms and see underwhat conditions would the meta-algorithm achieve dynamic optimality. Consider again theaccess sequence in epochs of length n, and let x 1 , . . . , x n be the accesses in the current epoch.
Consider the i th access x i , and assume that the online algorithm transforms the current
tree Ti −1 into the tree Ti . The transformation Ti −1 → Ti is governed by a function Λ, i.e.
Λ(Ti −1 ) = Ti . We let Λ depend on the current access x i , as well as on the past accesses in thecurrent epoch, i.e. on x 1 , . . . , x i −1 . Let F denote the family of online algorithms thus defined.
Observe that algorithms in F are more restricted than unlimited online algorithms (theirspace requirement is a function of n only). The number of online algorithms in F is afunction of n, and therefore, the meta-algorithm outlined above can simulate this family (andmatch the optimum over it). Dynamic optimality boils down to whether F is rich enough tocontain an algorithm matching OPT. We don’t know whether this is the case; let us, however,make some simple related observations.
Clearly, the optimal offline algorithm may also be assumed to perform actions dependingon the current epoch only. (At the epoch boundaries we can transform the tree into a
canonical state, increasing the cost by a small factor only.) Consider again the i th access
x i , and assume that the offline algorithm transforms the current tree Ti −1 into the tree Ti .
Whatever effect the past accesses x 1 , . . . , x i −1 may play on our current transformation isalready captured by the current tree Ti −1 . Thus, we may assume that the transformation
Ti −1 → Ti is governed by a function Λ0 that depends on the current access x i , as well as on
the future accesses in the current epoch, i.e. on x i +1 , . . . , x n , but not on the past accesses.
An obvious first observation is that if Λ0 depends on x i only (and not on the futureaccesses), then F does in fact contain Λ0 and the meta-algorithm over F is dynamically
optimal. A more subtle point is that if the optimal offline algorithm Λ0 depends on the future,but is invertible, then the inverse of Λ0 is an online algorithm from F , when ran backwards
in time. Since the offline optimum is invariant to reversing the access sequence, this would
also lead to a dynamically optimal online algorithm.
The requirement for the offline optimum to be invertible seems too strong. (It would
mean that every tree is reachable as the next state, including those trees in which soon-to-beaccessed keys are very far from the root). It remains to be seen whether a relaxed form of thisproperty has some relevance for the dynamic optimality question.
Strong static optimality. While the simulation-technique does not seem to solve dynamic
optimality, it can be used to construct an online algorithm whose cost matches the static
optimum. (This is a special case of Iacono’s result described in the beginning of the section,
since we can restrict attention to static trees, as a special family of “online” algorithms.) Suchan application of the MWU technique is also mentioned by Blum, Chawla, and Kalai [16].

26

Chapter 2. The binary search tree model

Kalai and Vempala [49] derive a similar result using a related, but more practical technique,also resulting in an online algorithm that achieves strong static optimality. (The term “strong”
refers to the fact that OPTstat is matched with a constant factor arbitrarily close to 1, in
contrast to Splay, which matches OPTstat with a larger constant factor.)
Free rotations. This model, studied by Blum, Chawla, and Kalai [16] is similar to the unlimited online model (§ 2.2.2), with the important difference that the cost of an algorithm is only
the cost of access, i.e. the length of the search path, and re-arrangements can be performed
for free in arbitrary parts of the tree.
Blum et al. show that in this (arguably very strong, but still online) model there is analgorithm, again using a variant of the MWU technique, whose cost in this model (i.e. notcounting the re-arrangement of the tree) asymptotically matches the offline BST optimum
OPT on every sequence. It remains an interesting question whether this result can bestrengthened to apply in more restricted online models. In particular, it is not clear how
many rotations the algorithm of Blum et al. typically performs.

2.3.2 Other models
Randomization. In both the strict and lenient online models we required algorithms tobehave deterministically. It is straightforward to extend the models such that the algorithms
can use a certain number of random bits for each access. (In case of the strict model, thiswould mean that the function Γ can produce different re-arrangements for the same searchpath, depending on a parameter which we set randomly.)
It is not clear whether such an extension can significantly improve the cost of an algorithm(in expectation or with high probability). Randomized variants of Splay were studied by
Fürer [46] and by Albers and Karpinski [6]. In both works the random strategies are relatively
simple, e.g. deciding randomly after every access between doing the Splay re-arrangement or
doing nothing, and the improvements are only by small constant factors.
Non-root access. Instead of starting every access from the root, we may allow an algorithm
to start from the location of the previous access. In this model, x i +1 is accessed by first goingup from x i to lca (x i , x i +1 ), then going down to x i +1 , as in a normal access. Even in a statictree, this access model leads to an interesting and non-trivial optimum, studied recently byBose, Douïeb, Iacono, and Langerman [20]. The optimum in this model is called the lazy
finger bound, and Bose et al. show that an approximation to this quantity can be expressed inclosed form. We mention this quantity again in § 2.4.
It is easy to see that the lazy finger bound is at most twice the cost of normal root-accessin the same static tree (since going to the lca is less costly than going to the root, and the costof going to the root is paid for anyway by the access in the root-access model). More difficult
to show is that the lazy finger bound is asymptotically not smaller than the usual offline BST
optimum OPT. This is implied by the result of Demaine, Iacono, Langerman, and Özkan [33].
More strongly, the recent result of Iacono and Langerman [54] shows that the cost of Greedy,
an online algorithm in the lenient model matches the lazy finger bound. We discuss thisagain in § 2.5.3 and § 2.7.
The “lazy finger” approach can also be combined with rotations, i.e. it can be defined ina dynamic model. The result of Demaine, Iacono, Langerman, and Özkan [33] implies thateven algorithms in this powerful dynamic lazy finger model can be simulated with a small
overhead cost by algorithms in the BST model, i.e. with root-access. Surprisingly, this holds
even if we allow a multiple (constant) number of fingers (i.e. pointers) to be used. (Withmultiple fingers, the algorithm can decide which finger to choose when performing an access,2.4. Upper bounds

27

and the finger is left at the location of the access.) Apart from the simple lazy finger bound,
the optimum quantities in these extended models are not well understood yet. For instance,
it is not known whether any online BST algorithm can match the optimum performanceof the best static tree with two or more fingers. We refer to the recent paper [26] for more
information.

2.4 Upper bounds
In this section we review some known upper bounds on OPT from the literature. These arequantities that depend on an access sequence X ∈ [n]m , and are asymptotically at least as
large as OPT (X ). Clearly, the cost of any O(1)-competitive algorithm has to be at or below
these bounds (asymptotically). Thus, the main reason for defining upper bounds is to provide
benchmarks for analyzing and comparing algorithms.
An obvious set of upper bounds on OPT are the costs of known algorithms (online oroffline). Intuitively, if an algorithm wants to match the theoretical optimum, it must firstmatch the costs of all other algorithms. Although simple, this observation turns out to be
useful: to prove that some quantity C is an upper bound on OPT, it is sufficient to design analgorithm (perhaps an offline algorithm tailored to the quantity in question) whose cost is
below C . The kinds of quantities C we are primarily interested in are formulaic, i.e. can be
expressed as some simple function of the access sequence.
Let X = (x 1 , . . . , x m ) ∈ [n]m , where m ≥ n. (For some of the bounds we require m ≥ n log n.)
Perhaps the simplest non-trivial upper bound on OPT (X ) is the quantity m · O(log n). Since
there exist static balanced trees in which every access takes O(log n) time, the cost of any
O(1)-competitive algorithm A has to be costA (X ) = m · O(log n). We call this the balance
condition of a BST algorithm.
¡P¢
A slightly stronger upper bound for OPT (X ) is O m
i =1 log (x i ) . To see that this quantity
is a valid upper bound, consider the BST over [n] whose right spine consists of the nodes
1, 2, 4, . . . , 2blog nc , and where the subtrees hanging to the left of the spine are balanced binary
search trees (over the elements that fall between two neighbors on the spine). This treecorresponds to a doubling binary search, typically used when the size of the searched list is
not known in advance. It is easy to verify that the depth of node j in the constructed tree is at
most 2 · blog j c + 1, for all j ∈ [n]. Bentley and Yao [13] show that the leading constant can be
reduced to 1, using a nested construction.
An even stronger upper bound on OPT is the static optimum OPTstat , i.e. the cost of
executing X with the best static BST (which includes the previously mentioned balanced
trees). We have seen the static optimum to be asymptotically equivalent with the entropy of asequence (Theorem 2.1). An algorithm A matches the static optimality bound, if for all X¡¢(sufficiently long), we have costA (X ) = O OPTstat (X ) .
We have seen in § 2.1 a simple upper bound of a different kind. An algorithm that isO(1)-competitive on sequences of length n must have cost O(n) when serving the sequence
S = (1, 2, . . . , n). This is because Rotate-once with a particular initial tree achieves this cost,
therefore OPT(S) = O(n). This is called the sequential access condition. To make this into awell-defined bound for all sequences of length n, we can define a function that equals n forthe sequence S and +∞ for all other sequences.
Sequential access is a special case of traversal access. A sequence X ∈ S n is a traversal
sequence if it is the preorder sequence of a BST, or equivalently, if it is a 231-avoiding permutation (Lemma 1.4). Observe that (1, 2, . . . , n) is the preorder sequence of a right-leaning path.
We say that an algorithm fulfills the traversal access condition, if it has cost O(n) for all traversal sequences. For an arbitrary traversal sequence X ∈ S n we have OPT (X ) = O(n), although

28

Chapter 2. The binary search tree model

this is less obvious than for sequential access (we discuss this in § 2.5.2 and § 4.3). Traversal
sequences were studied by Sleator and Tarjan [91], who asked whether Splay achieves thetraversal access condition. Particularly for the case of the traversal access condition and its
special cases, when we discuss online algorithms, it is important to specify the choice ofinitial tree.
The upper bounds discussed in the remainder of the section concern “locality of reference”
in a broad sense. With the exception of the lazy finger bound, introduced recently by Bose etal. [20], they were defined by Sleator and Tarjan in the original Splay paper [91].
©
ªLet t X (i ) be the last access time of an element x i , i.e. t X (i ) = max j : j < i and x j = x i . By
convention we set t X (i ) = 0, if x i is accessed at time i for the first time. The working set at time
i is defined as w X (i ) = {x j : t X (i ) < j ≤ i }, i.e. the set of distinct elements accessed since thePprevious access of x i . The working set bound for sequence X is the quantity mi =1 log |w X (i )|,and this quantity is known to be an upper bound on OPT(X ).
Next we define bounds involving “fingers”. The intuition behind these bounds is that anaccess sequence should be easier if its elements are “clustered together”. Let f ∈ [n] be an¡¢P
arbitrary fixed key. The static finger bound is defined as mi =1 log |x i − f | + 1 .
Whereas static finger refers to the distance from a fixed key, the dynamic finger bound¡¢P
depends on distances between successive accesses. It is defined as mi =2 logP|x i − x i −1 | + 1 .
Finally, the lazy finger bound, mentioned in § 2.3, is defined as minT m
i =2 d T (x i , x i −1 ).
Here T is a fixed reference BST, and d T (x, y) is the distance between two nodes x and y in T .
The reference tree T is chosen such as to minimize the total quantity. Intuitively, the lazy
finger bound is similar to the static optimum in that it captures the access cost in a static tree.
However, in the case of static optimum each access starts from the root, whereas in the caseof lazy finger each access starts at the location of the previous access. Despite what mightseem a minor difference, the lazy finger bound turns out to be rather more powerful: with the
exception of working set, it subsumes all other bounds defined in this section, including thetraversal, static optimality, and static and dynamic finger bounds. (By “subsume” we meanthat it is provably asymptotically smaller.) We refer to [20, 54, 26] for details.
Various other upper bounds have been defined in the literature, but those mentioned areperhaps the most important. In § 4 we describe a new class of upper bounds of a different
flavor, generalizing the traversal and sequential bounds discussed above in a natural direction.
Other than serving as benchmarks for BST algorithms, the purpose of the upper bounds
discussed in this section is to capture structural properties that make access sequences “easy”
in the BST model. The easiest sequences are those that can be accessed with constant average
cost per access (i.e. with total cost O(m)). Several such classes of easy sequences are known,
but a full characterization is lacking.
Problem 12. Characterize the sequences X ∈ [n]m (or at least X ∈ S m ) for which OPT(X ) =O(m).
For most of the bounds discussed in this section it is not a priori obvious that any online
algorithm should match them, but this is the case for all of them, although some of thebounds are not known to be matched in the strict online model. We discuss the known results
when we introduce the algorithms to which they apply (see § 2.5.2 and § 2.5.3). Here we state
two questions which we believe to be open.
Problem 13. Is there a strict online algorithm (with a fixed initial tree of its choice) that has
cost O(n) on every traversal sequence of length n?
Problem 14. Is there a strict online algorithm that matches the lazy finger bound?

2.5. More advanced algorithms

29

2.5 More advanced algorithms
2.5.1 Move-to-root
We describe an online dynamic BST algorithm that is more aggressive in its re-arrangement
strategy than Rotate-once. This algorithm, called Move-to-root, was introduced by Allen andMunro [7] at the same time as Rotate-once. It works as follows: after accessing an element x,
it rotates the edge between x and its current parent, until x becomes the root of the tree. The
algorithm is well-defined for any initial BST, and it works in the strict online model. (Again,
this is easy to verify. We return to this fact in § 3.2.) We only specify the operation whenaccessing a key x i , assuming that the state of the BST before the access is T .
Move-to-root(T, x i )1. Access(T ,x i )¡¢2. While parent(x i ) 6= null, rotate the edge x i , parent (x i ) .
In practice, Move-to-root appears to be superior to Rotate-once. In particular, Allen andMunro show that it satisfies the static optimality condition in expectation, if the accesses are
drawn independently at random from the frequency distribution. Nevertheless, a simple
example shows that Move-to-root fails to satisfy the balance condition, in fact it can be forced
to take Ω(n) time per access, thus it is not a contender for dynamic optimality. Such a bad
example is illustrated in Figure 2.2. A similar example shows that Move-to-root has total costΩ(n 2 ) for sequential access if the initial tree is a left-leaning path, therefore it fails to satisfy
the sequential access condition.

Figure 2.2: Move-to-root execution. Starting with an arbitrary initial tree,
access first the sequence (n, n − 1, . . . , 1), transforming the tree into a rightleaning path. Accessing (n, n − 1, . . . , 1) again leaves the tree in the state of aright-leaning path. The total access cost is Ω(n 2 ), whereas the offline optimum is O(n). (left) Tree after accessing (n, n − 1) in the second phase. (right)
Tree after accessing (n, n − 1, n − 2, n − 3) in the second phase.

30

Chapter 2. The binary search tree model

2.5.2 Splay
I see only one move ahead, but it is always the correct one.

— attributed to J OSÉ R AÚL C APABLANCA

Splay is an algorithm introduced in 1983 by Sleator and Tarjan [91]. It resembles Moveto-root, yet its properties are far more sophisticated. Many of the intriguing questions in
the dynamic BST model have first been raised in the context of Splay. The Splay algorithm
conforms to the strict online model (in fact we defined this model just around Splay). This
fact is easy to verify, but we return to it in § 3.2. Splay is well-defined for any initial BST. We
only specify the operation when accessing a key x i , assuming that the state of the BST before
the access is T .
Splay(T, x i )1. Access(T ,x i )2. While parent(x i ) 6= null, repeat:
Let p = parent(x i ) and gp = parent(p).
2.1. If p = root(T ), then rotate (x i , p) and stop.

(ZIG)

2.2. If (x i , p) and (p, gp) are both left-edges or both right-edges, thenrotate (p, gp), then rotate (x i , p).

(ZIG-ZIG)

2.3. Otherwise,rotate (x i , p), then rotate (x i , gp).

(ZIG-ZAG)

Instead of simply rotating x i to the root, Splay considers the next two edges above x i .
(This is unless x i is one edge away from the root, in which case it simply rotates x i to theroot in step 2.1.) If the next two edges on the path from x i to the root are of a different type,i.e. one  edge and one  edge, then we rotate the edge between x i and its parent twice(observe that the original grandparent of x i becomes the parent of x i after the first rotation)(step 2.3). If the next two edges are of the same type, then we first rotate the edge between
the parent and grandparent of x i , and only afterwards we rotate the edge between x i and its
parent (step 2.2). Step 2.2 is the only case in which something different happens compared toMove-to-root. This difference might seem insignificant, but it turns out to affect the behaviorof the algorithm dramatically.
The three different cases are shown in Figure 2.3. Every rotation we perform brings x ione step closer to the root. Therefore, the total number of rotations is exactly the length of
the search path to x i . We thus assume (as we always do in the strict model) that the rotation
cost is absorbed in the cost of access.
We first state some known facts about Splay, then some long-standing open questions.
Theorem 2.11 ([91]). Splay (with arbitrary initial tree) matches the balance, static optimality,
static finger, and working set bounds.
The following theorem was proved by Cole et al. [29, 28] in 2000, resolving the longstanding question of Sleator and Tarjan [91]. The proof is very involved.
Theorem 2.12 ([29, 28]). Splay (with arbitrary initial tree) matches the dynamic finger bound.
We sketch the proof of Theorem 2.11 later. As for Theorem 2.12, we ask the following.

2.5. More advanced algorithms

31

C
A

A

B

B

C

Figure 2.3: Splay local operations. (from top to bottom) ZIG, ZIG-ZIG, andZIG-ZAG cases. x is the accessed element, A, B , C , D denote subtrees thatare unaffected by the transformation. Symmetric cases omitted.

Problem 15. Is there a simpler proof that Splay matches the dynamic finger bound?
The following is a special case of Problem 14. An answer to this question would also yielda new proof for Theorem 2.12, since the lazy finger condition is known to imply the dynamic
finger condition [20].
Problem 16. Does Splay match the lazy finger bound?
The following result was first shown by Tarjan [101] in 1985. Later other proofs were foundthat improve the constant factors in the bound.
Theorem 2.13 ([101, 100, 37, 80]). Splay (with arbitrary initial tree) satisfies the sequential
access condition.
The following questions are related to Problem 13. The first is the original traversal
conjecture of Sleator and Tarjan [91], still wide open. The second is a significantly easier, as
far as we know, still open question.

32

Chapter 2. The binary search tree model

Problem 17.
• Is the cost of Splay (with every initial tree) O(n) for every traversal sequence of lengthn?
• Is the cost of Splay (with some fixed initial tree) o(n log n) for every traversal sequenceof length n?
Towards proving the traversal conjecture for Splay, we are aware only of the following
result of Chaudhuri and Höft [27] from 1993, in which the initial tree depends on the input sequence. Observe that this result also implies that OPT(S) = O(n), if S is a traversal
sequence.
Theorem 2.14 ([27]). The cost of Splay with initial tree T (of size n) for the traversal (preorder)
sequence of T as input is O(n).
Finally, despite the many attractive properties of Splay, and despite its observed good
performance in practice, we currently have no guarantees on its competitiveness (apart fromthe O(log n)-competitiveness that trivially follows from the balance condition).
Problem 18. Is Splay c-competitive for some c = o(log n)?
An easier question that is similarly open:
Problem 19. Is there some c = o(log n), such that the cost of Splay for X is at most c ·OPTstr,root (X )?
In the remainder of the section we sketch the proof of some of the known propertiesof Splay (i.e. Theorem 2.11), in order to introduce some of the tools that are used in § 3.
More precisely, we state the access lemma, a technical condition from which the properties
mentioned in Theorem 2.11 follow. We show that these properties are implied by the accesslemma for every strict online algorithm with the access-to-root property. In § 3.3 we define abroad class of strict online algorithms that satisfy the access lemma. (We also show that thisclass includes Splay.)
Let T be a BST over [n]. Let w : [n] → R>0 be a positive weight function, and for any set
PS ⊆ [n], let w(S) = a∈S w(a). Finally, denote W = w(T ) = w([n]). Sleator and Tarjan [91]define the sum-of-logs potential function
Φ(T ) =X¡ ¡¢¢log w subtree(a) .

a∈[n]

We remark that other potential functions that are of approximately the same magnitude
have also been used in the literature (e.g. [88, 48, 26], [71, § 6.1.2]).
Definition 2.15 (Access lemma [91]). Let A be a strict online BST algorithm with the accessto-root property. Suppose that A accesses a key x in a BST T , re-arranging it into a BST T 0 .
Let P be the search path in T to x. We say that the access lemma holds for A, if there is somefixed constant c > 0 such that for every such access it holds that:µ¶W
0c · |P | ≤ Φ(T ) − Φ(T ) + O 1 + log.
w(x)We state the following without proof, and refer to [91]. Alternative proofs are also given in§ 3.1 and § 3.4.
Theorem 2.16 ([91]). The access lemma holds for Splay.

2.5. More advanced algorithms

33

Observe that the quantity |P | in the access lemma (i.e. the length of the search path) is
exactly the cost of accessing x. Let A be a BST algorithm that satisfies the access lemma.
Then, the total cost of A for serving X (by a telescoping sum argument) is:
Ã
!
m
m
X
X
¢
1¡
W
costA (X ) =|P i | = Φ(Tm ) − Φ(T0 ) + O m +log.
cw(x i )i =1
i =1Here T0 is the initial tree, Ti is the tree after accessing x i , and P i is the search path whenaccessing x i in Ti −1 .
Definition 2.15 is a slightly weaker form of the original [91], but sufficient for our purposes.
The constant factor 1c for the first term of the cost can be removed, if we change the weightsw(·) by a factor of 2c , since this contributes a factor of c to Φ(·). Observe that this does notaffect the constant factor for the other terms, hidden in the O(·) notation.
The proof of the following statement follows the original Splay paper (alternative proofs
for some of these properties are given in [26]).
Theorem 2.17. Let A be a strict online algorithm with the access-to-root property for which
the access lemma holds. Then A fulfills the balance, static optimality, static finger, andworking set conditions.
Proof. Given X = (x 1 , . . . , x m ), we want to bound the total cost of accessing X by A.
Balance. Set the weights w(a) = 1, for all a ∈ [n]. Observing that Φ(Tm ) ≤ n log n yields
costA (X ) = m · O(log n).
Static optimality. Let n i denote the number of times key i appears in X . Setting theweights w(a) = n am+1 for all a ∈ [n], and assuming that m ≥ n log n, we obtain that costA (X ) isless than the entropy bound (Theorem 2.1(iii)).
¡¢2
Static finger. For any fixed f ∈ [n], we set the weights w(a) = 1/ |a − f | + 1 . We observe
P
that w(Ti ) is constant for all i (since k 1/k 2 converges to a constant), and obtain
Ã
!
m
X
¡
¢
costA (X ) ≤ O(n log n) + O m +log |x i − f | + 1 .
i =1Working set. We set the weights w(x i ) = 1/|w X (x i )|2 , where w X (x i ) is the working set attime i , defined in § 2.4. Notice that the weights are now time-dependent, but at all times,©
ªthe weights of the nodes are a permutation of 1/k 2 for k = 1, . . . , n. Initially we can set©
ª
the weights to an arbitrary permutation of 1/k 2 . Observe that we still have that w(Ti ) isconstant for all i . In [91] it is argued that the change of weights after an access (according
to the above scheme) can only make the total potential decrease, and therefore the accesslemma still holds, even with the time-dependent weights (in the case of Splay). This isbecause only the root node (after the access) increases its weight, and for other nodes theweight either decreases or stays the same. From the definition of the potential function Φ itis clear that the root node appears in only one term, the one containing every node – since
we are only permuting the weights, the contribution of this term remains the same.
We observe that the only property of Splay necessary for this argument to go through isthe access-to-root property. Thus, we conclude that the access lemma implies the working set
property for any strict online algorithm with the access-to-root property, since the following
holds:Ã!
m
X
costA (X ) ≤ O(n log n) + O m +log |w X (x i )| .
i =1

34

Chapter 2. The binary search tree modelSemi-splay. A variant of Splay called Semi-splay has also been described by Sleator andTarjan [91]. Here, the ZIG-ZIG case is different: only the rotation (p, gp) is performed, and thealgorithm continues by moving not x, but p towards the root. Semi-splay shares many of theattractive properties of Splay, and it performs less re-arrangements than Splay. It is therefore
preferable to Splay in many applications, even though it does not have the access-to-root
property.

2.5.3 GreedyFuture
Who controls the past controls the future.

— G EORGE O RWELL, 1984

We describe an offline BST algorithm called GreedyFuture, introduced by Lucas [68] in1988 and described independently by Munro [76] in 2000. We define GreedyFuture in thesecond offline model. GreedyFuture satisfies the search-path-only restriction, i.e. after eachaccess it only re-arranges the search path. GreedyFuture is an offline algorithm, in the sensethat its re-arrangement of the search path depends on accesses in the future (hence the name“future”). Informally, it re-arranges the search path in such a way, that the sooner an element
is accessed in the future, the closer it gets to the root (hence the name “greedy”). The initialtree in GreedyFuture can be arbitrary, although we will see that there is a canonical initialtree that plays an important role. Our description is loosely based on Demaine et al. [31].
We only specify the operation when accessing a key x i , and denote by T the BST before
the access. We assume that the sequence of future accesses x i +1 , . . . , x m is known.
GreedyFuture(T, x i )1. Access(T ,x i ) and let P denote the search path.
2. Let p = (p 1 , . . . , p |P | ) be the sorted keys of P , let p 0 = −∞, and p |P |+1 = +∞.
©
ª
3. Let t j = min t : t > i and p j −1 < x t < p j +1 , for all j = 1, . . . , |P |,or t j = +∞ if the set is empty.
¡¢
4. Let τ = t 1 , . . . , t |P | and let Q = treap(p, τ).

5. Replace P by Q in T .
GreedyFuture accesses a key x i in the usual way, following the search path from the root
to x i (step 1). Then, for each key p j in the search path we define the next access time t j , whichis the index of the next access that is on p j , or in the open interval between the predecessor
and successor of p j in the search path. We set this value to +∞ if there is no access in the
future that falls in the interval in question (steps 2 and 3). We then replace the search pathby a treap built of the search path, using the next access times as priorities (steps 4 and 5).
Recall the definition of the treap that guarantees that the root is the node p j with smallest
value t j , i.e. the one which is accessed first in the future. The same property is maintained
recursively in the subtrees of the root.
We observe the following: if the next access x i +1 is in the current search path (say p j ),then it is guaranteed to become the root. This is because its next access time is t j = i + 1, andfor all other keys p k , we have t k > i + 1 (since p j is not contained in any of the open intervals around other keys on the search path). If the next access x i +1 is in one of the subtrees

2.5. More advanced algorithms

35

hanging from the search path, then we have exactly two keys p j and p j +1 in the search pathsuch that p j < x i +1 < p j +1 . In this case, t j = t j +1 = i + 1, and all other next access times are
greater than i + 1. Therefore, one of p j and p j +1 has to become the root, and the other one
its child, according to the tie-breaking decision of the treap. (In the original description of
GreedyFuture, Lucas suggests breaking the tie according to whether the left subtree of p j
or the right subtree of p j +1 is accessed earlier in the future.) The subtrees are built recursively in the same way. Keys on the search path that are not accessed in the future (thosewith next access time +∞) are kept at the bottom of the constructed BST Q i (with ties broken arbitrarily by the treap construction). Figure 2.4 illustrates the execution of GreedyFuture.

Figure 2.4: GreedyFuture execution. (left) Tree before accessing 8. (right)
Tree after accessing 8, with future access sequence(9, 4, 6, 10, 11, 2, 6).
¡¢ GreedyFuture replaces the search path to 8 with treap (4, 6, 8, 10), (2, 3, 1, 1) . The first
sequence consists of the sorted keys in the search path, the second sequence
consists of the future access times of the keys in the search path. Observethat 8 is not accessed in the future, but 9 is accessed at time 1, and it has 8 aspredecessor. Similarly, although 10 is accessed only at time 4, since it is the
successor of 9, it is assigned priority 1.

The initial tree T0 of GreedyFuture can be arbitrary. Since GreedyFuture is an offline
algorithm, we may as well construct T0 depending on the input X . Perhaps the most natural
choice of initial tree is the one in which keys are already ordered by their first access time.
More precisely, let t i = min {t : x t = i }, for all i ∈ [n], again assuming t j = +∞ if j is neveraccessed. Then, let τ = (t 1 , . . . , t n ) and choose the initial tree T0 = treap(τ). The choice of thisinitial tree is natural, because it simulates the normal behavior of the algorithm. If at time
zero GreedyFuture would “touch” every node, the resulting tree would be exactly the tree T0
described above. We will refer to this particular choice of the initial tree as canonical.
GreedyFuture is of interest for two main reasons. First, because it was proposed as atheoretical construction that could plausibly achieve a cost close to the offline optimum.
Second, in a surprising development, Demaine et al. [31] showed in 2009 that GreedyFuture
can be simulated by an online algorithm with asymptotically the same cost. (As we discussin § 2.7, this online algorithm conforms to our lenient online, but not to the strict online
model.) Thus, besides Splay, GreedyFuture and its online variant discussed in § 2.7 are themost promising candidates for dynamic optimality. In the past few years it was shown that
GreedyFuture matches essentially all bounds known to be matched by Splay, and also several
that are not known to be matched by Splay. (To our knowledge the first such bounds were
the pattern-avoiding bounds discussed in § 4. Another recent example is the lazy finger
bound [54].) Furthermore, proofs for GreedyFuture (and its online variant) tend to be simpler
than those for Splay, especially in the geometric model described in § 2.7. In § 5 we revisit
GreedyFuture and give a number of new interpretations for it.

36

Chapter 2. The binary search tree model

We mention some known results about the behavior of GreedyFuture. In 2011, Fox [42]showed that an access lemma similar to Theorem 2.15 holds for GreedyFuture, from which
the results of the following theorem follow. (Observe that GreedyFuture does not have theaccess-to-root property. Nevertheless, the properties can be proven in the geometric view of
GreedyFuture, described in § 2.7.) The balance condition was also independently shown by
Goyal and Gupta [50].
Theorem 2.18 ([42]). GreedyFuture satisfies the balance, static optimality, static finger, working set, and sequential access conditions.
In 2016, Iacono and Langerman showed the following.
Theorem 2.19 ([54]). GreedyFuture satisfies the lazy finger condition.
Similarly as for Splay, we have no non-trivial results about the approximation ratio ofGreedyFuture.
Problem 20. Is there some c = o(log n), such that the cost of GreedyFuture for X is at mostc · OPT (X )?
Problem 21. Is there some c = o(log n), such that the cost of GreedyFuture for X is at mostc · OPTstr,root (X )? Even more specifically, can we bound the cost of GreedyFuture as c times
the cost of Splay?
The performance of GreedyFuture for traversal sequences is studied in § 4 in a moregeneral context and we present several results in this direction. Let us nevertheless state here
an open question that is not answered by our work.
Problem 22. Is the cost of GreedyFuture O(n) for every traversal sequence of length n withevery initial tree?
Finally, we mention again that GreedyFuture can be simulated by an online algorithmwith a constant factor overhead. We discuss this in § 2.7. It is somewhat unsatisfactory that
this online algorithm does not conform to the strict model. Therefore we ask the question.
Problem 23. Is there a strict online algorithm A, and some c = o(log n), such that the cost of
A for every (sufficiently long) input sequence X is at most c times the cost of GreedyFuture
for X ? In particular, is Splay such an algorithm?

2.5.4 Other algorithms
A number of further BST algorithms and families of algorithms have been discussed in theliterature, some of which fit in the strict online model. Generalizations of Splay have also
been studied before (Subramanian [99], Georgakopoulos and McClurkin [48]). We postpone
the discussion of these algorithms to § 3.
A class of BST algorithms of a different flavor are those related to Tango trees, achieving
the currently best known competitive ratio of O(log log n). We discuss these algorithms briefly
in § 2.6.3.

2.6. Lower bounds

37

2.6 Lower bounds
In this section we review known lower bounds for OPT. These are quantities that depend onan access sequence X ∈ [n]m , and are asymptotically at most as large as OPT(X ). Most of theresults in this section are due to Wilber [106].
First, we ask which access sequences are hard, in the sense of requiring a total cost ofm · Θ(log n). The (perhaps surprising) answer is that almost all access sequences are like this.
The following statement due to Blum et al. [16, Thm. 4.1] shows this in a stronger form thanthe original result of Wilber [106]. The proof of Blum et al. relies on an encoding/compression
argument. A similar argument by Kurt Mehlhorn [24, Thm. F.1] works also if we restrict
attention to permutation sequences.
Theorem 2.20 ([16]). The number of access sequences having optimal offline cost (peraccess) k is at most 212k , for all k ≥ 0, regardless of n or m.
Theorem 2.20 also implies that for an access sequence X drawn uniformly at random
from [n]m we have OPT(X ) = m · Ω(log n) with high probability. This can also be shown witharguments about Wilber’s lower bounds (defined later).
Wilber also showed that there exist highly structured individual sequences X ∈ S n , for which OPT(X ) =Ω(n log n). An example of such a sequence is the bitwise
reversal sequence which we describe in more detail, as it
is used in the subsequent discussion (especially in § 5).
For an integer t with 0 ≤ t < 2k , let revk (t ) be thenumber whose binary representation of length k (i.e.
padded from the left with 0s if necessary) is the reverseof the binary representation of length k of t . For instance,
rev4 (3) = 12, since 1100 is the reverse of 0011.
Let n = 2k , for some integer k > 0. We define
R , the bitwise reversal sequence of length n as R n =Figure 2.5: Bitwise reversal sequence¡n¢
R 16 = (0,
8,
4,
12,
2,
10,
6,
14,
1,
9,
5,
13,
3,
11,
7,
15).
revk (0), revk (1), . . . , revk (n − 1) . For instance, we have¢¡
Plot of rev4 (i ), i left-to-right, bottom-to-top. R 8 = (0, 4, 2, 6, 1, 5, 3, 7). It is instructive to look at the geLines connect entries differing in one bit.
ometric plot of R n , as it resembles the projection of ak-dimensional hypercube, suggesting recursive ways of
constructing R n (Figure 2.5). For values of n that are not powers of two, the sequence R n issimilarly defined (we simply truncate at the end). Wilber shows the following.
Theorem 2.21 ([106]). For every n we have OPT(R n ) = Ω(n log n).
We sketch the proof after we describe the first lower bound of Wilber. The two lower
bounds of Wilber are efficiently computable functions of X that yield quantities asymptotically not larger than OPT (X ). Particularly Wilber’s first bound has played an importantrole in the development of algorithms, and the competitive ratios of Tango, Multi-splay, andChain-splay hinge on this bound (§ 2.6.3). Wilber’s second bound is in some sense cleaner,
but so far it has not lead to algorithmic results, certainly not for a lack of trying.

2.6.1 Wilber’s first lower boundWe describe the bound slightly differently compared to the original description [106], in a
way more similar to [32] (the definitions are asymptotically equivalent). The bound has also
been called alternation or interleave bound.

38

Chapter 2. The binary search tree model

Let X = (x 1 , . . . , x m ) ∈ [n]m . Wilber’s first lower bound is parameterized by a reference
BST T over [n]. We denote the bound as W 1T (X ), and define it recursively as follows. Recall
that root (T ) denotes the root of T , and let L(T ) and R(T ) denote the left, respectively rightsubtree of root (T ). We define the crossing number of a sequence X with respect to a valuet , denoted cr(X , t ), as the number of neighboring pairs of entries in X that fall on different
sides of t . More precisely, let¯©
¯ª¯¯ ¯¯©

ª¯¯cr(X , t ) = ¯ i : x i ≤ t ≤ x i +1 ¯ + ¯ i : x i ≥ t ≥ x i +1 ¯.
Wilber’s first bound for X with respect to T is defined as

W 1T (X ) = cr X , root(T ) + W 1L(T ) X ≤root(T ) + W 1R(T ) X >root(T ) .
¡

¢

¡

¢

¡

¢

At the base of the recurrence, we let W 1T (X ) = 0 if T is empty, or if X has fewer than twoelements. Observe that for every BST T over [n], we have W 1T (X ) ≥ m − 1 for all X ∈ [n]m . It
is intuitive to view the lower bound geometrically (Figure 2.6). The following result holds.

Figure 2.6: Wilber’s first©lower ªbound. The access sequence X = (x 1 , . . . , x m )is plotted as a point set (x i , i ) in the plane. Here X = (2, 4, 3, 7, 5, 1, 6). Below
we show the reference tree T (a balanced tree of depth 2). Squares indicate
the crossings. From left to right we show the crossings corresponding to thefirst, second, resp. third levels of the reference tree. The quantity W 1T (X )counts the total number of crossings on all levels.

Theorem 2.22 ([106]). For all X ∈ [n]m , such that m ≥ n, and for all BSTs T over [n], we have¡¢
OPT(X ) = Ω W 1T (X ) .
The dependence on the reference tree makes this lower bound slightly inconvenient. It
is not clear which reference tree is the best for given X , in the sense of maximizing W 1T (X ),although such a tree is certainly computable with a simple dynamic program. In the original
definition, a balanced tree over [n] is used, and this is the choice used in Tango as well(§ 2.6.3). Demaine et al. [32] argue that for any fixed tree T over [n] there is some sequence¡¢X ∈ [n]m , such that W 1T (X ) = O OPT(X )/ log log n . To see this, consider an access sequenceof length m that consists of elements randomly sampled from a path of T of length log n. By
Theorem 2.20, for such a sequence we have OPT(X ) = m · Θ(log log n). On the other hand, it
is not hard to show that in this case W 1T (X ) = O(m).
We know that for a balanced BST T , the gap of Θ(log log n) between W 1T and OPT is
the maximum possible. This is because the cost of Tango is above OPT, but it is at most aΘ(log log n) factor greater than W 1T . For particularly bad choices of T , the gap between W 1T
and OPT can be as large as Θ(log n).

2.6. Lower bounds

39

It remains open, whether Wilber’s first lower bound is tight with a reference tree suitablychosen for the access sequence X . Even with a balanced reference tree, for the above separa¡¢tion it seems essential to query elements repeatedly. Let us denote W 1 (X ) = maxT W 1T (X ) ,and state the following open questions.
¡¢
Problem 24. Prove or disprove that W 1 (X ) = Θ OPT(X ) for all X ∈ [n]m .
¡¢Problem 25. Let T be a balanced BST over [n]. Prove or disprove that W 1T (X ) = Θ OPT(X )for all X ∈ S n .
It is now easy to prove Theorem 2.21. For a balanced BST
T over [n], Wilber’s first lower bound for R n is easily seen to be
W 1T (Rn ) = Θ(n log n). The tree can even be constructed in such a
way that R n produces every possible crossing at every level.

2.6.2 Wilber’s second lower boundThe second lower bound of Wilber [106] does not require a reference tree (informally, the role of the reference tree is played by theMove-to-root algorithm). The bound has also been called funnelbound. The definition below is based on [53].
Given X = (x 1 , . . . , x m ) ∈ [n]m , Wilber’s second lower boundfor X , denoted W 2 (X ), is defined as follows. Let T0 be the rightleaning path over [n], and execute the Move-to-root algorithm(§ 2.5.1) on X , starting with T0 . Let P i be the search path forsearching x i , for each i ∈ [m]. Let n i denote the number of zigzags
on the path P i , i.e. the number of successive pairs of edges in P i
consisting of a  and a  edge. In other words, n i counts thenumber of successive pairs of elements on the search path thatare on different sides of x i (one smaller, one greater). We defineP
W 2 (X ) = m
i =1 n i + m.
There is an alternative, geometric definition of Wilber’s second
lower bound, shown in Figure 2.7. We omit here the proof that thetwo definitions are equivalent, and discuss this in § 2.7.1.

Figure 2.7: Wilber’s second lower
bound. Example sequence X =(5, 8, 3, 2, 6, 4, 1, 7) plotted geometrically. An axis-parallel rectangle withcorners x, y ∈ X is empty, if it hasnonzero area, and it contains nopoints of X \ {x, y}. The funnel of x i is
the set of elements x j with j < i , suchthat x i and x j form an empty rectangle. In the figure, x 6 = 4 is highlighted,
and its funnel shown with rectangles.
Sweeping the funnel with a horizontal line bottom to top, n i counts thenumber of times we switch between
the two sides (left and right) of x i . In
the figure the switches are shown with
Theorem 2.23 ([106]). For all X ∈ [n]m , such that m ≥ n, we have¡¢lines, and n 6 = 2. Wilber’s second
P
OPT(X ) = Ω W 2 (X ) .
lower bound is i (n i + 1).

Nothing seems to be known about the possible gap between
Wilber’s second bound and OPT or the relation between the two lower bounds of Wilber.
¡¢
Problem 26. Prove or disprove that W 2 (X ) = Θ OPT(X ) for all X ∈ [n]m .
¢¡Problem 27. Prove or disprove that W 1 (X ) = Θ W 2 (X ) for all X ∈ [n]m .

2.6.3 Algorithms based on Wilber’s first lower boundWe briefly mention three online algorithms that are based on a similar idea, and that allachieve O(log log n)-competitiveness. All three algorithms rely on Wilber’s first bound, discussed in § 2.6.1. The algorithms mentioned in this section achieve a cost at most anO(log log n) factor greater than the lower bound, consequently their approximation of OPT
is not worse than this factor. (As a second consequence, they show that the gap between
Wilber’s first lower bound and OPT is not larger than this factor.)

40

Chapter 2. The binary search tree model

The detailed description and analysis of these algorithms is out of scope here. We mention
only that their analysis works (informally) by charging the cost of certain operations, i.e. ofrotations and of following pointers to Wilber’s lower bound W 1T , where T is a balanced tree
over [n]. Operations charged to the lower bound can be considered “free”. For the algorithms
we mention, it can be shown that on average for every roughly log log n operations, one
operation is “free” in the above sense, yielding the overall competitive ratio. The algorithms
work in the lenient model, and they heavily rely on annotations, as well as on re-arrangements
outside the search path. The competitive ratio of O(log log n) seems to be inherent to theapproach used in this class of algorithms, therefore it is not clear whether this line of study
will lead to further improvements. It is an interesting question whether the techniques usedby these algorithms can be simulated in the strict model, although this seems rather difficult
as well.
Tango was introduced by Demaine, Harmon, Iacono, and Pǎtraşcu [32] in 2004. It is
compatible with the lenient online model, as it stores O(log log n) bits of annotation per
node, no persistent state between accesses (except for the annotations), and uses a modest
amount of computation. (In fact, we defined the lenient model partly with Tango in mind.) It
maintains a preferred path decomposition of a balanced reference tree, and each preferredpath is maintained internally as a red-black tree. Besides the balance-bits required by the redblack trees, further bookkeeping information of at most O(log log n) bits per node is stored.
When the preferred path decomposition changes, split and merge operations are employed.
Since every path in the preferred path decomposition is of length O(log n), once we reachthe path in which the searched element resides, we need to spend only O(log log n) time tolocate it. (Since each path is internally stored as a balanced BST.) The cost of locating thecorrect path is charged to Wilber’s lower bound, as mentioned above. (This works, because
switching from one path to another when searching for a given element corresponds exactly
to a crossing in Wilber’s first bound.)Both Chain-splay, introduced by Georgakopoulos [47] in 2005, and Multi-splay, introduced independently by Wang, Derryberry, and Sleator [105] in 2006 are based on the sameidea as Tango, except that they use Splay trees at multiple levels, instead of the red-black treecomponents. As such, they are conceptually more uniform, and (particularly Multi-Splay)
fulfill properties that Tango does not. (For instance, in its original form, Tango does not satisfy
the balance condition, whereas Multi-splay does.) The factor of Θ(log log n) is “hard-coded”
into Tango – for the other two algorithms a better competitive ratio can be conjectured(perhaps with a similar or lower confidence as for Splay itself). Nonetheless, the provencompetitive ratio of both Chain-splay and Multi-splay is O(log log n), similarly to Tango.

2.7. The geometric view41

2.7 The geometric view
In this section we describe briefly the geometric BST model of Demaine et al. [31, 52]. As
the model concerns only the relative positions of points and not their distances, the term
“geometric” should be understood only as “visual”. All arguments in this geometric view canreadily be translated back to the original, geometry-free setting.
Again, consider an access sequence X = (x 1 , . . . , x m ) ∈ [n]m . We view X at the same time as©
ªa collection of points in the plane in a straightforward way: X = (x i , i ) : 1 ≤ i ≤ m ⊂ [n]×[m].
(By [n] × [m] we denote the integer grid with n columns and m rows.) We refer to the xcoordinate and the y-coordinate of a point as its key value and its time, respectively.
We call a point set Y ⊆ [n] × [m] satisfied (the term used by Demaine et al. is arborally
satisfied), if for every pair of points a, b ∈ Y , one of the following holds: (i) a and b are on thesame horizontal or vertical line, or (ii) the unique axis-parallel rectangle with corners a and b
contains some point in Y \ {a, b}, possibly on the boundary of the rectangle. We call a paira, b of points that violate both conditions (i) and (ii) an unsatisfied pair.
The minimum satisfied superset problem asks, given a point set X , to find a satisfied
superset Y ⊇ X of smallest cardinality. It is easy to see that if X ⊆ [n] × [m], then a minimum
satisfied superset of X can also be assumed to contain points only from [n]×[m], therefore, inthe following we assume all satisfied supersets to be of this kind (i.e. not to contain fractional,or out-of-bounds points). Let us call this first variant of the problem offline for reasons thatwill become clear soon.
Minimum satisfied superset problem
1. Read point set X ⊂ [n] × [m].
2. Output satisfied point set Y ⊇ X , such that Y ⊆ [n] × [m].

(Offline version)

Next, we define the execution trace (or simply execution) of a BST algorithm. Let A be an
offline BST algorithm in the second model. Let Q 1 , . . . ,Q m be the sequence of BSTs produced
by A while serving X . Recall that Q 1 , . . . ,Q m contain the nodes that are “touched” whenP
accessing x 1 , . . . , x m , and the cost of A on X is costA (X ) = i |Q i |.
ª©
The execution trace of A when serving X is defined as the point set (x, i ) : x ∈ Q i ⊆[n] × [m]. In words, the execution trace of A contains a point (x, i ), exactly if A “touches” x attime i (when accessing x i ). The following theorem captures the offline equivalence between
the satisfied superset problem and the BST problem.
Theorem 2.24 ([31]). A point set Y is an execution trace of some offline BST algorithm (withsome initial tree T0 ) serving X exactly if Y is a satisfied superset of X .
Theorem 2.24 implies that the cardinality of a satisfied superset of X equals the costof some offline algorithm serving X , it is therefore an upper bound on OPT(X ). Thus, thegeometric view can be used for designing offline algorithms for the BST problem: given
an access sequence X , it is sufficient to solve the (perhaps) cleaner geometric problem offinding a satisfied superset of X of small cardinality. We illustrate the geometric view of BST
in Figure 2.8.
For the proof of Theorem 2.24 we refer to [31]. The fact that the execution trace of a
BST algorithm is a satisfied superset of the input is easy to show. For the other direction, to“simulate” a satisfied superset Y by an offline algorithm in the second model, one needs toconstruct the trees T0 and Q i , for all i , in such a way that an access at a future time j will nothave to “touch” any nodes other than those indicated by Y . This can be achieved by using
treaps with priorities given by “future touch times”, similarly to the algorithm GreedyFuture

42

Chapter 2. The binary search tree model

Figure 2.8: Geometric view of BST.
(left) Access sequence X =(6, 5, 2, 3, 7, 1, 4), with key values on x axis, and time on the y axis bottomto-top, (middle) A superset of X that is not satisfied (newly added points
are shown as squares, and some unsatisfied pairs are highlighted), (right) A
satisfied superset of X corresponding to a BST algorithm serving X .

(§ 2.5.3). The proof of Theorem 2.24 is constructive: given a satisfied superset of X , we“recover” an offline BST execution, whose “touched” nodes are exactly those given by Y .
It may seem that this dependence on the future is essential in the correspondence between the tree-view and geometric view of BST. Surprisingly, Demaine et al. show that thecorrespondence between the tree-view and geometric view can also be maintained in an
online fashion, i.e. without knowledge of the future. The following definition and theorems
capture this result.
Recall that the satisfied superset problem asks to find a satisfied superset of a given set ofpoints X ⊂ [n] × [m]. Consider now the following problem, in which the input and output areprocessed line-by-line, with no possibility of going back.
Minimum satisfied superset problem
For each i = 1, . . . , m:
1. Read point (x i , i ) ∈ [n] × [m].
2. Output set of points Yi with y-coordinates equal to i , such that©
ª
Y = Y1 ∪ · · · ∪ Ym is a satisfied superset of X = (x i , i ) : 1 ≤ i ≤ m .

(Online version)

The cost of the solution for the online satisfied superset problem is, as in the offline case,the cardinality of the full output Y .
Theorem 2.25 ([31]). Let A be an online BST algorithm (in any model) with arbitrary initialtree, and let Y be the execution trace of A when accessing X . Let Yi be the set of points
in Y with y-coordinate equal to i . Then, Y1 , . . . , Ym is a valid output for the online satisfied
superset problem with input X .
Theorem 2.25 follows immediately from Theorem 2.24, since the restriction for A to be
an online algorithm only makes the statement more specific. For any online algorithm (inany model) there is a corresponding offline algorithm, which “happens to do the same thing”,
and the execution trace of this algorithm revealed line-by-line is a valid solution to the online
satisfied superset problem. The following result, however, is far from obvious.
Theorem 2.26 ([31]). Let A be an algorithm for the online satisfied superset problem, whose
total cost for input X is costA (X ). Then, there is an online BST algorithm with some initial¡¢tree T0 (independent of X ), whose cost for input X is O costA (X ) .
The proof of Theorem 2.26 from [31] relies on the non-trivial split-tree data structure.
It essentially simulates the future-dependent treap construction of Theorem 2.24 in a lazy

2.7. The geometric view

43

(non-future-dependent) way. We can interpret Theorem 2.26 as saying that to solve theonline BST problem, it is sufficient to design a (geometric) algorithm for the online satisfied
superset problem, and to simulate it by an online BST algorithm. Two caveats of this result
are the constant factor slowdown, and the fact that the resulting online algorithm requires
annotations, and may access elements outside the search path (due to the technical details of
the split-tree). It conforms therefore not to the strict, but at best to the lenient online model.
We say “at best” because we have not made any assumptions on the computational model inwhich the online satisfied superset algorithm lives. In case this algorithm relies on “exotic”
operations of any kind, the tree-view algorithm simulating it will also need to execute similarkinds of operations. This issue, however, is not encountered in any of the algorithms we
discuss.

2.7.1 Algorithms in geometric view
From the previous discussion we conclude that it is worthwile to try designing algorithms forthe geometric satisfied superset problem, whether in the online or in the offline variant (i.e.
whether we require the input to be revealed, and the solution to be constructed, line-by-line
or not).
Let us look first at existing BST algorithms from tree-view, and see what they do ingeometric view. Figure 2.9 shows the execution traces of various algorithms on the same
access sequence. The reader can easily verify that the resulting point sets are satisfied (nounsatisfied pairs).

Figure 2.9: BST algorithms in geometric view. Execution traces for accesssequence X = (6, 5, 2, 3, 7, 1, 4). Accesses shown as dots, touched nodes shownas squares. (i) Static balanced BST, (ii) Rotate-once with right-leaning pathinitial tree, (iii) Move-to-root with right-leaning path initial tree, (iv) Splaywith right-leaning path initial tree, (v) GreedyFuture with right-leaning pathinitial tree, (vi) GreedyFuture with canonical initial tree.

Figure 2.9(i) shows the execution of the access sequence X = (6, 5, 2, 3, 7, 1, 4) in a staticbalanced BST having node 4 at the root, nodes 2 and 6 as the children of the root, and nodes
1, 3, 5, 7 as leaves. The interpretation of the execution trace is straightforward. Since the root
node 4 is on the search path of every accessed key, it is touched every time (in every row).

44

Chapter 2. The binary search tree model

Node 2, the left child of the root is touched whenever an element smaller than 4 is accessed,
namely in the cases x 3 = 2, x 4 = 3, and x 6 = 1. The fact that the execution trace of a static
BST is a satisfied point set follows from Theorem 2.24. It is, however, instructive to prove thisthrough a direct (easy) argument for static trees.
We briefly discuss the geometric view of Move-to-root, illustrated in Figure 2.9(iii). Consider two points (x i , i ), (x j , j ) ∈ X , assuming i > j and x i > x j . Suppose there is no otheraccess point “in between”, i.e. there is no (x k , k) ∈ X with j < k < i , and x j ≤ x k ≤ x i . Then,
we claim that at time i , node x j is on the search path of x i , it is therefore touched by Moveto-root. This is because, at time j , node x j becomes the root (and as such, the ancestor ofx i ). It is easy to see that in Move-to-root, only the accessed node can gain new descendants.
Since no other node between x j and x i is accessed between time j and i , it is impossible forsome node other than x j to become lca(x i , x j ), therefore x j is still the ancestor of x i at timei . In geometric view, this means that if two input points (x i , i ), (x j , j ) ∈ X , with i > j , form arectangle containing no other points of X , then the output Y will contain the point (x j , i ).
The previous observation resembles the earlier definition of unsatisfied pairs, except that
here we refer only to points of X , whereas an unsatisfied pair may consist of arbitrary points
in Y ⊇ X . This difference hints at why Move-to-root may be inefficient. The pair (x i , i ), (x j , j )may already be satisfied at time i by some point in Y \ X . In this case, it may be redundant to
add point (x j , i ) to the solution, but Move-to-root adds it anyway.
It can be shown that points of the above kind (i.e. corners of rectangles defined by input
points) are essentially the only points in the output of the geometric Move-to-root, apartfrom the input points themselves, and apart from some points added due to the initial tree.
Again, the fact that the execution trace of Move-to-root is a satisfied point set follows from
Theorem 2.24, but it can also be shown through a simpler direct argument. Based on theabove equivalence between the tree-view and geometric view of Move-to-root, it can beverified easily why the two earlier definitions of Wilber’s second lower bound are equivalent(see § 2.6.2 and Figure 2.7). We omit the details.
Let us now formulate a necessary and sufficient requirement for algorithms solving the online satisfied superset problem. Consider the execution of an algorithm A at time i . At thistime, the point sets Y1 , . . . , Yi −1 have already been output (andcannot be changed), input point (x i , i ) has been read, and thealgorithm is about to construct the output point set Yi , i.e. thei th line of the overall output Y . Observe that if A is a correctalgorithm, then the set Y1 ∪ · · · ∪ Yi −1 must be satisfied. Suppose otherwise, that Y1 ∪ · · · ∪ Yi −1 contains an unsatisfied paira, b. Since all future outputs Yi , . . . , Ym are disjoint from therectangle formed by a and b, the overall output Y will remain
Figure 2.10: Stair in geometric view.
unsatisfied, contradicting the correctness of A.
Horizontal line shows current time i .
Let us define the stair of x i at time i , denoted stairi (x i ) or Points below line form a satisfied set.
simply stair(x i ) as the set of x-coordinates of points in Y1 ∪· · ·∪ Rectangles indicate unsatisfied pairs
Yi −1 that form unsatisfied pairs with (x i , i ) (with respect to the with the current access point x i , and hollow squares indicate stair(x i ).
already constructed set of points Y1 ∪ · · · ∪ Yi −1 ). The following
lemma claims that at every time, the points corresponding to
the stair of the current access point have to be added, at a minimum, to the solution. This
statement resembles (not accidentally) the observation that the search path to the accessed
element x i has to be touched by every BST algorithm. We illustrate the concept of “stair” inFigure 2.10.

2.7. The geometric view

45

Lemma 2.27 ([31]). Let A be an algorithm for online satisfied superset. Then, the output
Yi of A at time i must contain all points (y, i ), where y ∈ stairi (x i ). Furthermore, the set
containing only these points in addition to the access point (x i , i ) is a valid output.
Proof. Suppose that Y1 ∪ · · · ∪ Yi is satisfied and for some y ∈ stairi (x i ), we have (y, i ) ∉ Yi . By©
ªthe definition of the stair, in Y1 ∪ · · · ∪ Yi −1 ∪ (x i , i ) there is an unsatisfied pair (x i , i ), (y, j )for some j < i . Since this pair is satisfied in Y1 ∪ · · · ∪ Yi , there must be a point (q, i ) ∈ Yi suchthat (q, i ) is in the rectangle formed by (x i , i ) and (y, j ). Assume w.l.o.g. that y < x i and that(q, i ) is the leftmost such point. By our assumption, q > y must hold, but then the pair (q, i ),(y, j ) is unsatisfied, a contradiction. Therefore, all points (y, i ), where y ∈ stairi (x i ) must be
contained in Yi .
©
ª ©
ªFor the second part, we need to show that Yi = (x i , i ) ∪ (y, i ) : y ∈ stairi (x i ) is a valid
output. Suppose for contradiction that Y1 ∪ · · · ∪ Yi contains an unsatisfied pair (y, i ), (q, j ),for some j < i . (We assume that i is the first time this happens.) Assume w.l.o.g. that q < y.
Observe that (y, i ) cannot be the same as (x i , i ), for in that case (q, i ) would have been added
to the solution, making the pair (y, i ), (q, j ) satisfied. There are three cases to consider: (1)If x i < q, then, by the fact that (y, i ) was added to the solution, there must exist some point(y, k) ∈ Y1 ∪ · · · ∪ Yi −1 , such that j < k < i , contradicting that the pair (q, j ), (y, i ) is unsatisfied.
(2) If q ≤ x i < y, then (x i , i ) itself is in the rectangle formed by (q, j ) and (y, i ), making the pairsatisfied. (3) Finally, if x i > y, then, again, there must exist some point (y, k) ∈ Y1 ∪ · · · ∪ Yi −1 ,such that k < i . If k ≥ j , then (q, j ), (y, i ) is satisfied, if k < j , then (q, j ) and (x i , i ) must haveformed an unsatisfied pair, therefore (q, i ) ∈ Yi , a contradiction.
Lemma 2.27 gives a minimum necessary set of points that every valid online satisfied
superset algorithm must output at a given time. This minimum set of points is also sufficient.
It is natural to propose the algorithm whose output is (at every time) just this minimum,and nothing else. Let us call the resulting algorithm GeometricGreedy, defined as follows.
(Demaine et al. [31] introduced this algorithm with the name GreedyASS.)
GeometricGreedy
For each i = 1, . . . , m:
1. Read point (x i , i ) ∈ [n] × [m].
©
ª ©
ª2. Output Yi = (x i , i ) ∪ (y, i ) : y ∈ stairi (x i ) .
GeometricGreedy appears to be a very reasonable geometric sweepline algorithm for theminimum satisfied superset problem: processing the input one row at a time, it adds the minimum number of points necessary to make the point set on one side of the sweepline satisfied.
Observe that GeometricGreedy solves the online satisfied superset problem. Remarkably,
this algorithm turns out to be an old friend in disguise.
Theorem 2.28 ([31]). For every X , the output of GeometricGreedy for X is the execution
trace of GreedyFuture for X with the canonical initial tree.
Proof. We refer to § 2.5.3 for the description of GreedyFuture. We run simultaneously GreedyFuture in tree-view (starting from the canonical tree) and GeometricGreedy in geometricview on the same input X . Suppose by induction that until time i (before accessing x i ) the
execution trace of GreedyFuture equals the output of GeometricGreedy. Since at time iGreedyFuture only touches the search path of x i , and GeometricGreedy only adds the points
with x-coordinate in stairi (x i ) ∪ {x i }, we only need to show that these two sets are equal.
Let y ∈ [n] be an arbitrary key. Suppose that y ∈ stairi (x i ), and let j be the last touched
time of y. More precisely, j is the largest integer such that j < i and (y, j ) ∈ Y j . (If no such

46

Chapter 2. The binary search tree model

integer exists, then y could not be in stairi (x i ).) Assume w.l.o.g. that y < x i . Observe that after
accessing x j at time j in the execution of GreedyFuture, node y becomes the ancestor of x i .
To see this, observe that it cannot be the case that y < lca(y, x i ) ≤ x i , since no element fromthis interval is in the search path of x j (in Q j ), since the rectangle between (y, j ) and (x i , i )is empty in the GeometricGreedy execution. Therefore, at time j , it holds that y = lca(y, x i ).
Since no key in the interval [y, x i ] is on any of the search paths for x j +1 , . . . , x i −1 , node yremains an ancestor of y, it is therefore on the search path of x i at time i .
For the converse, suppose that y ∉ stairi (x i ) ∪ {x i }. We need to argue that at time i , node
y is not an ancestor of x i in the GreedyFuture execution. Again, assume w.l.o.g. that y < x i ,and let j be the maximum integer such that j < i and y ∈ Y j .
Suppose first that no such integer j exists, i.e. y was never touched. Then, in the treap
construction of the canonical initial tree the priority of x i is smaller than the priority of y(since x i is accessed earlier than y). In the canonical tree, y cannot thus be the ancestor of x i .
Since y is not touched before time i , i.e. it is not on any of the search paths in GreedyFuture,
it cannot gain new descendants, therefore, it is not an ancestor of x i at time i . We assume
therefore that the last touched time j of y exists (0 < j < i ).
Since y ∉ stairi (x i )∪{x i }, there is some point (q, k) ∈ Yk , such that j ≤ k < i and y < q ≤ x i .
Let (q, k) be such a point with maximum value of k, and among those with the same valueof k, the one with maximum value of q. Observe that q ∈ stairi (x i ) ∪ {x i }, and by a similarargument as before, after the access at time k we have that q is an ancestor of x i (possibly q
equals x i ).
Suppose for contradiction that y is an ancestor of x i at time i . Since y is not touched (i.e.
not on a search path) when accessing x k+1 , . . . , x i −1 , it must hold that y is an ancestor of x i
already after the access at time k. Since, at this time q is the ancestor of x i , by the ordering
condition it must hold that y is the ancestor of q. Thus, y is touched at time k, therefore
k = j . Recall the treap construction in GreedyFuture at time k. Since x i is in the subtree of q,
the priority of q is at most i . For y to become the ancestor of q, it must have a priority lessthan i , in other words, there must exist some x t in the left subtree of y, such that j < t < i .
Let x t be such an element with minimum t . Then, when x t is accessed, y is on its searchpath, therefore (y, t ) ∈ Y t must hold. This contradicts our choice of j as the last touched timeof y.
The remarkable aspect of Theorem 2.28 is that GeometricGreedy, an (online) algorithm
for satisfied superset turns out to be the geometric counterpart of the (offline) BST algorithm
GreedyFuture (§ 2.5.3). By Theorem 2.26, we obtain an online BST algorithm that simulates
GreedyFuture with a constant factor overhead. Let us call the resulting online BST algorithm
OnlineGreedy. When there is no chance for confusion, we will refer to both GeometricGreedy
and OnlineGreedy simply as Greedy. We refer to Figure 2.9(vi) for an example run of GeometricGreedy (or equivalently, the execution trace of GreedyFuture with canonical initialtree).
It is natural to ask what the execution trace of GreedyFuture looks like, if we have an
initial tree other than the canonical one. The equivalence between stairs and search paths
from the proof of Theorem 2.28 suggests a method of inserting an arbitrary initial tree ingeometric view.
For an arbitrary BST T over [n], consider the point set P T = P 1 ∪ · · · ∪ P n , where P i =
©¡
¢¡
¢
¡
¢ª
i , − depthT (i ) , i , − depthT (i ) − 1 , . . . , i , −n + 1 . In words, P T consists of columns ofpoints stacked for every key in [n], equal in height to n minus the depth of the key in T . Thesecolumns are placed under X , i.e. with y-coordinates at most 0.
For an arbitrary access sequence X ∈ [n]m (and corresponding point set), and an arbitrary
BST T over [n], we define the point set X T = P T ∪X . We then run GeometricGreedy on X T

2.7. The geometric view47

(with y-coordinates of the input and output now running from −n +1 to m). Observe that therows of X T corresponding to the initial tree T are already satisfied, therefore GeometricGreedy
does not add any new points in these rows. When we refer to the output of GeometricGreedy
for X with initial tree T , we mean the output of GeometricGreedy on X T , excluding thepoints in P T from the output. The following theorem captures the correspondence between
GreedyFuture and GeometricGreedy with initial trees.
Theorem 2.29 ([31]). For every sequence X ∈ [n]m and BST T over [n], the output of GeometricGreedy for X with initial tree T is the execution trace of GreedyFuture with the initialtree T .
The proof of this result requires only a small modification of the proof of Theorem 2.28.
Namely, we observe that before the first access x i , the equivalence between stairs and searchpaths already holds. That is, for every element y ∈ [n], we have that the search path of y in
T consists exactly of the keys in stair1 (y). Note that the unsatisfied rectangles that define
stair1 (y) contain one corner from the initial tree. The usage of initial trees in geometricview is illustrated in Figure 2.11, and the execution trace of GreedyFuture with initial tree isillustrated in Figure 2.9(v).

1

2

3

4

5

6

7

8

9 10 11

1

2

3

4

5

6

7

8

9 10 11

Figure 2.11: Tree-view and geometric view of initial tree. Search path andstair (at time 1) of key 5.

In summary, GeometricGreedy can exactly capture the execution trace of GreedyFuturewith arbitrary initial tree. Most often we look at GeometricGreedy with “no initial tree”, whichcorresponds to GreedyFuture with canonical initial tree. In the online BST simulation ofGeometricGreedy, the “no initial tree” state corresponds to the initial split-tree data structure.
The important difference between the two is that the canonical initial tree of GreedyFuture
depends on the future, whereas the split-tree initial tree of OnlineGreedy does not. Thus,
the statements we prove about GeometricGreedy “with no initial tree” can be translated tostatements about OnlineGreedy started from a particular fixed initial tree. Statements weprove about GeometricGreedy started “from initial tree T ” can be translated to statements
about OnlineGreedy started from initial tree T . One can also view the “no initial tree” state ofGeometricGreedy as a “preprocessing”. Namely, we can think of the OnlineGreedy algorithm
as if it starts by rotating its initial tree (whatever it may be) to the split-tree data structure(in linear time). It is worth mentioning that Demaine et al. [31] define GreedyFuture andGeometricGreedy without initial tree, and thus their algorithm (implicitly) performs thispreprocessing.
We have little to say about the geometric views of Rotate-once (Figure 2.9(ii)), Splay(Figure 2.9(iv)), and other natural BST algorithms. The geometric view discussed in thissection seems to give limited intuition about these algorithms. We have seen that every
online satisfied superset algorithm must, at every time, touch at least the stair of the current
access point. This is also true for the geometric view of Splay (and other BST algorithms). Also,
the choice of initial tree can be enforced in geometric view for Splay and other algorithms
similarly as for GreedyFuture.

48

Chapter 2. The binary search tree model

Algorithms other than Greedy, however, also touch other points besides the (local) minimum given by the stair, even if they have the search-path-only property in tree-view, as Splay
does. This may seem contradictory, since we said that the stair in geometric view corresponds
to the search path in tree view. This is however, only true for Greedy. For Splay, and for otheralgorithms, the exact re-arrangement of the search path is not explicitly represented (orrather, it is not represented where it happens, but it is spread around in different rows in
the future). The reason why Splay in geometric view touches more points at time i than theminimum necessary, is that it re-arranged the search paths at earlier times in particular ways.
Touching more points than necessary at any given time may turn out to be helpful in the
future. It remains an interesting question to decide locally which extra points may be worth
touching, a question equivalent to designing a good online BST algorithm.
One can attempt to encode in the geometric view the exact re-arrangement of the search
path in the exact line where it happens. Doing this would re-establish the link between searchpaths and stairs for every algorithm, at the cost of the simplicity of the geometric model [25,§ C]. It could well be that for analyzing Splay and other algorithms, some entirely different
geometric or combinatorial representation will prove to be useful (see e.g. the techniques
used by Pettie [80, 82]).
We close this subsection with the following whimsical question. OnlineGreedy is a treeview algorithm with cost proportional to the cost of GreedyFuture. What does the execution
trace of OnlineGreedy look like in geometric view? We know that due to the split-tree data
structure, OnlineGreedy may touch elements outside the search path, and thus, its geometricview will add points other than the stair to the solution (it is therefore different from GeometricGreedy). However, since OnlineGreedy is online, its geometric view is an algorithm forthe online satisfied superset problem. Call this algorithm GeometricOnlineGreedy. We neednot stop after one step, and can look at the tree-view simulation of GeometricOnlineGreedy(perhaps called OnlineGeometricOnlineGreedy) and so on, ad infinitum. Does this process
have a non-trivial fixed point?

2.7.2 A closer look at GeometricGreedy
Based on the results of the previous subsection, it is tempting to “forget about trees” andanalyze GeometricGreedy directly. We have seen that GeometricGreedy is a natural sweepline
algorithm for solving the online satisfied superset problem. In fact, as it does the minimum
work necessary at every time, one might at first think that it is optimal. The minimal example
in Figure 2.12 shows that this is not the case. Informally, GeometricGreedy is not optimal,
because, as the example shows, it may be worth to do more work locally than what is strictly
necessary, as this may reduce the amount of work we need to do in the future.
We have already seen in § 2.5.3 that the performance of GreedyFuture (and by extension OnlineGreedy) is very good, matching
several upper bounds. This makes OnlineGreedy, due to its simplicity in geometric view, perhaps the most promising contender for
dynamic optimality (even if, in tree-view, OnlineGreedy is far from
simple). In § 4 we analyze the behaviour of OnlineGreedy (in fact,
GeometricGreedy) on a variety of input sequences, and in § 5 we Figure 2.12: Smallest example
where GeometricGreedy is not opgive additional interpretations of GeometricGreedy.
timal. X = (1, 3, 2). (left) GeometIt appears quite plausible that GeometricGredy computes a ricGreedy output. (right) A smallest
constant approximation of the optimum (this must be the case,satisfied superset.
if GreedyFuture is constant-competitive, as conjectured, see e.g.
Problem 20). In the following, let OPT(X ) denote the optimum satisfied superset solution

2.7. The geometric view

49

size for X , and let costGG (X ) denote the cost of GeometricGreedy for X . Due to Theorem 2.24
and Theorem 2.28, these quantities exactly match the offline BST optimum, respectively thecost of GreedyFuture for X , according to the second offline BST model.
The worst known example [31] for the approximation ratio of GeometricGreedy is aconstruction where the ratio is arbitrarily close to 43 , see Figure 2.13. The following conjectureis therefore natural, although much stronger than the conjectured dynamic optimality of
GreedyFuture.
Problem 28. Is costGG (X ) ≤ 43 · OPT(X ) for every X ?
In fact, an even stronger conjecture is suggested by Demaine
et al. [31], and earlier by Munro [76], who speculate that the cost of
GreedyFuture matches OPT(X ) with an additive error of at mostO(m), or even just m. This conjecture is sensitive to constant factor
modifications of the cost, therefore we need to be careful in specifying exactly which cost model we use. As far as we understand,it was formulated in what we call the second offline model, therefore, if true, it would also hold for GeometricGreedy. The example
in Figure 2.14 shows that such a strong form of the conjecture isfalse. The figure presents an input sequence X ∈ S 30 , i.e. a permutation of length m = 30, such that costGG (X ) ≥ OPT(X ) + m + 1.
The exact sequence shown in the figure is X = (18, 9, 17, 16, 25, 19, 4,
10, 26, 24, 8, 13, 5, 28, 23, 20, 7, 12, 1, 29, 27, 3, 22, 11, 14, 2, 30, 21, 6, 15).
Figure 2.13: Example where theObserve that the example does not settle Problem 28, since theapproximation ratio of Geomet44
ricGreedy is 3 . X = (2, 3, 1, 3, 1, . . . ). approximation ratio is not known to be more than 3 in this example.
(left) GeometricGreedy output. The example in Figure 2.14 was obtained with computer search. It(right) Smallest satisfied superset. is not immediately clear how to extend it into an infinite family of
examples, although visually it does seem to have a certain structure.
It seems plausible that there are permutations of arbitrary size with a compact description,
on which the error of GeometricGreedy is larger than m (computer experiments suggest thatsuch examples are easier to come by as m grows, until the computation itself becomes too
costly). Constructing structured examples (whether permutations or not) on which Greedy
performs suboptimally remains an interesting direction. Whether such constructions will
give new insight on the behavior of Greedy remains to be seen.
A last remark on the example in Figure 2.14 is that the cost of GeometricGreedy is compared here not with the exact optimum, but with the cost of GeometricGreedy ran sideways(which is an upper bound on OPT). It is easy to see that running GeometricGreedy (or any
valid satisfied superset algorithm) on reversed, mirrored, or 90-degrees rotated variants of
the input still produces a valid solution. The fact that time and (key-)space in the BST model
can be interchanged is one of the more surprising and non-trivial insights of the geometricview. The exact relation between the costs for these variants is, however, poorly understood.
Problem 29. Is the cost of GeometricGreedy asymptotically the same on X and X rot , where
X rot is X rotated by 90 degrees?
Based on the above discussion, the possibility that the following conjecture holds is not
ruled out (again, this is a statement stronger than the dynamic optimality of GreedyFuture).
Problem 30. Is costGG (X ) ≤ OPT(X ) + O(m) for every X ∈ [n]m ?
Regardless of GeometricGreedy, one may try to attack the geometric satisfied superset
problem directly, using various tools from the field of geometric approximations. One possible direction would be to formulate the problem as a linear program. Surprisingly little has

50

Chapter 2. The binary search tree model

Figure 2.14: Counterexample to additive error conjecture for Greedy. Permutation sequence X of length 30. (left) GeometricGreedy output with
costGG (X ) = 140. (right) a different solution showing OPT(X ) ≤ 109.

come so far from such attempts. One aspect of the satisfied superset problem that makes
it unusual is its non-monotonicity: adding more points to a satisfied point set may render
it unsatisfied. The hardness of the problem is also poorly understood (see Problem 3). Demaine et al. [31] prove the NP-hardness of the problem in the general case where the input
may contain multiple points in the same column, as well as in the same row. The following
intriguing question is thus open.
Problem 31. Is minimum satisfied superset NP-hard for point sets with one point in everyrow?

2.7.3 Lower bounds in geometric view
A rectangle formed by two points x and y (not on the same vertical or horizontal line) is theunique axis-parallel rectangle whose two corners are x and y. If one of x and y is to theright and above of the other, we say that the rectangle formed by x and y is a -rectangle.
Otherwise, we call it a -rectangle.
Let I X denote the set of rectangles formed by unsatisfied pairs of points in X . A setof rectangles R ⊆ I X is called -independent, if all rectangles in R are -rectangles, andfor any two rectangles R 1 , R 2 ∈ R, no corner of R 1 is fully inside R 2 (a corner of R 1 on theboundary of R 2 is allowed, see Figure 2.15). We define the condition for a set of rectangles
R ⊆ I X to be -independent analogously.
Let X ∈ [n]m be an access sequence (and corresponding point set). The maximum
independent rectangle (MIR) bound is defined as follows: MIR(X ) = m + | R | + | R |, whereR , R ⊆ I X are the largest -independent, respectively -independent sets of rectangles
in I X . The following result was shown by Demaine et al. [31, 52]. A similar lower bound was
also described by Derryberry et al. [34].
¡¢
Theorem 2.30 ([31]). OPT(X ) = Ω MIR(X ) .
Theorem 2.30 provides yet another lower bound for OPT. In fact, MIR can be thought ofas a family of bounds, since all (possibly non-maximal) sets of independent rectangles give alower bound.

2.7. The geometric view

51

Figure 2.15: (left) Pairs of independent -rectangles. (right) Pairs of nonindependent -rectangles.

In [31] it is shown that the MIR bound subsumes Wilber’s two bounds (i.e. MIR(X ) is
asymptotically at most as large as W 1 (X ) or W 2 (X ) for all X ). This can be seen by constructing particular sets of independent rectangles that exactly capture Wilber’s bounds. Thus,
Theorem 2.30 implies Theorems 2.22 and 2.23, which is fortunate, since the original proofs ofWilber for these results are quite complicated compared to the proof of Theorem 2.30 [31].
Surprisingly, there is a simple algorithm for computing a constant-approximation of
the quantity MIR(X ), found by Demaine et al. [31]. Moreover, this algorithm shows a deep
similarity to GeometricGreedy. We describe in the following the two algorithms Greedy andGreedy , which are similar to Greedy, differing only in the fact that they consider unsatisfied
rectangles of the -, respectively -type only. We are interested in the union of their outputs.
For that purpose, let us define stair and stair at time i , similarly to the normal stairdefined earlier. Thus, let
©

ª

©

ª

stair
(x i ) = stairi (x i ) ∩ 1, . . . , x i − 1 ,iand similarly:

stair
(x i ) = stairi (x i ) ∩ x i + 1, . . . , n .
iGreedyFor each i = 1, . . . , m:
1. Read point (x i , i ) ∈ [n] × [m].
©
ª ©
ª2. Output Yi = (x i , i ) ∪ (y, i ) : y ∈ stair(x i ) .
i

GreedyFor each i = 1, . . . , m:
1. Read point (x i , i ) ∈ [n] × [m].
©
ª ©
ª2. Output Yi = (x i , i ) ∪ (y, i ) : y ∈ stair(x i ) .
i
The outputs of Greedy and Greedy are not, in general, valid solutions for the satisfied
superset problem with input X (and neither is their union). More precisely, the output of
Greedy (Greedy ) contains no unsatisfied -type (-type) pairs of points, therefore theunion of the Greedy and Greedy solutions contains no unsatisfied pairs of input points ofeither type. It may, however, contain unsatisfied pairs involving one or two output points.
Let costG  (X ), and costG  (X ) denote the cost of Greedy , respectively Greedy , i.e. thecardinalities of their outputs. The SignedGreedy bound, denoted SG(X ) is defined simply as

SG(X ) = costG  (X ) + costG  (X ).

52

Chapter 2. The binary search tree model

The following theorem holds.
¡¢
Theorem 2.31 ([31]). For every X ∈ [n]m we have SG(X ) = Θ MIR(X ) .

We revisit these quantities in § 4.7 where we analyze MIR(X ) for various special sequences
X , and in § 5, where we look at other quantities asymptotically equal to MIR(X ), and givedifferent interpretations of this quantity (which also yield alternative proofs for Theorem 2.30).
The following important questions are open.
¡¢¡¢
Problem 32. Prove or disprove that W 1 (X ) = Θ MIR(X ) or W 2 (X ) = Θ MIR(X ) hold for
all X ∈ [n]m .
¡¢Problem 33. Prove or disprove that MIR(X ) = Θ OPT(X ) for all X ∈ [n]m .

53Chapter 3

Splay tree: variations on a theme
There is no excellent beauty that hath not somestrangeness in the proportion.

— F RANCIS B ACON , Of Beauty (1612)

In this chapter we study the Splay algorithm ([91], § 2.5.2) in a broader context, as aparticular member of a class of algorithms. Recall that Splay is a strict online BST algorithm
according to the model defined in § 2.2. Splay is known to be very efficient both in theory andpractice. We would like to understand why Splay is efficient, when similar algorithms such as
Move-to-root and Rotate-once can be very inefficient, even on some of the simplest inputs.
By efficiency of an algorithm we mean that its cost is below the various upper bounds
discussed in § 2.4. At a minimum, we expect a BST algorithm to satisfy the balance condition,i.e. to have cost m ·O(log n), when serving an access sequence X ∈ [n]m , since this can alreadybe achieved by a static balanced BST. More strongly, we will be concerned mainly with theupper bounds implied by the access lemma (Definition 2.15, Theorem 2.17).
Since we want logarithmic cost on average (i.e. not necessarily for every access), we do
not require algorithms to maintain a balanced BST at all times. Nevertheless, for most accesssequences, we expect efficient algorithms to maintain a reasonably balanced tree most of thetime (as otherwise an adversary could always be asking for keys with large depth).
As a first attempt, let us look at the trees maintained by the various algorithms in someconcrete (small) examples. For a BST algorithm A and some fixed n, consider the graph
G A whose vertices correspond to the C n different BSTs over [n]. Accessing a certain key
by algorithm A transforms the underlying BST. We represent such a transformation as adirected edge in G A from the BST before the access to the BST after the access. We call G A
the transition graph of A. We illustrate in Figure 3.1 the transition graphs of three algorithms
for very small values of n (3 and 4).
Surprisingly, in the n = 3 case, the transition graph of Splay is not strongly connected, i.e.
there exist pairs of trees T1 , T2 , such that having T1 as initial tree, T2 is unreachable. In thecase of Move-to-root and Rotate-once, it can be shown easily that from an arbitrary initialtree, every possible tree is reachable through some sequence of accesses, for arbitrary sizen. Even for Splay, the above observation turns out to be an artefact for the small value of nconsidered, and not a general phenomenon (Robert Tarjan, personal communication).
Second, at least in these tiny examples, intuitively it seems that BSTs with smaller depths(i.e. that are more balanced) are somehow “more central”, i.e. “easier to reach” in the case of
Splay than in the case of Rotate-once. (Such a difference between Splay and Move-to-root isless apparent.) Is it possible to precisely formulate and prove such an intuition?
Recall from § 2.2 that a strict online BST algorithm A is defined by its initial tree T0 and
its transition function (denoted ΓA ). Can we understand the structure of the transition graph

54

Chapter 3. Splay tree: variations on a theme

Figure 3.1: Transition graphs of Rotate-once (left), Move-to-root (middle),
and Splay (right), for BSTs over [3] (above) and over [4] (below). Self-loops andmultiple edges omitted. In the n = 4 case, isomorphic states are collapsed.

G A in terms of properties of ΓA ? More importantly, from structural properties of G A can we
directly infer something about the behavior and efficiency of A?
At this point, such a full understanding of BST algorithms from “first principles” seems
too ambitious. We will instead look at restricted classes of strict online BST algorithms, or
equivalently, at transition functions ΓA with certain properties. We would like to identify
properties of ΓA that guarantee the efficiency of the BST algorithm A, and to understandhow this relates to the efficiency of Splay and other known algorithms.

3.1 Splay revisited: a local view
Recall the definition of a strict online BST algorithm (§ 2.2) accessing a sequence X =(x 1 , . . . , x m ) ∈ [n]m . Such an algorithm is fully described by an initial tree T0 and a transition function Γ that transforms, after every access x i , the search path P i of x i into a tree Q iof the same size. We call the tree Q i resulting from this transformation the after-tree. All
subtrees hanging from the search path P i are re-attached in a unique way to the after-tree Q i .
Transforming P i to Q i changes the tree Ti −1 into Ti .
In this chapter we only consider strict online BST algorithms that have the access-to-root
property. That is, we require Γ to be such that x i is the root of Q i (and consequently, of Ti ).
For most of the discussed results the restriction can be relaxed, although at the expense ofsome technicalities. Observe that both Splay and Move-to-root satisfy the access-to-root
condition, but Rotate-once, in general, does not.
Recall the definition of Splay (§ 2.5.2). The transition function Γ is, in the case of Splay,
defined by a series of local transformations (the ZIG, ZIG-ZAG, and ZIG-ZIG cases) applied tothe search path until the accessed key becomes the root. This suggests a generalization of
Splay, where Γ similarly moves the accessed key to the root, through a possibly different set of3.1. Splay revisited: a local view

55

local transformations. (Move-to-root also fits this general model – in the case of Move-to-root
the local transformations are simple rotations.)
Such a generalization of Splay was studied by Subramanian [99] in 1996, and in a slightly
more general form by Georgakopoulos and McClurkin [48] in 2004. In the remainder of thesection we give a brief account of Subramanian’s result.
Consider the search path P i and the after-tree Q i when accessing x i . For simplicity, we
drop the indices and refer to these objects as P , Q, and x. A decomposition of the transforP0

P1

P k−1

mation Γ : P → Q is a sequence of BSTs (P = Q 0 −→ Q 1 −→ · · · −−−→ Q k = Q), such that for all
i , the tree Q i +1 can be obtained from the tree Q i , by rearranging a path P i contained in Q i
into a tree R i , and linking all the attached subtrees in the unique way given by the ordering
condition. Clearly, every transformation P → Q has such a decomposition, since a sequenceof rotations fulfills the requirement.
We call a strict online BST algorithm A with the access-to-root property local withwindow-size c, if all the transformations P → Q defined by its transition function ΓA have a
decomposition with the following properties:(i) (start) x ∈ P 0 , where x is the accessed element in P ,(ii) (progress) P i +1 \ P i 6= ;, for all i ,(iii) (overlap) P i +1 ∩ P i 6= ;, for all i ,(iv) (no-revisit) (P i − P i +1 ) ∩ P j = ;, for all j > i ,(v) (window-size) |P i | ≤ c, for some constant c > 0.
The following statements are straightforward to verify.
Theorem 3.1. Splay is local with window-size 3. Move-to-root is local with window-size 2.
We define two additional conditions on the decomposition of transformations P → Q.
(vi) (progress) x is the leaf of P i , and the root of R i , for all i ,(vii) (depth-reduction) the transformation P i → R i strictly reduces the depths of bothchildren of x (if they exist), for a constant fraction of the cases i .
Again, it is straightforward to verify that Splay fulfills the conditions (vi) and (vii) byinspecting Figure 2.3. Observe that, it is only true for the ZIG-ZIG and ZIG-ZAG cases that thetwo children of the accessed element x decrease their depth. This condition does not hold in
the ZIG case, but since this case is applied at most once for every access, condition (vii) is
satisfied. On the other hand, Move-to-root does not satisfy condition (vii).
The goal of the above definitions is to generalize Splay to a broader class of algorithms,
replacing the local ZIG, ZIG-ZAG, and ZIG-ZIG cases by more general families of transformations. The above definition of locality (conditions (i)-(v)) is slightly different from thedefinitions of [99, 48], but not in an essential way. We state the result of Subramanian [99] ina slightly weaker form than the original. In particular, [99] does not require the access-toroot property. Recall the access lemma (Definition 2.15) from which several properties of astrict online algorithm with the access-to-root property can be derived (Theorem 2.17). The
following result also implies Theorem 2.16.

56

Chapter 3. Splay tree: variations on a theme

Theorem 3.2 ([99]). Let A be a strict online BST algorithm with the access-to-root property
that is local with window-size c = O(1) (conditions (i)-(v)), and additionally, it satisfies
conditions (vi) and (vii). Then the access lemma holds for A.
Proof. Recall the definition of the potential function Φ from § 2.5.2. Observe that the subtrees
of nodes that are not on the search path P do not change during the re-arrangement, andtherefore their contribution to the potential function Φ remains the same. We only needto account for the contribution of nodes of P . We apply the transformation P → Q stepby-step, according to the decomposition. Let ∆Φi denote the increase in potential during
the application of a single transformation P i → R i . Let subtreei (x) denote the subtree of
node x after the transformation P i → R i has been applied. For convenience, we denote¡¢w subtreei (x) by w s i (x). We have:∆Φi =X ³ ¡ i ¢¡¢´
log w s (v) − log w s i −1 (v)

(3.1)

v∈P i

³ ¡
¢
¡
¢´
≤ c · log w s i (x) − log w s i −1 (x) .

(3.2)

Inequality (3.2) follows from condition (vi), namely, the observations that v ∈ subtreei (x)and x ∈ subtreei −1 (v), for every v ∈ P i . So far, we have not used condition (vii), and indeed,(3.2) is not strong enough to prove the access lemma. Therefore, we “perturb” the potential difference ∆Φi in (3.1) to bring in an additional constant term. A local transformation
P i → R i can be of two types. The tree R i is either a path, or not. We consider the two cases inturn.
Case 1 (R i is a path): Let L and R be the left, respectively right child of x before the transformation P i → R i , and let B be the node in R i of largest depth. If, as required by condition(vii), the depths of L and R decrease, then subtreei (B ) is disjoint from both subtreei −1 (L) andsubtreei −1 (R).
Thus,
w s i (x) ≥ w s i (B ) + w s i −1 (x).
From the fact that (X − Y )2 ≥ 0, it follows that:³´2
w s i (x) ≥ 4 · w s i (B ) · w s i −1 (x).

Taking logarithms, we obtain
¡
¢
¡
¢
¡
¢
2 · log w s i (x) ≥ 2 + log w s i (B ) + log w s i −1 (x) .

(3.3)

Case 2 (R i is not a path): Let r = root(P i ), and let L and R be two sibling nodes in
R (since R i is not a path, two such nodes must exist). By disjointness of subtreei (L) andsubtreei (R), we get
w s i −1 (r ) ≥ w s i (L) + w s i −1 (R).
i

In consequence,
¡
¢
¡
¢
¡
¢
2 · log w s i −1 (r ) ≥ 2 + log w s i (L) + log w s i (R) .

(3.4)

Plugging (3.3) and (3.4) into (3.1), we obtain:
³ ¡
¢
¡
¢´
∆Φi ≤ (c + 1) · log w s i (x) − log w s i −1 (x) − 2.

(3.5)

3.2. Splay revisited: a global view

57

For transformations P i → R i with the depth-reduction property we have (3.5). For theremaining transformations we fall back to (3.2). Let T and T 0 denote the tree before and after
the access by A. Since a constant fraction of the transformations have the depth-reduction
property, by a telescoping sum we obtain:
µ
¶
X
W
|P |
0
i
Φ(T ) − Φ(T ) = ∆Φ ≤ O 1 + log− Ω(1) ·.
w(x)ci
The statement is the same as the access lemma (Definition 2.15). In the last step we used¢¡
the facts that x = root(T ), w subtree(x) ≥ w(x), and that there are at least |Pc | steps in thedecomposition of the transformation. A factor of c + 1 and an additive constant have been
hidden in the O(·) term.
Theorem 3.2 (and the more general formulations in [99, 48]) already give a broad generalization of Splay, and a sufficient condition for the efficiency of a strict online BST algorithm(in the sense of the access lemma). The resulting general class of algorithms is however, still“local”, relying on the decomposition of the transition function Γ into constant-sized transformations. In the next sections we develop a more “global” description of BST algorithms
satisfying the access lemma.

3.2 Splay revisited: a global view
Let P be the search path when accessing x in T . The transition function Γ of Splay transforms
P into a tree Q. We view this transformation globally, illustrated in Figure 3.2.
Let S = (a 0 , a 1 , . . . a |P |−1 ) be the sequence of the keys in P , in their order of appearance on
the search path from x to root(T ), i.e. a 0 = x and a |P |−1 = root(T ).
Consider the following two-step transformation (Figure 3.2). First, make x the root andsplit the search path P into two paths, the path of elements smaller than x, and the pathof elements larger than x. Second, for all i , if the pair of keys a 2i +1 and a 2i +2 are on thesame side of x (i.e. both smaller or both larger), rotate the edge (a 2i +1 , a 2i +2 ). In other words,
remove a 2i +2 from the path and make it a child of a 2i +1 .

Figure 3.2: Global view of Splay. The first transformation illustrates Move-toroot. The first and second transformations together illustrate Splay. Subtrees
hanging from the search path are omitted.

Theorem 3.3. The above two-step transformation describes exactly the transformation of
Splay. The first step alone describes the transformation of Move-to-root.
Proof. We execute a Splay access to x according to the original definition (§ 2.5.2) and maintain the invariant that for the nodes of the search path P that have already been visited, thesubtree of x (in the tree Q being constructed) has exactly the structure given by the new
definition. Observe that once a node is in the subtree of x, it stays there until the end of

58

Chapter 3. Splay tree: variations on a theme

the process. The invariant holds in the beginning when only x is visited, as the subtree of x
contains only x. The inductive step is straightforward to verify: whether a ZIG-ZIG, ZIG-ZAG,
or ZIG step is executed, the invariant is maintained.

3.3 Sufficient conditions for efficiency
In this section we give conditions on the transition function ΓA of a strict online algorithm A
with the access-to-root property that are sufficient to guarantee that the access lemma holds
for A. First we define the combinatorial properties of trees that will be used.
Let P be the search path when accessing x in T by algorithm A. The transition function
ΓA of A transforms P into a tree Q. Again, we view this transformation globally, and refer to
Q as the after-tree. The transformation is illustrated in Figure 3.3.
Let z denote the number of edges on the search path connecting nodes on different sidesof x. We refer to z as the number of zigzags. Define the left-depth, respectively right-depth of
a node v as the number of , respectively  edges on the path from the root to v. We willconsider left- and right-depth mostly in the after-tree. We illustrate these parameters (andothers) in Figure 3.3.

Figure 3.3: Parameters of the search path and the after-tree. The search path
to x is shown on the left, and the after-tree is shown on the right. The search
path consists of 12 nodes and contains four edges that connect nodes on
different sides of x (z = 4). The after-tree has five leaves. The left-depth of a in
the after-tree is three (the path from the root a to x goes left three times) andthe right-depth of y is two. The set {a, c, f , v, y} is subtree-disjoint. The sets{d , e, g }, {b, f }, {t , y}, {w} are monotone. Subtrees hanging from the search
path and from the after-tree are not shown.

The following theorem is the main result of this chapter.
Theorem 3.4. Let A be a strict online BST algorithm with the access-to-root property. If forevery access x:(i) the number of leaves of the after-tree is Ω(|P | − z) where P is the search path of x, and z
is the number of zigzags in P , and(ii) for every key t ∈ P such that t > x (resp. t < x), the right-depth of t (resp. left-depth of t )in the after-tree is O(1), then the access lemma holds for A.
Let T be the tree before accessing x and let T 0 be the tree after the re-arrangement.
(Remember, that the search path P and the after-tree Q are subtrees of T , respectively, T 0 .) In
the following, we write subtreeT (x) for the subtree of x in T , and we write subtreeT 0 (x), forthe subtree of x in T 0 .
The main task in proving Theorem 3.4 is to relate the potential difference ΦT − ΦT 0 to
the length of the search path P . It is convenient to split the potential into parts that we can3.3. Sufficient conditions for efficiency

59

argue about separately. For a subset X ⊆ [n] of the nodes, define a partial potential on X as¡ ¡¢¢P
ΦT (X ) = a∈X log w subtreeT (a) .
Again, observe that the potential change is determined only by the nodes on the searchpath, i.e.
ΦT − ΦT 0 = ΦT (P ) − ΦT 0 (P ).
Further, observe that we can argue about disjoint sets of nodes separately.
S
Lemma 3.5. Let P be the search path to x. Let X = ki=1 X i where the sets X i are pairwise¡¢Pdisjoint. Then ΦT (X ) − ΦT 0 (X ) = ki=1 ΦT (X i ) − ΦT 0 (X i ) .
We introduce three kinds of sets of nodes, namely subtree-disjoint, monotone, and zigzag
sets, and derive bounds on the potential change for each of them. See Figure 3.3 for illustration.
A set of nodes X ⊆ P is subtree-disjoint if subtreeT 0 (a) ∩ subtreeT 0 (b) = ; for all pairs of
distinct a, b ∈ X . Remark that subtree-disjointness is defined with respect to the subtrees
after the access.
Again, let (a 0 , a 1 , . . . , a |P |−1 ) be the nodes of the search path P from x to the root of T . For
each i , define the set Zi = {a i , a i +1 } if a i and a i +1 lie on different sides of x, and let Zi = ;Sotherwise. The zigzag set ZP is defined as ZP = i Zi . In words, the number of non-empty
sets Zi is exactly the number of zigzags in the search path, and the cardinality of ZP is thenumber of elements involved in such zigzags.
A set of nodes X ⊆ P is monotone if all elements in X are larger (smaller) than x and havethe same right-depth (left-depth) in the after-tree Q.
We bound first the change of potential for subtree-disjoint sets. The proof of the following
lemma was inspired by the proof of a statement similar to the access lemma for GreedyFuture¡¢
by Fox [42]. In the following we use the notation w s(x) for w subtreeT (x) and w s 0 (x) for¡¢w subtreeT 0 (x) . Further, we use the standard notation for open, closed, and mixed intervalsof integers, e.g. for a ≤ b we denote [a, b] = {a, a + 1, . . . , b}, (a, b) = {a + 1, . . . , b − 1}, (a, b] ={a + 1, . . . , b}. Recall that W = w(T ).
Lemma 3.6. Let X be a subtree-disjoint set of nodes. Then
|X | ≤ 2 + 8 · log

W+ ΦT (X ) − ΦT 0 (X ).
w s(x)

Proof. We consider the nodes smaller than x (i.e. X <x ) and greater or equal to x (i.e. X ≥x )separately. We show
|X ≥x | ≤ 1 + ΦT (X ≥x ) − ΦT 0 (X ≥x ) + 4 · logW.
w s(x)

A symmetric statement holds for X <x . We only give the proof for X ≥x .
Denote X ≥x by Y = {a 0 , a 1 , . . . , a q } where x = a 0 < . . . < a q . Before the access, x is a
descendant of a 0 , a 0 is a descendant of a 1 , and so on. Let subtreeT (a 0 ) = [c, d ]. Then[x, a 0 ] ⊆ [c, d ] and d < a 1 . Let w 0 = w s(a 0 ). For j ≥ 0, define σ j as the largest index ` such¡¢that w [c, a ` ] ≤ 2 j · w 0 . Then σ0 = 0 since
l weights
m are positive and [c, d ] is a proper subset ofW[c, a 1 ]. The set {σ0 , . . .} contains at most log w
distinct elements. It contains a 0 and a q .
0
Now we bound from above the number of indices i with the property σ j ≤ i < σ j +1 . We
call such an element a i heavy if w s 0 (a i ) > 2 j −1 · w 0 . There can be at most 3 heavy elements
as otherwiseX¡¢w [c, a j +1 ] ≥w s 0 (a k ) > 4 · 2 j −1 · w 0 ,σ j ≤k<σ j +1

60

Chapter 3. Splay tree: variations on a theme

a contradiction.
Next we count the number of light (a.k.a. non-heavy) elements. For every light element¡¢¡¢
a i , we have w s 0 (a i ) ≤ 2 j −1 · w 0 . We also have w s(a i +1 ) ≥ w [c, a i +1 ] > w [c, a σ j ] and thus
i +1 )
w s(a i +1 ) > 2 j · w 0 by the definition of σ j . Thus the ratio r i = wws(as 0 (a i ) ≥ 2 whenever a i is alight element. Moreover, for any i = 0, . . . , q − 1 (for which a i is not necessarily light), we haver i ≥ 1. Thus,Ã!
YYw s 0 (a q )
w
s(a
)
i
2number of light elements ≤
ri =
.
·
0
w0
0≤i ≤q w s (a i )0≤i ≤q−1

W.
So the number of light elements is at most ΦT (Y ) − ΦT 0 (Y ) + log w
0

W
Putting the bounds together, and denoting L = log w, we obtain0|Y | ≤ 1 + 3(dLe − 1) + ΦT (Y ) − ΦT 0 (Y ) + L ≤ 1 + 4L + ΦT (Y ) − ΦT 0 (Y ).
We look next at monotone sets. We first make a simple observation, then we bound thecontribution of monotone sets to the potential difference.
Lemma 3.7. Assume x < a < b and that a is a proper descendant of b in P . If {a, b} ismonotone, then subtreeT 0 (a) ⊆ subtreeT (b).
Proof. Clearly [x, b] ⊆ subtreeT (b). The smallest item in subtreeT 0 (a) is larger than x, andsince a and b have the same right-depth, b is larger than all elements in subtreeT 0 (a).
Lemma 3.8. Let X be a monotone set of nodes. ThenΦ(X ) − Φ0 (X ) + log

W
≥ 0.
w(x)

Proof. We order the elements in X = {a 1 , . . . , a q } such that a i is a proper descendant of a i +1
in the search path for all i . Then subtreeT 0 (a i ) ⊆ subtreeT (a i +1 ) by monotonicity, and henceQX
w s(a i +1 )w s(a 1 ) q−1
a∈X w s(a)log
Φ(X ) − Φ0 (X ) = log Q
+
.
=
log
0
0
w s (a q ) i =1
w s 0 (a i )a∈X w s (a)w(x)1)
The second sum is nonnegative. Thus Φ(X ) − Φ0 (X ) ≥ log wwss(a0 (a ) ≥ log W .
qTheorem 3.9. Suppose that for every access to an element x, we can partition the elementson the search path P into k subtree-disjoint sets D 1 to D k and ` monotone sets M 1 to M ` .
Then
X
i ≤k

|D i | ≤ ΦT (S) − ΦT 0 (S) + 2k + (8k + `) · log

W
.
w(x)

The proof of Theorem 3.9 follows immediately from Lemma 3.6 and 3.8.
Finally, we look at zigzag sets. We view the transformation as a two-step process, i.e. wefirst rotate x to the root and then transform the left and right subtrees of x. Since we assume
the access-to-root property, this is no restriction.
³´
Lemma 3.10. |Z | ≤ Φ(ZP ) − Φ0 (ZP ) + O 1 + log wWs(x) .
Proof. Because x becomes the root, and ancestor relationships are otherwise preserved,
subtreeT 0 (a) = subtreeT (a) ∩ (−∞, x) if a < x, and subtreeT 0 (a) = subtreeT (a) ∩ (x, ∞) if a > x.
We first deal with a single zigzag.

3.3. Sufficient conditions for efficiency

61

i +1 )
Lemma 3.11. 2 ≤ Φ(Zi ) − Φ0 (Zi ) + log wws(as(a i ) .

Proof. This proof is essentially the same as the proof for the ZIG-ZAG case for splay trees [91].
We give the proof only for the case where a i > x and a i +1 < x, as the other case is symmetric.
Let a 0 be the left ancestor of a i +1 in P and let a 00 be the right ancestor of a i in P . If these¡¢elements do not exist, we set the values to −∞ and +∞, respectively. Let W1 = w (a 0 , 0) ,¡¡¢¢W2 = w (0, a 00 ) , and W 0 = w (a i +1 , 0) . In T we have w s(a i ) = W 0 +w(x)+W2 and w s(a i +1 ) =W1 + w(x) + W2 , and in T 0 we have w s 0 (a i ) = W2 and w s 0 (a i +1 ) = W1 .
Thus
Φ(Zi ) − Φ0 (Zi ) + log

W1 + w(x) + W2
W 0 + w(x) + W2

≥ log(W1 + w(x) + W2 ) − logW1 + log(W2 + w(x) + W 0 ) − logW2+ log

W1 + w(x) + W2
W 0 + w(x) + W2

≥ 2 · log(W1 + W2 ) − logW1 − logW2≥ 2,
since (W1 + W2 )2 ≥ 4W1W2 for all W1 ,W2 .
Let Zeven (Zodd ) be the union of the Zi sets with even (odd) indices. One of the two sets
has cardinality at least |Z2P | . Assume that it is the former, the other case is symmetric. We sum
the statement of the claim over all i in Zeven and obtain¶µXw s(a i +1 )0Φ(Zi ) − Φ (Zi ) + log≥ 2 · |Zeven | ≥ |ZP | .
w s(a i )i ∈Zeven
The elements in ZP \ Zeven form two monotone sets and hence
Φ(ZP \ Zeven ) − Φ0 (ZP \ Zeven ) + 2 · log

W≥ 0.
w s(x)

This completes the proof.
The following theorem combines all three tools: subtree-disjoint, monotone, and zigzag
sets.
Theorem 3.12. Suppose that for every access we can partition P \ {x} into at most k subtreedisjoint sets D 1 to D k and at most ` monotone sets M 1 to M ` . Then
¶
µ
X
¡
¢¡
W ¢
|D i | + |ZP | ≤ Φ(P ) − Φ0 (P ) + O k + ` 1 + log
.
w(x)
i ≤k
Proof. We view the transformation as a two-step process, i.e. we first rotate x to the root andthen transform the left and right subtrees of x. Let Φ00 be the potential of the intermediate
tree. By Lemma 3.10,µ¶
W|ZP | ≤ Φ(P ) − Φ00 (P ) + O 1 + log.
w s(x)
By Theorem 3.9,¶¢¡W ¢|D i | ≤ Φ (P ) − Φ (P ) + O k + ` 1 + log
.
w(x)
i ≤k
X

00

0

µ
¡

62

Chapter 3. Splay tree: variations on a theme

To prove the main theorem, we just need the following proposition that follows directlyfrom the definition of monotone set.
Lemma 3.13. Let S ⊆ P be a set of keys consisting only of elements larger than x. Then S canbe decomposed into ` monotone sets if and only if the elements of S have only ` different
right-depths in the after-tree. A symmetric statement holds for elements smaller than x.
We are ready to prove the main theorem.
Proof of Theorem 3.4. Let L be the set of leaves of Q. By assumption (i) there is a positive|Q|−zconstant c such that |L| ≥ c . Then |Q| ≤ c · | L | + z. We decompose P \ {x} into L and `monotone sets. By assumption (ii) ` = O(1). An application of Theorem 3.12 with k = 1 and` = O(1) completes the proof.

3.4 Applications
Theorem 3.4 implies the access lemma for essentially all BST algorithms for which it is known
to hold (we refer here to online BST algorithms with the access-to-root restriction), as well as
for some new ones.
Theorem 3.14 (Restatement of Theorem 2.16). The access lemma holds for Splay.
Proof. Recall the global view of Splay from § 3.2. Consider the search path P for a splay
access. There are |P2 | − 1 odd-even pairs of successive nodes on the search path. For each pair,
if there is no side change, then Splay creates a new leaf in the after-tree. Let L denote the setof leaves in the after-tree, and let z denote the number of side changes (zigzags) in the searchpath. Thus
|P |
|L| ≥
− 1 − z.
2
Since the right-depth (left-depth) of elements in the after-tree of Splay is at most 2, both
requirements of Theorem 3.4 hold, and an application of the theorem finishes the proof.
Theorem 3.4 also implies the access lemma for the generalizations of Splay by Subramanian [99] and by Georgakopulos and McClurkin [48], although only with the access-to-root
restriction. We omit the details here, and refer to [25]. Furthermore, an analogue of Theorem 3.4 can be defined in geometric view (§ 2.7), and used to show that GreedyFuture andOnlineGreedy satisfy a statement analogous to the access lemma. (This is somewhat surprising since GreedyFuture does not have the access-to-root property, and OnlineGreedy is noteven a strict algorithm in tree-view.) Again, we refer to [25] for details.
PathBalance. The PathBalance BST algorithm transforms the search path P into a balanced
BST of depth dlog |P |e. This heuristic was suggested by Sleator (as reported in [99]). Observethat in the described form, PathBalance is a strict online algorithm, but in general it does nothave the access-to-root property. To make the algorithm amenable to our tools, we change
it slightly, such as to transform P into a balanced BST rooted at the accessed element x. The
depth of this BST is at most dlog(1 + |P |)e, and there is no reason to believe that the modified
version of the algorithm would have radically different performance compared to the originalone. The following basic question raised by Sleator is open.
Problem 34. Is the cost of PathBalance m · O(log n) for every (sufficiently long) access sequence X ∈ [n]m ?

3.5. Monotonicity and locality

63³´
log log n
In 1995 Balasubramanian and Raman [10] showed the upper bound of m·O log n · log log log non the cost of PathBalance, using a quite involved argument. This is still the best known
guarantee. We show that a simple application of the tools developed in § 3.3 almost matches
this bound.
First we observe that since the after-tree in PathBalance is a balanced BST, the numberof leaves in the after-tree is Ω(|P |). There are, hovewer, nodes with Ω(log |P |) right-depth
or left-depth in the after-tree, which can be as large as Ω(log n). Thus, we cannot directly
apply Theorem 3.4. Nevertheless, the techniques developed in § 3.3 can be used to show thefollowing result for PathBalance.
³¡
¢¡
¢´
W
Lemma 3.15. |P | ≤ Φ(P ) − Φ0 (P ) + O 1 + log |P | 1 + log w(x).

Proof. We decompose P into sets P 0 to P c , where P k contains the nodes of depth k in theafter-tree. Each P k is subtree-disjoint. An application of Theorem 3.9 completes the proof.
¡¢
Theorem 3.16. PathBalance has cost at most m · O log n · log log n when accessing X =(x 1 , . . . , x m ) ∈ [n]m .
Proof. We choose the uniform weight function: w(a) = 1 for all a ∈ [n]. Let c i be the cost ofP
accessing x i , for 1 ≤ i ≤ m, and let C = 1≤i ≤m c i be the total cost of accessing X = (x 1 , . . . , x m ).
Q
Note that i c i ≤ (C /m)m . Since Φ(T ) ≤ n log n for any BST T over [n], we haveC ≤ n log n +

X

¡¡
¢¡
¢¢
O 1 + log c i 1 + log n = m · O(log n) · log(C /m)

1≤i ≤mby Lemma 3.15. Assume C = K · m log n for some K . Then K = O(1) + O(1) · log(K · log n) andhence K = O(log log n).

3.5 Monotonicity and locality
In this section we show that locality of a strict online BST algorithm, i.e. the fact that its
transition function Γ has a decomposition that satisfies conditions (i)-(v) from § 3.1, is, in a
precise sense, equivalent with the monotonicity condition described in § 3.3.
Recall that a strict online BST algorithm A with the access-to-root property is called local
with window-size c, if all the transformations P → Q defined by its transition function ΓA
have a decomposition with properties (i)-(v) from § 3.1. We are mainly concerned with thecase when c = O(1).
Recall the definition of monotone sets from § 3.3. We call a strict online BST algorithm
A with the access-to-root property w-monotone, if all after-trees generated by ΓA can bepartitioned into w monotone sets. By Lemma 3.13, this is equivalent with the condition thatfor every after-tree Q of ΓA , the nodes in Q have at most w different left- or right-depths. We
are mainly concerned with the case when w = O(1).
In the remainder of the section we prove the following theorem.
Theorem 3.17. Let A be a strict online BST algorithm with the access-to-root property. (i) If
A is local with window size w, then it is 2w-monotone. (ii) If A is w-monotone, then it islocal with window-size w.
Let x denote the accessed element in the search path P (i.e. the root of Q).
(i) Suppose for contradiction that the after-tree Q is not decomposable into 2w monotone sets. As a corollary of Lemma 3.13, A contains a sequence of elements x 1 , x 2 , . . . , x w+1
such that either (a) x < x 1 < · · · < x w+1 , or (b) x w+1 < x w < · · · < x 1 < x holds, and x i +1 is a
descendant of x i for all i . Assume that case (a) holds, the other case is symmetric.

64

Chapter 3. Splay tree: variations on a theme0

Let i 0 be the first index for which x w+1 ∈ P i . From the (window-size) condition we know
0that P i contains at most w elements, and thus there exists some index j < w + 1 such that
000
x j ∉ P i . As x j is a descendant of x w+1 in the search path P , it was on some path P i for
i 00 < i 0 , and due to the (no-revisit) condition it will not be on another path in the future. Thus,
it is impossible that x j becomes an ancestor of x w+1 , so no local algorithm can create Q fromP , a contradiction.
(ii) We give an explicit local algorithm A that creates the tree Q from the path P . As
in Lemma 3.13, we decompose Q into Q >x = R 1 ∪ · · · ∪R w R and Q <x = L 1 ∪ · · · ∪L w L where R i(respectively L i ) denote the set of elements whose search path contains exactly i edges of type (resp. of type ). In other words, R i and L i denote the set of elements with right-depth,
resp. left-depth equal to i . Let L 0 = R 0 = {x}. Denote as P = (x 1 , x 2 , . . . , x k = x) the search pathfor x, i.e., x 1 is the root of the current tree and x j +1 is a child of x j . For any j , let t j (R i ) be theelement in R i ∩ {x j , . . . , x k } with minimal index, and define t j (L i ) analogously.
For any node s of Q, let the first right ancestor FRA(s) be the first ancestor of s in Q thatis larger than s (if any) and let the first left ancestor FLA(s) be the first ancestor of s smaller
than s (if any).
We start by making a few structural observations, which we prove later.
Lemma 3.18. Fix j , let S = {x j , . . . , x k }, consider any i ≥ 1, and let s = t j (R i ).
(i) If s is a right child in Q then its parent belongs to S ∩ R i −1 .
(ii) If s is a left child in Q then FRA(s) 6∈ S and FLA(s) = t j (R i −1 ).
(iii) If s is a right child and FRA(s) ∈ S then all nodes in subtreeQ (s) belong to S.
(iv) If FRA(s) ∈ S then FRA(t j (R ` )) ∈ S for all ` ≥ i .
We are now ready for the algorithm. We traverse the search path P of x backwards towards
the root. Let P = (x 1 , x 2 , . . . , x k = x). Assume that we have reached node x j . Let S = {x j , . . . , x k }(the already seen nodes). We maintain an active set A of nodes. It consists of all t j (R i ) suchthat FRA(t j (R i )) 6∈ S and all t j (L i ) such that FLA(t j (L i )) 6∈ S. When j = k, A = S = {x}. Consider
any y ∈ A such that y > x (the argument for y < x is symmetric and omitted). Assume thatparent(y) ∈ S. Then y must be a right child (since, otherwise parent(y) ∉ S, by definition of
A). Furthermore, FRA(y) 6∈ S. Since FRA(y) = FRA(parent(y)), it follows that parent(y) is also
active.
By part (iv) of Lemma 3.18, there are indices ` and r such that exactly the nodes t j (L ` ) tot j (R r ) are active. When j = k, only t j (R 0 ) = t j (L 0 ) = x is active. We maintain the active nodes
in a path P 0 . By the preceding paragraph, the nodes in S \ A form subtrees of Q. We attach
them to P 0 at the appropriate places and we also attach P 0 to the initial segment x 1 to x j −1 ofP.
What are the actions required when we move from x j to x j −1 ? Assume x j −1 > x and let
S 0 = {x j −1 , . . . , x k }. Also assume that x j −1 belongs to R i and hence x j −1 = t j −1 (R i ). For all ` 6= i ,t j (R ` ) = t j −1 (R ` ). Notice that x j −1 is larger than all elements in S and hence FRA(x j −1 ) 6∈ S 0 .
Thus x j −1 becomes an active element and the t j (R ` ) for ` < i are active and will stay active.
All t j (R ` ), ` > i , with FRA(t j (R ` )) = x j −1 will become inactive and part of the subtree of Q
formed by the inactive nodes between t j (R i ) and x j −1 . We change the path P 0 accordingly.
Verifying that the algorithm satisfies conditions (i)-(v) of a local algorithm is straightforward: the path P 0 is augmented by one new element in every step, its size is at most w at all
times (since it contains at most one node from each L i and R i ), and once a node becomesinactive (leaves P 0 ), it never becomes active again.
It remains to prove the earlier structural observations.

3.6. On the necessity of locality

65

Proof of Lemma 3.18.
(i) The parent of s lies between x and s and hence belongs to S. By definition of the R i ’s, italso belongs to R i −1 .
(ii) parent(s) ∈ R i and hence, by definition of t j (R i ), we have parent(s) 6∈ S. Since FLA(s) < s,we have FLA(s) ∈ S ∩ R i −1 . The element in R i −1 after FLA(s) is larger than parent(s) andhence does not belong to S.
(iii) The elements between x and FRA(s) (inclusive) belong to S.
(iv) Since z = FRA(s) ∈ S, s is a right child and z belongs to R ` for some ` < i . Consider any` > i , and let q = t j (R ` ). Suppose that q > z. Then on the path between q and z (in Q)
there is some element in S ∩ R i greater than s, contradicting s = t j (R i ). Therefore, q < z,
and hence FRA(q) ≤ z. Thus FRA(t j (R ` )) ∈ S.
We remark that the algorithm in the proof of Theorem 3.17 relies on advice about the
global structure of the search path to after-tree transformation. In particular, it uses information about the nearest left- or right- ancestor of a node in the after-tree Q. Therefore, theresult of this section can be interpreted as saying that transformations that are monotone canbe decomposed and executed as a local transformation. This does not, however, imply thatthe resulting local algorithm has a compact description, or that the local transformations canbe done using only locally available information (as in Splay).
Nonetheless, a limited amount of information about the already-processed structure of
the search path can be encoded in the shape of the path P 0 that contains the active set A (thechoice of the path shape is rather arbitrary, as long as the largest or the smallest element is at
its root).

3.6 On the necessity of locality
In this section we look at whether the monotonicity condition (i.e. condition (ii) of Theorem 3.4), or equivalently the locality condition (i.e. conditions (i)-(v) from § 3.1), is necessary
for an algorithm to be efficient. We show the following result, which can be seen as a partial
converse of Theorem 3.4. We refer to § 3.9 for a discussion of its implications.
Theorem 3.19. If the access lemma with the sum-of-logs potential function holds for a BST
algorithm A, then the after-trees created by A must satisfy condition (ii) of Theorem 3.4, i.e.
A is k-monotone with k = O(1).
Proof. Consider a transformation ΓA : P → Q of a strict online BST algorithm A when accessing x. Suppose that Q \ {x} cannot be decomposed into constantly many monotone sets.
We want to show that A does not satisfy the access lemma with the sum-of-logs potentialfunction Φ.
Assume w.l.o.g. that the right subtree of Q cannot be decomposed into constantly many
monotone sets. Let s > x be a node of maximum right depth in Q. By Lemma 3.13, we may
assume that the right depth is k = ω(1). Let x 1 , . . . , x k be nodes on the path to s, such thatx < x 1 < · · · < x k < s. All these nodes are descendants of s in the search path P .
Let us define a weight assignment to the elements of P and the trees hanging from P , forwhich the access lemma does not hold. Assign weight zero to all pendent trees, weight 1 toall proper descendants of s in P and weight K (where K À 1) to all ancestors of s in P . The
total weight W then lies between K and |P | · K .
We bound the potential change. We use the same notation as in the previous sections.
0(a)
Let r (a) = wwss(a). In words, r (a) is the ratio between the weights of the subtree rooted at a in
the after-tree and in the search path. For all nodes x i , we have w s(x i ) ≤ |P | and w s 0 (x i ) ≥ K .

66

Chapter 3. Splay tree: variations on a theme

So r (x i ) ≥ |PK | . Consider now any other node a ∈ P . If a is an ancestor of s in the search path,then w s(a) ≤ W and w s 0 (a) ≥ K . If a is a descendant of s, then w s(a) ≤ |P | and w s 0 (a) ≥ 1.
Thus r (a) ≥ |P1 | for every a ∈ P . We conclude
Φ0 (T ) − Φ(T ) ≥ k · log

K− |P | · log |P |.
|P |If A satisfies the access lemma with the sum-of-logs potential function, then we must
have:
µ
¶
¡ ¡
¢¢
W
0
Φ (T ) − Φ(T ) ≤ O log− |P | = O log K · |P | .
w(x)
¡ ¡
¢¢
However, if K is large enough and k = ω(1), then k · log |PK | − |P | · log |P | À Ω log K · |P | , a
contradiction.

3.7 On the necessity of many leaves
In this section we study condition (i) of Theorem 3.4. This condition can be interpreted assaying that the number of leaves in the after-tree Q or the number of zigzags in the search
path P must be proportional to |P |.
The fact that condition (ii) of Theorem 3.4 alone is not sufficient for an algorithm to satisfy the access lemma, follows fromthe easy observation that Move-to-root satisfies condition (ii), but
not the access lemma. Informally, we can say that an algorithm
must “do something else” besides being local (=monotone). It
would be desirable to show that this “something” must be exactly condition (i) of Theorem 3.4. A conclusive statement in thisdirection would say that “if a sufficiently high fraction of the transformations done by A do not satisfy condition (i), then the accesslemma cannot hold”. Perhaps most insight would be gained fromthe description of a global adversary strategy that would force any
algorithm that consistently violates (i) to have high total cost.
At this point, we are unable to prove such a statement. Instead,
we relate condition (i) to a different (reasonable) measure of efficiency: the sequential access condition. (Recall that A satisfies Figure 3.4: Illustration of the proof
the sequential access condition, if from every initial tree over [n] of Theorem 3.20. Tree after accessing
it can serve the sequence (1, . . . , n) with cost O(n).) We show the node i − 1, before accessing i . Wing
partition shown with shaded ellipses.
following theorem.
Theorem 3.20. If for all after-trees Q created by algorithm A, it holds that (i) Q can be
decomposed into O(1) monotone sets, and (ii) the number of leaves of Q is at most n o(1) ,then A does not satisfy the sequential access condition.
Observe that the value n in Theorem 3.20 is the global number of nodes (not just the
number of nodes |Q| on the search path). Before proving Theorem 3.20, we state the open
question of whether the result can, in some way, be improved.
Problem 35. Can Theorem 3.20 be strengthened in any of the following ways?
1. Involving in the statement (instead of the sequential access condition) the balance
condition, the access lemma, or some other measure of efficiency.
2. Involving in the statement the quantity z (number of zigzags).
3. Relaxing the condition that every transformation must create only few leaves.
4. Relaxing the dependence on the monotonicity condition.

3.7. On the necessity of many leaves

67

5. Relaxing the bound n o(1) to, say, o(n) or o(|Q|).
Despite the shortcomings of Theorem 3.20, there are also some apparent strengths of thisresult (which can be seen as another partial converse of Theorem 3.4). In particular, the statement refers to the sequential access property, without relying on the sum-of-logs potential,or on any other proof technique. Second, as the quantity n o(1) involves n, and not |Q|, theresult holds regardless of what the algorithm does when |Q| ≤ n o(1) , i.e. when the search pathis very short. The remainder of the section is devoted to the proof of Theorem 3.20.
Let R be a BST over [n]. We call a maximal left-leaning path of R a wing of R. Moreprecisely, a wing of R is a set {x 1 , . . . , x k } ⊆ [n], with x 1 < · · · < x k , and such that x 1 has no leftchild, x k is either the root of R, or the right child of its parent, and x i is the left child of x i +1
for all 1 ≤ i < k. A wing may consist of a single element. Observe that the wings of R partition[n] in a unique way, and we call the set of wings of R the wing partition of R, denoted as
w p(R). We define a potential function Ψ over a BST R as follows:
Ψ(R) =

X|w| · log |w|.

w∈w p(R)Let T0 be a left-leaning path over [n] (i.e. n is the root and 1 is the leaf). Consider a strict
online BST algorithm A with the access-to-root property. Suppose that A accesses elementsof [n] in sequential order, starting with T0 as initial tree. Let Ti denote the BST after accessing
element i . Then Ti has i as the root, and the elements yet to be accessed (i.e. {i + 1, . . . , n})form the right subtree of the root, denoted R i . To avoid treating T0 separately, we augment
it with a “virtual root” 0. This node plays no role in subsequent accesses, and it only adds a
constant one to the overall access cost.
Using the previously defined potential function, we denote Ψi = Ψ(R i ). We make thefollowing easy observations: Ψ0 = n log n, and Ψn = 0.
Next, we look at the change in potential due to the restructuring after accessing elementi . Let P i = (x 1 , x 2 , . . . , x ni ) be the search path when accessing i in Ti −1 , and let n i denote its
length, i.e. x 1 = i − 1, and x ni = i . Observe that the set P i0 = P i \ {x 1 } is a wing of Ti −1 .
Let Q i be the after-tree resulting from the re-arranging of the path P i . Observe that theroot of Q i is i , and the left child of i in Q i is i − 1. We denote the tree Q i \ {i − 1} as Q i0 , and thetree Q i0 \ {i }, i.e. the right subtree of i in Q i , as Q i00 .
The crucial observation of the proof is that for an arbitrary wing w ∈ w p(Ti ), the following
holds: (i) either w was not changed when accessing i , i.e. w ∈ w p(Ti −1 ), or (ii) w contains a
portion of P i0 , possibly concatenated with an earlier wing, i.e. there exists some w 0 ∈ w p(Q i0 ),such that w 0 ⊆ w. In this case, we denote as ext(w 0 ) the extension of w 0 to a wing of w p(Ti ),i.e. ext(w 0 ) = w \ w 0 , and either ext(w 0 ) = ;, or ext(w 0 ) ∈ w p(Ti −1 ).
Now we bound the change in potential Ψi − Ψi −1 . Wings that did not change during
the restructuring (i.e. those of type (i)) do not contribute to the potential difference. Also
note, that i contributes to Ψi −1 , but not to Ψi . Thus, we have for 1 ≤ i ≤ n, assuming that0 log 0 = 0, and denoting f (x) = x log(x):Ψi − Ψi −1 =

X

¯¢
¯ ¢¢
¡ ¡ ¯ 0¯ ¯¡¯
f ¯w ¯ + ¯ext(w 0 )¯ − f ¯ext(w 0 )¯ − f (n i − 1).

w 0 ∈w p(Q i00 )By simple manipulation, for 1 ≤ i ≤ n:
Ψi − Ψi −1 ≥X
w 0 ∈w p(Q i00 )¡¯ ¯¢
f ¯w 0 ¯ − f (n i − 1).

68Chapter 3. Splay tree: variations on a theme
By convexity of f , and observing that |Q i00 | = n i − 2, we haveÃ!
¯¯ni − 2n −200 ¯¯¯ − f (n i − 1) = (n i − 2) · log ¯ i 00 ¯ − f (n i − 1).
Ψi − Ψi −1 ≥ w p(Q i ) · f ¯¯w p(Q 00 )¯¯w p(Q )¯ii¯¯Lemma 3.21. If R has right-depth m, and k leaves, then ¯w p(R)¯ ≤ mk.

Proof. For a wing w, let `(w) be any leaf in the subtree rooted at the node of maximum depth
in the wing. Clearly, for any leaf ` there can be at most m wings w with `(w) = `. The claim
follows.
¯¯
Thus, ¯w p(Q i00 )¯ ≤ n o(1) . Summing the potential differences over i , we getΨn − Ψ0 = −n log n ≥ −nXn i log (n o(1) ) − O(n).

i =1Denoting the total cost of algorithm A on the access sequence (1, . . . , n) as C , we obtainP
C = ni=1 n i = n · ω(1). This shows that A does not satisfy the sequential access property.

3.8 Depth-halving
Already Sleator and Tarjan [91] formulated the belief that the property that makes Splayefficient is depth-halving, i.e. the fact that every element on the search path reduces its
distance to the root by a factor of approximately two. Later authors [99, 10, 48] raised thequestion, whether such a global depth-reduction property is by itself sufficient to guarantee
the access lemma. In this section we explore this question.
Let A be a strict online BST algorithm with the access-to-root property. As before, let P be
the search path when searching for key x using algorithm A, let Q be the resulting after-tree,
and let T and T 0 be the trees before and after the access.
We say that A is weakly depth-halving if for every node x ∈ P it holds that d T 0 (x) ≤d T (x)/2 + c, for some fixed constant c ≥ 0. Let us observe the following easy fact.
Theorem 3.22 ([91]). Splay is weakly depth-halving.
Proof. The proof follows from the following observations, which can be verified by inspectionof Figure 2.3 (note that the final ZIG step affects the depths by a constant one only.)
1. In every ZIG-ZIG or ZIG-ZAG step, descendants of x reduce their depth by at least 1.
2. A node of P may increase its depth by at most 2 before becoming the descendant of x
3. A node that is a descendant of x, will remain so throughout all remaining ZIG-ZIG and
ZIG-ZAG steps of the current access.
4. When a node y ∈ P becomes a proper descendant of x, the number of remaining
ZIG-ZIG or ZIG-ZAG steps of the current access is at least bd T (y)/2c − 1.
(We remark that by a similar argument, Semi-splay (§ 2.5.2) is also weakly depth-halving,even though it does not have the access-to-root property.)
If weak depth-halving leads to good properties of algorithms, one would expect thatthe reduction of depths by some smaller constant factor would also be sufficient. Such a
constant-factor depth-reduction can be shown for the local algorithms with local depthreduction conditions discussed in Theorem 3.2 and the rest of § 3.1. The following natural
questions are open.

3.8. Depth-halving

69

Problem 36. Does every weakly depth-halving strict online algorithm satisfy the balance
condition? More strongly, does the access lemma hold for every such algorithm? How about
the sequential access, dynamic finger, lazy finger, and O(1)-competitiveness properties?
Let us first show a negative result: weak depth-halving by itself does not imply theconditions of Theorem 3.4 (Figures 3.6, 3.7, 3.8 illustrate this). In some sense, Figure 3.8 isthe strongest of the counterexamples, since in that case, even though the transformation is
weakly depth-halving, the monotonicity-condition is violated (an anti-monotone path of
linear size is created). It follows from Theorem 3.19 that weak depth-halving cannot imply
the access lemma in its full generality with the sum-of-logs potential function.
A possible way to modify the definition of weak depth-halving would be to require depthhalving for the roots of the subtrees hanging from the search path, instead of the nodesof the search path themselves. The proof of Theorem 3.22 can be minimally adapted toshow that Splay satisfies this modified form of depth-halving as well. Unfortunately, thetransformations shown on Figures 3.6 and 3.8 satisfy this modified form of depth-halving,violating at the same time, some condition of Theorem 3.4.
Does perhaps weak depth-halving and monotonicity together imply the access lemma?
This may still be the case, perhaps even provable by an argument involving the sum-of-logs
potential, but not by our Theorem 3.4, as Figures 3.6 and 3.7 show.
In general, the reverse implication between the conditions of Theorem 3.4 and depthhalving does not hold either. It is easy to think of a transformation that is monotone, createsa linear number of leaves, yet it is not depth-halving (for instance, this is the case, if we run
Splay only halfway up the search path).
In the remainder of the section we describe a stronger form of depth-halving, that does
imply the conditions of Theorem 3.4, and thus guarantees the access lemma. This leads to a
new family of efficient BST algorithms with a natural global description.
Let A be a strict online BST algorithm with the access-to-root property. Consider again
the search path to after-tree transformation P → Q, and let T and T 0 be the trees before andafter the access.
Let a, b ∈ P be two arbitrary nodes. If b is an ancestor of a in P, but not in the after-tree
Q, then we say that a has lost the ancestor b, and b has lost the descendant a. Similarly wedefine gaining an ancestor or a descendant. We stress that only nodes on the search path
(resp. the after-tree) are counted as descendants, and not the nodes of the pendent trees (i.e.
only nodes in P , and not those in [n] \ P ).
We say that A is strongly depth-halving if (i) every node a ∈ P loses
at least ( 12 + ²) · depthT (a) − c ancestors, for fixed constants ² > 0, c ≥ 0,
and (ii) every node on the search path P , except the accessed elementx, gains at most d new descendants, for a fixed constant d ≥ 0.
Theorem 3.23. Let A be a strict online BST algorithm with the accessto-root property, that has the strong depth-halving property. Then theaccess lemma holds for A.
We prove Theorem 3.23 by applying Theorem 3.4. Before that, let
us argue that with our current proof techniques the conditions of TheFigure 3.5: Illustration of the orem 3.23 cannot be trivially strengthened. If we relax the constant in
proof of Theorem 3.23. Left condition (i) from ( 1 + ²) to 1 , the conditions of Theorem 3.4 are no2
2
subtree of x in after-tree Q.
longer implied. There exist rearrangements in which every node loses a
1
or descendants,
2 -fraction of its ancestors, gains at most two ancestorspyet both the number of zigzags and the number of leaves created are O( |P |) (this is shown

70

Chapter 3. Splay tree: variations on a theme

in Figure 3.6). If we further relax the ratio to ( 12 − ²), we can construct an example where thenumber of zigzags and the number of created leaves are only O(log |P |/²).
Allowing more gained descendants and limiting instead the number of gained ancestors
is also beyond the strength of Theorem 3.4. It is possible to construct an example (Figure 3.7)
in which every node loses an (1 − o(1))-fraction of ancestors, yet the number of leaves createdpis only O( |P |) (while having no zigzags in the search path).
Proof of Theorem 3.23. We show that A satisfies the conditions of Theorem 3.4.
Let x be the accessed element, and let L 1 be its left child in the after-tree. Let (L 1 , . . . , L t )denote the longest sequence of nodes such that for all i < t , L i +1 is the right child of L i in theafter-tree, and let Ti denote the left subtree of L i for all i ≤ t . Observe that the nodes in Ti
are ancestors of L i in the search path, therefore, L i has gained them as descendants. Thus,
from condition (ii) of strong depth-halving, we have that |Ti | ≤ d for all i . Since there are at
most d nodes in each subtree, the largest number of left-edges on a path in the left subtree ofx is d . A symmetric statement holds for the right subtree of x. This proves condition (ii) of
Theorem 3.4 (see Figure 3.5).
Next, we show that a linear number of leaves are created, verifying condition (i) of
Theorem 3.4. By depth(·) we always mean depthT (·), i.e. depth in the tree before the rearrangement.
²·depth(x)We claim that there exists a left-ancestor of x in the search path that loses−(c +1)
2
left-ancestors, or a right-ancestor of x that loses this number of right-ancestors.
Suppose that there exists such a left-ancestor L of x (the argument on the right is entirely
symmetric). Observe that the left-ancestors that L has not lost form a right-path, withsubtrees hanging to the left. The lost left-ancestors of L are contained in these subtrees. Fromthe earlier argument, each of these subtrees is of size at most d . Since the subtrees contain in²·depth(x)total at least− (c + 1) elements, there are at least
2
µ
¶
¡
¢
1 ² · depth(x)− (c + 1) = Ω depth(x)d2¡ ¢many of them, thus creating Ω |P | new leaves.
It remains to prove the claim that some ancestor of x loses many ancestors “on the sameside”. Let L and R be the nearest left- (respectively right-) ancestor of x on the search path.
Assume w.l.o.g. that L is the parent of x in the search path. For any node y in the search
path P , let d ` (y), d r (y) denote the number of left- respectively right-ancestors of y in P . We
consider two cases:• If d ` (x) > d r (x), then d r (L) ≤µdepth(x). Since L loses
2

¶
µ
¶
1
1
+ ² · depth(L) − c ≥+ ² · depth(x) − (c + 1)
2
2

ancestors, it must lose at least ² · depth(x) − (c + 1) left-ancestors.
• If d ` (x) ≤ d r (x), then d ` (R) < d r (R), and hence d ` (R) ≤depth(R) ≥ d r (R) = d r (x) − 1 ≥Since R losesµ¡1depth(R). At the same time,2

depth(x) − 2.
2

2 + ² · depth(R) − c ancestors, it must lose at least¢¶1
depth(x) − 2
depth(x)+ ² · depth(R) − c − d ` (R) ≥ ² ·−c ≥ ²·− (c + 1)
2
2
2

3.9. Discussion and open questions

71

right-ancestors.
Unfortunately, the strong depth-halving condition is indeed rather strong, for instance,
Splay does not satisfy it. Therefore, we close the section with the following general question.
Problem 37. Find a natural definition of depth-halving that Splay satisfies, and show that it
implies the access lemma (or at least the balance condition).

3.9 Discussion and open questions
In this chapter we discussed a number of results related to the efficiency of strict online
BST algorithms, based on properties of their transition function. We used the access lemma
as a stand-in for “efficiency”, as it implies a number of upper bounds for BST algorithms,
including static optimality (Theorem 2.17). The ultimate goal of this research program would
be a characterization of all efficient strict online BST algorithms. Unfortunately, we have notquite reached such a full understanding (even if we focus only on the access lemma).
In Theorem 3.4 we gave necessary conditions for a BST algorithm to satisfy the accesslemma. We looked at strict online algorithms with the access-to-root property, and additionally we required them to be “monotone”, as well as to involve “many leaves” or “many zigzags”
in every transformation. The class of algorithms thus obtained includes Splay. An immediate
follow-up question is the following.
Problem 38. Does every algorithm that satisfies the conditions of Theorem 3.4 have any of
the sequential access, dynamic finger, lazy finger, and O(1)-competitiveness properties?
Of the parameters used in Theorem 3.4, the number of zigzags is to the least extent under
the control of the algorithm designer, since it depends on the key being accessed, and it islikely that some key will have few zigzags on its search path. The reason why zigzags arehelpful seems to be related to depth-reduction: as we move the accessed element x to theroot, we break up edges between nodes on different sides of x, and thus we reduce the depths
of elements on both sides of x.
The role played by the monotonicity condition seems relatively well understood. In
particular, we have shown that it is equivalent with the “local decomposability” of an algorithm. We also showed that this condition is necessary for showing the access lemma via
the sum-of-logs potential. Does this mean that non-monotone (=non-local) algorithms areautomatically bad, or is this just a limitation of the sum-of-logs proof technique? We haveseen that reasonable families of algorithms, such as PathBalance or weak depth-halving
violate the monotonicity property. Can they satisfy the access lemma by some other potentialfunction? Less ambitiously, can they satisfy the balance condition? (See also Problem 34.)
Problem 39. Is there a (natural) non-monotone strict online BST algorithm with access-toroot property that satisfies the balance condition?
Non-monotonicity means that long monotone subsequences of nodes are “reversed”, i.e.
their orientation changed from left-leaning to right-leaning. Such a transformation has theeffect of significantly increasing the depth of some subtrees hanging from the search path.
Since in the strict model we have no information about the sizes of these subtrees, Splay,and other algorithms with the monotone property take the conservative route: they do notreverse long monotone paths, since doing this could send large subtrees down the tree. (Thisis also the intuition behind the proof in § 3.6). It is not clear, however, how frequently such

72

Chapter 3. Splay tree: variations on a theme

Figure 3.6: Weakly depth-halving re-arrangement of the search path P . The
transformation does not satisfy the conditions of Theorem 3.4. Every nodeof P loses half of its ancestors, gains at most one new ancestor, and every
node of P (except x) gains at most one new descendant. On the other hand,pz, ` = O( n), where z is the number of zigzags in P , and ` is the number ofleaves of the after-tree.

Figure 3.7: Weakly depth-halving re-arrangement of the search path P . The
transformation does not satisfy the conditions of Theorem 3.4. Every nodeof P loses a (1 − o(1))-fraction of its ancestors and gains at most one newpancestor. On the other hand, z = 0, and ` = O( n), where z is the number ofzigzags in P , and ` is the number of leaves of the after-tree.

Figure 3.8: Weakly depth-halving re-arrangement of the search path P . The
transformation does not satisfy the conditions of Theorem 3.4. Every node of
P approximately halves its depth. However, there is a node left of the accessed
node x with left-depth Ω(n).

3.9. Discussion and open questions73

bad scenarios can arise. To better understand the limitations of non-monotone algorithms, a
global adversary argument would be helpful.
Subramanian [99] argues compellingly, that as long as we enforce the locality (=monotonicity) condition, almost every BST re-arrangement satisfies the access lemma. Loosely
speaking, as long as our algorithm is local, it will do fine, unless most of the time it “doesnothing”, or if it “does what Move-to-root would do”, and on top of that, it is unlucky enoughto meet a search path that is left-leaning or right-leaning (i.e. few zigzags). “Doing fine” refers
here to satisfying the access lemma, which is still far from satisfying dynamic optimality.
(Proving that almost every algorithm in such a broad class satisfies dynamic optimality would
be a very interesting, if somewhat anticlimactic turn of events.)
Perhaps “many leaves” is the most intriguing parameter of Theorem 3.4. It is intuitivethat creating many branchings (and in consequence, many leaves) should be helpful, and in§ 3.7 we showed that (assuming monotonicity), a weaker form of the “many leaves” conditionis necessary for the sequential access property. We already asked whether this condition isnecessary in a stronger sense (Problem 35). Could it be that the “many leaves” condition
alone is sufficient?
Problem 40. If every transformation creates Ω(|P |) leaves, is the balance condition guaranteed? How about the sequential, dynamic finger, lazy finger, O(1)-competitiveness properties?
Since an algorithm with guaranteed “many leaves” may be non-monotone, it is plausiblethat the answer to Problem 40 is negative. A positive answer would, for instance, also imply
results about PathBalance, since PathBalance fulfills the many leaves property. (For thesequential property a positive answer would be much less surprising.) To settle the balance(i.e. logarithmic average cost) part of Problem 40, it would be sufficient to exhibit a longsequence of “search path → after-tree” transformations in a tree, in which the created subtrees
have a linear number of leaves, and the average length of the paths is superlogarithmic. We
find this a natural combinatorial question, regardless of its implications to the BST model.
A perhaps easier question would include the zigzags, as they appear in Theorem 3.4.
Problem 41. If every transformation creates Ω(|P | − z) leaves, where z is the number ofzigzags in P , is the balance condition guaranteed? How about the other properties?
In § 3.8 we explored the topic of depth-halving. Since the cost of an access depends
on the length of the search path, i.e. the depth of the accessed element, it is reasonable toexpect that some proof technique directly using global depths should help for studying BST
algorithms. The role played by depth-reduction in the efficiency of BST algorithms seems
not fully understood (Problems 36 and 37).
Finally, the access lemma is only part of the story. Addressing the following questions
would lead to new insight about the BST model. To answer these questions (even partially),
we may try to find alternative proofs or to generalize existing proofs of these properties for
Splay or other known algorithms.
Problem 42. Characterize the class of strict online algorithms that satisfy the sequential
access property.
Problem 43. Characterize the class of strict online algorithms that satisfy the dynamic finger,
lazy finger (if any), or O(1)-competitiveness (if any) properties.

75

Chapter 4

Pattern-avoiding access
Akár egy halom hasított fa,
hever egymáson a világ,
szorítja, nyomja, összefogja
egyik dolog a másikát.

— J ÓZSEF ATTILA, Eszmélet (1934)

In this chapter we study families of access sequences that can be served by BST algorithms
much faster than what the logarithmic worst case bound would suggest. The sequences
we study are characterized by their pattern-avoidance properties. Compared to structures
previously studied in the BST literature, pattern-avoidance captures a different aspect ofaccess sequences. Therefore, the results of this chapter can be seen as complementary to theupper bounds discussed in § 2.4.
Pattern-avoidance in sequences has a rich literature both in combinatorics [103, 56, 18,89] and in computer science [59, § 2.2.1], [22, 61, 102, 85, 19]. More broadly, the avoidance of
substructures in combinatorial objects has often been found to make algorithmic problems
easier (a prominent example is the theory of forbidden minors in graphs). Our goal is to
explore, to what extent the avoidance of patterns in access sequences is relevant and helpful
in the BST model.
We mostly consider access sequences X = (x 1 , . . . , x m ) ∈ [n]m that are permutations, i.e.
m = n, and X ∈ S n . We remark that many of the results can be extended to non-permutation
access sequences. Focusing on permutations allows us to avoid some technicalities, and it isalso justified by the following result.
Theorem 4.1. Suppose that there is a BST algorithm A whose cost is at most c · OPT(X )for all X ∈ S n . Then there is a BST algorithm B whose cost is at most O(c) · OPT(X ) for all
X ∈ [n]m , for m ≥ n.
We omit the proof of Theorem 4.1, and refer the reader to [24, Thm. 2.1]. The result
appears to have been folklore for some time (mentioned in [31]), and if both A and B
are offline algorithms, then it can be shown without further conditions, using an intuitive“perturbation”-argument. However, if we require A and B to be online BST algorithms, then,as far as we know, the result has only been shown with some (mild) assumption on A. (Theexact assumption in [24] is that A does not “touch” a node x, if x has not yet been on anyof the search paths for an access.) It is an interesting question whether Theorem 4.1 can beshown unconditionally for online algorithms.

4.1 Sequences and patterns
For convenience, we repeat the main definitions related to pattern-avoidance from § 1.3.

76

Chapter 4. Pattern-avoiding accessTwo sequences (a 1 , . . . , a n ) and (b 1 , . . . , b n ) of the same length are order-isomorphic, if
their entries have the same relative order, i.e. a i < a j ⇐⇒ b i < b j for all i and j . For example,(581) and (231) are order-isomorphic, whereas (1234) and (1324) are not.
Given a sequence X ∈ [n]m , and a permutation π ∈ S k , we say that X is π-avoiding, if it
has no subsequence that is order-isomorphic with π, otherwise we say that X contains π. For
example, the sequence (4, 7, 5, 2) contains 231 and is 123-avoiding. We often call the avoided(or contained) permutation π a pattern.
It is helpful to view sequences geometrically, i.e. we interpret a sequence X = (x 1 , . . . , x m ) ∈©
ª[n]m at the same time as a set of points X = (x i , i ) ⊂ [n] × [m]. Let us remark that all pointsets discussed in this chapter are in the plane, and consist only of points with integral
coordinates. Observe that a permutation X gives rise to a point set X in which no two points
are on the same horizontal or vertical line. Pattern-avoidance can be defined for arbitrary
point sets as follows.
A point set X ⊆ [n] × [m] avoids a point set P ⊆ [k] × [k], if there is no subset Y ⊆ X that isorder-isomorphic with P . Two point sets A and B are order-isomorphic, if there is a bijection
f : A → B that preserves the relative positions of points, i.e. x is strictly to the right of y if andonly if f (x) is strictly to the right of f (y), and x is strictly above y if and only if f (x) is strictly
above f (y), for all x, y ∈ A.
The correspondence between the two views is evident. For instance, a permutation X ∈ S n is 231-avoiding³´ exactly if its corre•• . See Figure 4.1 forsponding point set avoids the point set•
illustration.
As mentioned already, the topic of pattern-avoidance has received enormous attention from the mathematical community. Particularly the enumeration of pattern-avoiding permutations has
been extensively studied. Even for very small example patterns π (e.g.
π of size 4), the question of determining the number of π-avoiding Figure 4.1: Illustration of pattern
permutations turns out to be very difficult, and only in very few cases avoidance. Plot of permutation
X = (6, 1, 3, 2, 8, 7, 4, 5) containing
is an exact number (or even a precise asymptotic bound) known.
213 (highlighted) and avoiding
The following important result was known as the Stanley-Wilf
4321.
conjecture, formulated independently in the 1980s by Stanley andWilf, until it was proven in 2004 by Marcus and Tardos [70], building on work by Füredi and
Hajnal [45], as well as by Klazar [57].

Theorem 4.2 ([70]). There is a function f (·) such that for every permutation π ∈ S k , the¡¢nnumber of π-avoiding permutations of size n is at most f (k) .
From our point of view, the result plays the following role. We would like to show thatevery access sequence X ∈ S n that avoids some fixed pattern π ∈ S k can be accessed in the
BST model with low total cost. Ideally, we would like to show OPT(X ) ≤ n · g (k), for somefunction g (k) not depending on n. When such an upper bound on OPT(X ) exists, we saythat X has “linear cost”. (Linear cost can alternatively be seen as constant average cost per
access.) Theorem 4.2 shows that such a result can not be ruled out automatically. If thenumber of π-avoiding permutations were super-exponentional, then such a result would be
impossible, as Theorem 2.20 implies that at most an exponential number of sequences canhave linear cost.
In this chapter we prove several statements about the cost of sequences with patternavoiding properties. In its full generality, we are, as of yet, unable to settle the question. Let
us therefore propose the following as the main open question of this chapter (and perhaps ofthe entire thesis).

4.1. Sequences and patterns

77

Problem 44. Is there some fixed function f (·) such that for every access sequence X ∈ [n]mthat avoids an arbitrary fixed pattern π ∈ S k , we have OPT(X ) ≤ m · f (k)? More strongly, doessuch an upper bound hold for the cost of some online algorithm?

In § 4.4 we show a relaxed form of the statement, where the upper bound has a mild
dependence on n (in the form of the very slowly growing inverse Ackermann function α(n),see e.g. [30, § 21.4]). In § 4.5 and § 4.6 we show that the statement holds for some specificfamilies of patterns π. In most cases we are able to bound not only OPT, but also the cost of
the online BST algorithm Greedy (§ 2.7.1).
We also study the independent rectangle bound MIR(X ) in terms of pattern-avoidance
properties of the access sequence X (§ 4.7.1). In this case, we can show a linear boundfor all access sequences X that avoid an arbitrary fixed pattern π. Recall from § 2.4 that
MIR is the strongest known lower bound for OPT, and it is conjectured to asymptotciallymatch OPT. (In fact, Wilber conjectured that even the weaker W 2 bound matches OPT.)
Results of this type give further evidence that the answer to Problem 44 may be affirmative. Indeed, if the cost of Greedy (or any other online algorithm A) on pattern-avoiding
input is superlinear, then either Greedy (or A) is not dynamically optimal, or the conjecture¡¢
MIR(X ) = Θ OPT(X ) must be false.
The family of access sequences that avoid an arbitrary fixed pattern is quite general.
Special cases that were intensively studied in the BST literature include sequential access(the sequence S = (1, 2, . . . , n) avoids 21, and it is the only permutation of length n to do so),and traversal access (preorder sequences are exactly the 231-avoiding permutations, see
Lemma 1.4). As far as we know, even for the 231-avoiding case, it was not previously shownthat an online algorithm can achieve linear cost. (Chaudhuri and Höft [27] show that Splayachieves linear cost on 231-avoiding access sequences, but only with an initial tree that
depends on the input, thus the algorithm can not be considered online).
It is well-known that a random permutation of size n contains allppatterns of size up to Θ( n). It is also well-known that permutations ofpsize n cannot contain all patterns of size t for t = ω( n). It can also be
shown easily that the bitwise reversal sequence studied in § 2.6 containsp
all patterns of size up to Θ( n) (see Theorem 4.3). These observations
are consistent with the fact that random permutations, resp. the bitwise
reversal sequence, have high cost in the BST model. There are, however,p
permutations of size n that contain all patterns of size up to Θ( n), yethave linear cost in the BST model. We illustrate such a permutation (the“tilted grid”) and its execution by Greedy in Figure 4.2. The claims about
the pattern-containment property and the linear cost (by Greedy) of thisFigure 4.2: Tilted grid permufamily of permutations can be verified by visual inspection, we therefore
tation of size n = 25. It contains all patterns of size up to omit the formal proofs.
pBased on the above discussion we conclude that pattern-avoidanceΘ( n), and is served with linisasufficient condition for the “easiness” of a sequence, but it is not aear cost by Greedy.
full characterization. In § 4.8 we discuss the relation between patternavoidance and other structural properties of sequences.
Theorem 4.3. The bitwise reversal sequence R n ∈ S n contains every permutation of size t ,pfor some t = Ω( n).

78

Chapter 4. Pattern-avoiding access

Proof. Suppose n = 22k , and let P = (p 0 , . . . , p 2k −1 ) ∈ S 2k an arbitrary permutation. Let (x)kdenote the value x in binary, padded to length k with zeros on the left. Let revk (x) be thebitwise reversal of (x)k and let (x.y) denote the bitwise concatenation of x and y.
Denote R n = (r 0 , . . . , r n−1 ), where r i = rev2k (i ). We show that R n contains P . Define the¢¡sequence y i = (i )k . revk (p i ) for i = 0, . . . , 2k − 1. Observe that y i is increasing, and with
distinct values between 0 and 22k − 1. Therefore, r y i is a subsequence of r n . Observe thatr y i = rev2k (y i ) = p i . revk (i ),which is order-isomorphic with P .
In the remainder of this section we define two broad families ofpattern-avoiding sequences.
W
We call a permutation X = (x 1 , . . . , x n ) ∈ S n a -type permutation, if
for all i it holds that x i = max{x 1 , . . . , x i } or x i = min{x 1 , . . . , x i }. In words,
W
every entry in a -type permutation is either larger or smaller than all
previous entries. See Figure 4.3 for an illustration.
W
VW
A -type permutation is a permutation whose reverse is a -type Figure 4.3: Example -type
permutation
permutation. (By the reverse of a permutation π ∈ S n we mean the perX = (5, 6, 4, 3, 7, 8, 9, 2, 1, 10).
mutation (πn , . . . , π1 ).) It is easy to verify that the monotone sequencesWV(1, . . . , n) and (n, . . . , 1) are permutations of both - and -type.
W
In the literature, -type permutations have been studied in various contexts, and arealso known as Gilbreath permutations (or Gilbreath shuffles). Diaconis and Graham [35,§ 5] give several characterizations for them, of which we mention two. We also state twoother characterizations. Verifying the equivalences between the definitions is left as an easy
exercise.

Lemma 4.4. Let X = (x 1 , . . . , x n ) ∈ S n . The following are equivalent.
(i) X is aW-type permutation,(ii) [35] for all j , the values in {x 1 , . . . , x j } are consecutive,(iii) [35] for all j , the values in {x 1 , . . . , x j } are distinct modulo j ,(iv) X avoids both 132 and 312,(v) X is the reverse of a preorder-sequence of a path (i.e. a BST where every non-leaf node
has exactly one child).
W
V
The number of -type (as well as the number of -type) permutations of size n is 2n−1 .
W
To see this, observe that a -type permutation is uniquely encoded by a binary string inwhich the i th digit tells us whether the (i + 1)th entry of the permutation is a maximum
or a minimum of the entries so far. The value of the first entry is uniquely determined by
the number of minima and maxima in the permutation (i.e. the number of 0s and 1s in theencoding).
W
V
Permutations of - and -type have rather simple structure. We use them next to definea more intricate family of permutations.
WW
We call X ∈ S n a k -avoiding permutation, if there is an arbitrary -type permutationV
π ∈ S k such that X is π-avoiding. We define k -avoiding permutations analogously.

4.1. Sequences and patterns

79

As a simple example, observe that preorder sequences are 231-avoiding, and thus theyW
are 3 -avoiding. As another example consider (23 . . . k1)-avoding permutations, which havebeen studied in the context of sorting with multiple stacks (see e.g. [17]). Since (23 . . . k1) is aW
W
-type permutation of size k, a permutation that avoids it is k -avoiding.
As an even simpler example consider (12 . . . k)-avoiding and (k . . . 1)-avoiding permutations, which we call (k − 1)-decreasing, respectively (k − 1)-increasing. As a very special case,S = (1, 2, . . . , n) is 1-increasing. By the previous discussion, a (k − 1)-increasing or (k − 1)WV
decreasing permutation is both k -avoiding and k -avoiding.
The following lemma states the folklore result that k-increasing and k-decreasing permutations have a natural decomposition. We state this observation only for the increasing case,as the other one is symmetric.
Lemma 4.5. Let X = (x 1 , . . . , x n ) ∈ S n . The following are equivalent:(i) X is (k . . . 1)-avoiding,(ii) X can be partitioned into pairwise disjoint increasing subsequences Y1 , Y2 , . . . , Yk−1 .
Proof. (ii) =⇒ (i):Let Y1 , . . . , Yk−1 be pairwise disjoint, increasing subsequences of X , and suppose there exists
a subsequence X 0 of length k of X , order-isomorphic to the pattern (k . . . 1). Since X 0 is
decreasing, no two elements of X 0 can be in the same subsequence Yi . This is a contradiction,
since we have only k − 1 subsequences Yi . Therefore, such an X 0 cannot exist, and X is
(k . . . 1)-avoiding.
(i) =⇒ (ii):Assume that X is (k . . . 1)-avoiding. We construct the decomposition of X into increasing
subsequences Y1 , . . . , Yk−1 as follows. To simplify the argument, we refer to X simultaneously©
ªas a set of points (x i , i ) . Let Y1 be the “wing”, i.e. the points of X that form an empty
rectangle with the top left corner (0, n + 1). (By this definition, we have x 1 ∈ Y1 .) Clearly, Y1
forms an increasing subsequence of X . We remove the elements of Y1 from X and similarlyfind Y2 as the wing of the remaining points. We repeat the process, thereby finding Y1 , Y2 , . . . .
We claim that we run out of points before reaching Yk , thus constructing a decomposition of
X as required.
Suppose otherwise that we have reached Yk , and consider an arbitrary point x i k ∈ Yk .
Since x i k was not chosen in Yk−1 , the rectangle with corners (x i k , i k ) and the top-left corner(0, n + 1) contains some point from Yk−1 . Pick such a point, and denote it x i k−1 . Observe thatx i k−1 < x i k , and i k−1 > i k . Since x i k−1 was not chosen in Yk−2 , we can similarly pick a suitablex i k−2 in Yk−2 . Continuing in this fashion, we construct the subsequence (x i 1 , ..., x i k ) of X that
forms the forbidden pattern (k . . . 1), a contradiction.
A natural generalization of k-increasing, respectively k-decreasing permutations are
k-monotone permutations, i.e. those that can be decomposed into k disjoint monotone
subsequences (increasing and decreasing subsequences arbitrarily mixed). Such permutations have been studied in the context of sorting (e.g. [66, 11]) and have been called “shuffledmonotone sequences”. The family of k-monotone permutations seems not to have a simple
avoided-pattern characterization, and such permutations are, in fact, NP-hard to recognize [65].
WW
We have seen that -type and -avoiding permutations generalize sequential and traversal (a.k.a. preorder) sequences. Next we generalize these sequences in a different way, anddescribe yet another decomposition of permutations.

80

Chapter 4. Pattern-avoiding access

Given a permutation X = (x 1 , . . . , x n ) ∈ S n we call an interval [a, b] ⊆ [n] a block of X , if,
for some c we have©
ª ©
ªx a , x a+1 , . . . , x b = c, c + 1, . . . , c + b − a .
In words, a block is a contiguous interval that is mapped to a contiguous interval.
Observe, that every permutation trivially has a block of size n, and n blocks of size 1.
A permutation X ∈ S n is decomposable if it has a block of size strictly betweeen 1 and n.
Otherwise, we say that it is simple. See Figure 4.4 for an illustration. (We refer to Brignall [21]for a survey of this well-studied concept. The decomposition described here also appears in
the literature as substitution-decomposition.)
3142
1

12

21 12

1 21 1 1 1 1
1 1

Figure 4.4: (left) Permutation (6, 1, 3, 2, 8, 7, 4, 5) and its block-decomposition
tree. Permutation (3142) at the root is obtained by contracting the four top
level blocks into points. (right) Simple permutation (6, 1, 8, 4, 2, 7, 3, 5).

We say that X is decomposable into k blocks if there exist disjoint [a 1 , b 1 ], . . . , [a k , b k ]Ssuch that each [a i , b i ] is a block of X and i [a i , b i ] = [n]. To each block [a i , b i ] we associate©
ªa permutation that is order-isomorphic to the sequence of entries x ai , x ai +1 , . . . , x bi in theblock. We call X recursively d -decomposable, if it is decomposable into at most d blocks,
such that the permutations associated to the blocks are either of length one or themselvesrecursively d -decomposable. For simplicity, we drop the term “recursive” and refer to such
permutations simply as d -decomposable.
The process of recursively decomposing a permutation gives rise to a block-decomposition
tree, illustrated in Figure 4.4. The nodes of the block-decomposition tree are permutations(of size at most d ) that describe the relative positions of the blocks at the same level. Moreprecisely such a permutation is order-isomorphic to the sequence formed by taking an arbitrary representative element from each block of a decomposition, e.g. in the above example¡¢
we may take the sequence x a1 , x a2 , . . . , x ak .
Let us observe that preorder sequences are 2-decomposable. This
V
W
will imply that - and -type sequences are also 2-decomposable, since
the first is a preorder sequence of a special tree (Lemma 4.4), and the second is the reverse of the first (reversing a permutation clearly preserves
its block-decomposition).
Given a preorder sequence X = (x 1 , . . . , x n ), let k be the maximum
index such that x 2 , . . . , x k are all smaller than x 1 . Since x 2 , . . . , x k are thenodes in the left subtree of x 1 in an underlying BST over [n], we have©
ª ©
ªFigure 4.5: Preorder sequencex 1 , . . . , x k = 1, . . . , x 1 . By a similar argument for the right subtree of©
ª ©
ªwith left (right) subtree of root
x 1 , we have x k+1 , . . . , x n = x 1 + 1, . . . , n . Thus we obtain two blocks ofa highlighted as L (R). ObX , and we can continue the same process recursively. See Figure 4.5 for serve that point a together
illustration.
with L can form a single block.
The entire family of 2-decomposable permutations is known as separable permutations. Separable permutations are well-studied in the literature (see e.g. [19]).
They have a number of equivelent characterizations, for instance, they are exactly the permutations avoiding both 2413 and 3142 (which are the only simple permutations of size 4). The4.1. Sequences and patterns

81

number of separable permutations of length n is the nth Schröder number [107, 94].
The following statement relates pattern-avoidance and decomposability of permutations.
Lemma 4.6. Let P ∈ S n , and let k be an integer. The following are equivalent.
(i) P is k-decomposable,(ii) P avoids all simple permutations of size at least k + 1,(iii) P avoids all simple permutations of size k + 1 and k + 2.
Proof. (ii) =⇒ (iii) is obvious.
(iii) =⇒ (ii) follows from the result of Schmerl and Trotter [86] that every simple permutation of length n contains a simple permutation of length n − 1 or n − 2, and the simple
observation that if P avoids Q, then P also avoids all permutations containing Q.
(ii) =⇒ (i) follows from the observation that a permutation P contains all permutations associated to nodes of its block-decomposition tree. Further, it is known [21] thatevery permutation P has a block-decomposition tree T in which all nodes are simple permutations. If P contains no simple permutation of size k + 1 or more, it must have a blockdecomposition tree in which all nodes are simple permutations of size at most k, it is therefore,k-decomposable.
(i) =⇒ (ii): we show the contrapositive ¬(ii) =⇒ ¬(i). Indeed, if P contains a simple
permutation Q of size at least k + 1, then any k-decomposition of P would induce a kdecomposition of Q, contradicting the fact that Q is simple.
Since there are no simple permutations of size 3, from Lemma 4.6 it follows that 3decomposable permutations are exactly the same as 2-decomposable (i.e. separable) permutations.
W
We remark that the k -avoiding and the k-decomposable properties capture very different aspects of permutations. It is easy to construct permutations of length n that areW
2-decomposable but not k -avoiding for any k = o(n), as well as permutations that are
2-increasing, but simple (i.e. not k-decomposable for any k < n). We omit the details.
In closing, we revisit Lemma 4.5 that characterizes permutations that are decomposable
into a small number of increasing (or decreasing) subsequences. Can we say something
about permutations that are decomposable into subsequences of a more general type?
Before making an observation in this direction, let us define the tensor product between two
permutations as follows.
Given X = (x 1 , . . . , x n ) ∈ S n and P = (p 1 , . . . , p k ) ∈ S k , we denote as
Y = X ⊗ P the permutation Y of size n · k, order-isomorphic with¡
Y 0 = x1 · k + p 1 , x1 · k + p 2 , . . . , x1 · k + p k ,x2 · k + p 1 , . . . , x2 · k + p k ,...,Figure 4.6: Tensor product.
(21) ⊗ (123) = (456123)¢
xn · k + p 1 , . . . , xn · k + p k .

In words, we obtain X ⊗P by replacing every entry of X with a block that contains a sequenceorder-isomorphic to P . See Figure 4.6 for illustration.

82

Chapter 4. Pattern-avoiding access

Lemma 4.7. Suppose X ∈ S n can be partitioned into pairwise disjoint subsequences (notnecessarily contiguous) Y1 , . . . , Yk , such that for all i , the sequence Yi is πi -avoiding, for somepattern πi . Then X avoids π1 ⊗ π2 ⊗ · · · ⊗ πk .
Proof. We prove the following claim from which the original statement follows by induction.
If X can be partitioned into disjoint subsequences A and B , such that A is π0 -avoiding and B
is π00 -avoiding, then X is π0 ⊗ π00 -avoiding.
If π0 ⊗ π00 is longer than X , then we are done. Suppose otherwise, that X contains a
subsequence P isomorphic to π0 ⊗ π00 . Partition P into subsequences P 1 , P 2 , . . . , each orderisomorphic to π00 . Notice that A must contain an entry from each P i , otherwise B would
contain a subsequence isomorphic to π00 . By the definition of “⊗”, these entries form asubsequence isomorphic to π0 , contradicting that A is π0 -avoiding.

4.2 Tools
4.2.1 Hidden elements
In the remainder of this chapter we analyze OPT(X ) for sequences X that avoid some pattern.
We mostly do this by analyzing costGG (X ), the cost of GeometricGreedy on X . Recall thatgiven a point set X , GeometricGreedy outputs a set Y ⊇ X that contains no unsatisfied pairsof points. We also analyze Greedy and Greedy , whose outputs are, in general, not satisfied
supersets, but nevertheless, closely related to OPT. (See § 2.7 for definitions.)
Recall that the cost of these algorithms is the cardinality of their
output. When we argue about the output of Greedy, Greedy andGreedy , a useful property that is often used is that certain elementsa ∈ [n] become “hidden” during the execution, with respect to someinterval of [n]. This means that as long as no key is accessed in thehidden interval of a, node a is not touched. (In geometric view
this means that no point with x-coordinate equal to a is output.)In the following we describe this concept more formally and list Figure 4.7: Hidden element in gesome cases when elements become hidden during the execution ometric view. After time t , eleof Greedy, Greedy and Greedy . See Figure 4.7 for an illustration. ment x ∈ [n] is hidden in (w, n] forConsider an arbitrary algorithm A that processes a point set Greedy, and0 in (w, x] for Greedy .
After time t , element x is hidden
X ⊆ [n]×[m], and outputs a point set Y ⊇ X , such that Y ⊆ [n]×[m].
in (w, y) for Greedy: Any access outCall points in X access points, and let us say that x is touched by A
side of (w, y) will not touch x.
at time t , if (x, t ) ∈ Y .
Definition 4.8. For an algorithm A, an element x ∈ [n] is hidden in the interval [w, y] ⊆ [n]after t , if, given that there is no access point p ∈ [w, y] × (t , t 0 ] for some t 0 > t , then x will not
be touched by A at any time in the interval (t , t 0 ].
In the following, we denote by τ(x, t ) the last time at or before t when x is touched, i.e.
©
ªτ(x, t ) = max q : q ≤ t and (x, q) ∈ Y .

Lemma 4.9. Let X ⊆ [n] × [m], and let x ∈ [n] be some element.
(i) If there is an element w < x where τ(w, t ) ≥ τ(x, t ), then x is hidden in (w, n] and (w, x]
after t for Greedy and Greedy respectively.
(ii) If there is an element y > x where τ(y, t ) ≥ τ(x, t ), then x is hidden in [1, y) and [x, y)
after t for Greedy and Greedy respectively.
(iii) If there are elements w, y where w < x < y, and τ(w, t ), τ(y, t ) ≥ τ(x, t ), then x is hiddenin (w, y) after t for Greedy.

4.2. Tools

83

Proof. (i) Consider any t 0 > t . For the case of Greedy, assume that there is no access pointin (w, n] × (t , t 0 ]. Suppose x is touched in the time interval (t , t 0 ], and let (p, t p ) be thefirst access point in this time interval that causes the touching of x. Then p ∈ [1, w], andt p ∈ (t , t 0 ]. As x is not touched in the time interval (t , t p ) by the choice of p, we havethat τ(x, t p − 1) = τ(x, t ). If τ(w, t ) ≥ τ(x, t ), then the rectangle with corners (p, t p ), and(x, τ(x, t p − 1)) contains the point (w, τ(w, t )), and thus it is satisfied before accessing p.
Therefore, the accessing of p via Greedy does not touch x, a contradiction. It follows
that x is hidden in (w, n] for Greedy after t .
For the case of Greedy , assume that there is no access point in (w, x] × (t , t 0 ]. Suppose
x is touched in the time interval (t , t 0 ], and let (p, t p ) be the first access point in thistime interval that causes the touching of x. Then p ∈ [1, w], and t p ∈ (t , t 0 ]. (The casep ∈ (x, n] is not possible for Greedy , since p < x must hold.) The remainder of theargument is the same as for Greedy.
(ii) The argument is analogous to (i).
(iii) Consider any t 0 > t . Assume that there is no access point in (w, y) × (t , t 0 ]. Suppose x is
touched in the time interval (t , t 0 ], and let (p, t p ) be the first access point in this timeinterval that causes the touching of x. There are two cases. If p ∈ [1, w], we use theargument of (i). If p ∈ [y, n], we use the argument of (ii).

4.2.2 Forbidden submatrix theory
Suppose that X ⊆ [n] × [n] and P ⊆ [k] × [k] are sets of planar points with integer coordinates,
and X is P -avoiding. How many points can X maximally contain? Forbidden submatrix
theory studies questions of this type, usually formulated in the language of 0/1-matrices, orin terms of subgraphs of bipartite graphs, instead of planar point sets. The cardinality of X
is clearly at most n · m, but depending on the structure of P , in many cases, much stronger
bounds can be shown.
Perhaps the first question of this kind was the 1951 problem of Zarankiewicz, which asks
for the cardinality of X in the case where the avoided pattern P is an a-by-b “rectangular
block” of points. (Alternatively, we can ask for the maximum number of edges in a bipartite
graph that avoids a certain bipartite subgraph.) Many variants and generalizations of thisproblem have been studied, we refer to Füredi [44], and Bienstock and Győri [15]. (Problemsof a similar flavour have been asked even earlier in graph theory, going back to the theoremof Mantel from 1907, concerning the maximum number of edges in triangle-free graphs.)
In its most general form, the problem of Zarankiewicz is not fully resolved, but for many
special cases tight or almost tight bounds are known. We give a simple proof for the basic
a = b = 2 case.
©
ªLemma 4.10. Let X ⊆ [n] × [n], and P = (0, 0), (0, 1), (1, 0), (1, 1) . If X avoids P , then |X | =p
Θ(n n).
Proof. Let Φi denote the number of unordered pairs x, y ∈ [n] such that for some j ≤ i we
¡ ¢have (x, j ), (y, j ) ∈ X . Clearly, for all i we have Φi ≤ n2 , and we set Φ0 = 0. Let n k denote the¡ ¢number of points in X with y-coordinate k. We claim that Φk − Φk−1 = n2k for all k. This is¡ ¢because none of the n2k pairs with y-coordinate k can appear with y-coordinate less than
¡ ¢
¡ ¢
P
k, since this would create the forbidden pattern P . We have thus n2 ≥ Φn − Φ0 = nk=1 n2k .
¡ ¢ ¡ ¢
P
By convexity, the quantity |X | = k n k is maximized if the n k s are equal, and n2k = n2 /n. Itppfollows that n k ≤ n + 1, and |X | = O(n n). A simple construction shows that this bound isasymptotically tight.

84

Chapter 4. Pattern-avoiding access

We state further results from the literature that we use in the remainder of the chapter.
For details and proofs of these statements (in the language of 0/1-matrices), we refer toFüredi, Hajnal [45, Cor. 2.7], Marcus, Tardos [70], Fox [41], Nivasch [78], and Pettie [81]. We
call a point set X ⊂ [n] × [n] a permutation point set, if there is exactly one point on every
horizontal or vertical line with integer coordinates. Relaxing this condition slightly, we call apoint set light if it has a single point on every vertical line, but possibly multiple points on
horizontal lines.
Lemma 4.11. Let X ⊆ [n] × [n] and P ⊆ [k] × [k] such that X avoids P .
³• ´• , then |X | ≤ 4n.
(i) [45, Cor. 2.7] If P =•(ii) [70, 41] If P is a permutation point set, then |X | ≤ n · 2O(k) .
(iii) [78, 81] If P is a light point set, then |X | ≤ n · 2α(n)

O(k)

.

Our use of this theory is inspired by work of Pettie [80, 82], who applied forbidden patterntechniques to prove bounds about data structures (in particular he reproves the sequential
access theorem for Splay, and proves that Splay achieves O(α∗ (n)) average cost per operation
on deque-sequences – sequences of insert and delete operations at minima and maxima
of the currently stored key-set). There are marked differences in our use of the techniques
compared with the work of Pettie. In particular, we look for patterns directly in the execution
trace of a BST algorithm, without any additional encoding step. It appears that the direct use
of forbidden submatrix techniques is particularly suited for the study of Greedy. Furthermore,
instead of using fixed forbidden patterns, we make use of patterns that depend on the input.
For further applications of the technique we refer to [23].

4.3 Sequential and traversal accessAs a warmup, in this section we present a direct proof for the linear costof Greedy on traversal sequences. The proof is a simple application of
the forbidden submatrix technique. For an alternative proof (not using
forbidden submatrices) we refer to [24, § A].
Theorem 4.12. Let X ∈ S n be a 231-avoiding permutation. Then thecost of GreedyFuture on X with the canonical initial tree is at most 4n.
³• ´• -avoiding.
Proof. We view X as a permutation point set. Then X is•
We study the output Y of GeometricGreedy on X with no initial tree,
which by Theorem 2.28 equals the execution trace³of GreedyFuture
on X
´
•

Figure 4.8: Proof of• -avoiding. Thenwith the canonical initial tree. We claim that Y is
Theorem 4.12.
•
by Lemma 4.11(i), we have |Y | ≤ 4n, and we are done.
Let T ³be the´ BST whose preorder sequence is X . Suppose for contradiction that Y•• , and thus there exist (a, t a ), (b, t b ), (c, t b ) ∈ Y , such that t a < t b < t c andcontains•
c < a < b. Observe that there exists an access point (d , t d ) ∈ X , such that d = a and t d ≤ t a , forotherwise a would not be touched at time t a by Greedy. (Possibly (a, t a ) itself is this accesspoint.) Since b is hidden in (a, n] after t a , for b to be touched at time t b , there must be anaccess point in (a, n] × (t a , t b ]. Let (e, t e ) be the lowest such access point in X (possibly (b, t b )itself). Let f be the first left ancestor of e in T , and suppose it is accessed at time t f (i.e.
( f , t f ) ∈ X ). (Observe that d ≤ f < e holds, since lca(d , e) is an ancestor of f , and also t f < t e .)Then, since f ∈ stair te (e) (since there is no touched or accessed point in ( f , e] × [1, t e )), we4.3. Sequential and traversal access85

have ( f , t e ) ∈ Y . But then, since c is hidden in [1, f ) after t e , for c to be touched at timet c , there must be an access point in [1, f ) × (t e , t c ]. Let (g , t g ) ∈ X be such an access point(possibly (c, t c ) itself is this point). We have ( f , t f ), (e, t e ), (g , t g ) ∈ X order-isomorphic to³• ´• , contradicting that X is 231-avoiding. (See Figure 4.8.)•

A corollary of Theorem 4.12 (using the equivalences discussed in§ 2.7.1) is that the cost of the online BST algorithm OnlineGreedy witha fixed initial tree (or alternatively, with an initial preprocessing that is
independent of the access sequence) is O(n).
Curiously, for GeometricGreedy in the case of an access sequence
X that is the preorder sequence of a tree T , having no initial tree ingeometric view has the exact same effect as having T as an initial tree.
(We refer to Theorem 2.29 and Figure 2.11 in § 2.7.1 for discussion of
initial trees in geometric view.) The claim follows from the observationthat the the canonical tree of GreedyFuture is in this case exactly the tree
Figure 4.9: Counterexample T that generates the sequence X . (We refer to 2.5.3 for the definition of
to naïve approach. Input
the canonical tree.)X = (4, 5, 6, 1, 2, 3) avoids (321),
Looking at the proof of Theorem 4.12 it is tempting to conjecture
but output contains (321).
that if X avoids P , then the GeometricGreedy
output avoids P , as we³´
have seen in the proof of Theorem 4.12 for the case P =

•

•

• .

Unfortunately, in general, this is not true. Figure 4.9 shows the counterexample P =

³•

•

´
•

.

Since traversal sequences of length n include (1, . . . , n) as a specialcase, Theorem 4.12 also implies the linear cost of Greedy for sequential
access. However, in the case of sequential access we can strengthen
the result to hold with arbitrary initial tree.
Theorem 4.13. Let X = (1, . . . , n). Then the cost of GreedyFuture on X
with arbitrary initial tree is at most 5n.
Proof. We split the output Y ∈ [n] × [n] into two parts: The points
strictly above the diagonal between (1, 1) and (n, n) and the points
at or below the diagonal. All access points are on the diagonal. By asimple inspection of the Greedy execution on X it is clear that above
the diagonal there are exactly n − 1 points in Y . (See ³Figure´ 4.10.) We•• , and thus,
argue that the points at or below the diagonal avoid•
by Lemma 4.11(i), their number is at most 4n.
Suppose there are (a, t a ), (b, t b ), (c, t b ) ∈ Y , at or below the diagonal,
such that t a < t b < t c and c < a < b. If (a, t b ) or (b, t b ) were accesspoints, then (c, t c ) would have to be above the diagonal to form the pattern. Therefore,
assume that (a, t b ), (b, t b ) ∈ Y \ X . Observe that b is hidden after t a in interval (a, n], therefore
if b is touched at time t b , then there must be an access point in (a, n]×(t a , t b ]. But then, (c, t c )is strictly above the diagonal, a contradiction.

Figure 4.10: Proof of
Theorem 4.13. Initial tree shown
below line.

W
The argument in Theorem 4.13 can be extended without much effort to -type permutaVtions (with initial tree). Surprisingly, showing the same for -type permutations seems much
more difficult. Observe that by Lemma 4.4 this is a very special case of the question whether
Greedy satisfies the traversal access condition with an arbitrary initial tree (see Problem 22,
and the discussion in [24]).

86

Chapter 4. Pattern-avoiding access

Problem 45. Is the cost of Greedy, Splay, or some other online BST algorithm O(n) on allV-type permutations of size n with every initial tree?

4.4 The main result for Greedy
In this section we show the following result.
Theorem 4.14. The cost of Greedy with arbitrary initial tree, for every access sequence X ∈ S nO(k)that avoids an arbitrary pattern π ∈ S k is n · 2α(n) .
The result implies that Greedy with arbitrary initial tree has cost n ·2α(n) for all traversal
sequences of length n, almost matching the conjectured linear bound.
It remains open whether the bound in Theorem 4.14 can be strengthened. We conjecturethat it can be improved to a linear bound (Problem 44). Nonetheless, the existing bound isalready stronger than what is known for other online BST algorithms such as Splay. We ask
therefore the following open question.
O(1)Problem 46. Find an upper bound on the cost of Splay for every access sequence X ∈ S n thatavoids an arbitrary pattern π ∈ S k .
Before proving Theorem 4.14 we introduce a number of simple concepts.
Let Y ⊆ [n] × [m] be a set of points that contains a point set P ⊆ [k] × [k]. A box is a set oftype [a, b] × [c, d ]. We call a box B a bounding box of P in Y if Y ∩ B contains P , but Y ∩ B 0
avoids P for all boxes B 0 ⊂ B . Observe that the bounding box of P in Y is not necessarily
unique.
We consider arbitrary geometric algorithms that read an input point set X ⊆ [n] × [m]and output a point set Y ⊆ [n] × [m] such that Y ⊇ X . We say that an algorithm A is inputrevealing if, for some constant k there is a point set G ⊆ [k] × [k] such that whenever Y
contains G, every bounding box B of G in Y contains at least one point of X . When such a G
exists for an algorithm, we say that G is an input-revealing gadget.
We extend now the tensor product notation described earlier to arbitrary point sets.
Given a point set Y ⊆ [n] × [m], we can associate to it a 0/1-matrix M Y in the obvious way:
M Y (i , j ) = 1 if (i , j ) ∈ Y and 0 otherwise. The mapping is clearly bijective, so we will refer to apoint set and its associated matrix interchangeably.
The tensor product between two 0/1-matrices M and G, denoted M ⊗ G is obtained byreplacing every one-entry of M by a copy of G, and every zero-entry of M by an all-zero
matrix equal in size with G. The tensor product between two point sets Y and G, denoted
Y ⊗G is the point set corresponding to the matrix M Y ⊗G Y .
The following simple observation is the key ingredient of the result.
Lemma 4.15. Suppose algorithm A produces output Y from input X . If G is an inputrevealing gadget for A and X avoids P , then Y avoids P ⊗G.
Proof. Suppose Y contains P ⊗ G, and consider a point set PG ⊆ Y that is order-isomorphic
to P ⊗ G. Consider all bounding boxes B 1 , B 2 , . . . of G in PG. By the definition of the input¢
S ¡revealing gadget, each B i contains a point of X . Denote X 0 = i B i ∩ X . Clearly X 0 ⊆ X , andX 0 contains P , therefore X contains P , a contradiction. (See Figure 4.11.)

4.4. The main result for Greedy

87

The following property of Greedy holds.
Lemma 4.16. G = ( • • • ) is an input-revealing gadget for Greedy with
arbitrary initial tree.
Proof. Let Y be the output of Greedy for input X , and let(a, t a ), (b, t b ), (c, t c ) ∈ Y order-isomorphic to G, such that a < b < c.
Let B be the box with corners (a, t a ), (c, t b ). As τ(a, t a ), τ(c, t a ) ≥τ(b, t a ), element b is hidden in (a, c) after t a . If there is no accessFigure 4.11: Proof of Lemma 4.15 point in B , then (b, t b ) cannot be touched, a contradiction. (SeeandOutput Y contains Figure 4.11.)³ • ´4.16.
¡ • ¢
¡ • ¢
⊗ • • , where • • is an
input-revealing gadget,³ therefore´••

input X contains•

We are ready to prove the main theorem.

• .

Proof of Theorem 4.14. Observe that for the gadget G of Lemma 4.16,
if P is a permutation point set of size k, then P ⊗G is a light point setof size 3k. By Lemma 4.15 and 4.16 the output of Greedy for X avoids P ⊗G. An applicationof Lemma 4.11(iii) finishes the proof.
•

To improve the bound of Theorem 4.14 from quasilinear to linear, it would be sufficient
to find an input-revealing gadget G that is a permutation point set. (Since, in that case, forpermutation point set P , the point set P ⊗G would also be a permutation point set, and thestronger bound of Lemma 4.11(ii) could be applied.) Unfortunately, as a construction of
Thatchaphol Saranurak shows, such a gadget does not exist for Greedy with some initial tree.
We refer to [24, § G] for details.

4.4.1 An aside: adaptive sorting
One of the very few algorithmic problems that has been studied even more extensively thanthe BST problem is sorting. It is well-known that in the comparison-only model, sorting asequence of n elements requires Ω(n log n) comparisons in the worst case. Furthermore, thisbound is matched by several classical algorithms such as Mergesort, Heapsort, or Quicksort(with proper choice of pivot) [30], [71, § 2].
Given the importance of sorting, significant effort was spent on studying the performanceof algorithms on input sequences with a certain amount of pre-sortedness, in which case it
is possible to beat the Θ(n log n) barrier. Various kinds of structures have been proposed tocapture pre-sortedness, some of them similar to the BST structures studied in § 2.4. This
broad area of research has been called adaptive sorting. As an entry point to the vast literature
on adaptive sorting, we refer to [77, 39, 66, 69, 75, 11], [60, § 5.3], and references therein.
A remark is in order. Adaptive sorting feels similar to the study of OPT in the BST problem. However, in the case of sorting, true instance-optimality, in a sense similar to dynamic
optimality in the BST model, is ill-defined. This is because for every particular sequence X ,there is a sorting algorithm tailored to X , that can sort it in linear time (by simply verifyingthat the input is indeed in the same order as X , and then putting it in the correct order). In
fact, a stronger result of Fredman [43] shows that if the input permutation is drawn froman arbitrary subset of S n , then it can be sorted using a number of comparisons essentiallymatching the information-theoretic lower bound. However, the result of Fredman does notinclude the work spent outside of the comparison-model, and since his algorithm explicitly
maintains a distribution over the permutations, it is highly impractical.

88

Chapter 4. Pattern-avoiding accessIn light of these, adaptive sorting for restricted families of inputs is still an interesting,and practically relevant problem. In the spirit of this chapter, we ask the following question:
Problem 47. Is there a sorting algorithm that can sort in linear time every permutation thatavoids an arbitrary fixed pattern?
By Theorem 4.2, such an algorithm can exist, in fact, if we only care for the number ofcomparisons, the result of Fredman mentioned before answers this question. However, we
would like an algorithm that is practical, has low overall cost on pattern-avoiding input, anddegrades gracefully on arbitrary input, i.e. it is a good general-purpose sorting algorithm.
This question was also asked by Arthur [9] in 2007, who gave an adaptive sorting algorithmwith running time O(n log log log n) for inputs with certain special avoided patterns.
We observe that the main result of this chapter (Theorem 4.14) addresses Problem 47 andimproves the known adaptive sorting results in several ways. Given a BST algorithm that
supports insertions, we can sort a sequence X by inserting its entries into an initially empty
BST, and reading them out in order in the end. The cost of sorting equals (asymptotically)
the total cost of inserts in the BST model. (In fact, if we only care about the number ofcomparisons, then the cost of sorting seems closely related to the “search-only cost” in themodel of Blum et al., § 2.3, since re-arranging the tree is free.) This idea is, of course, notnew, but simply a description of the classical Insertion-sort algorithm, with a particular data
structure for storing the already sorted elements.
We state without proof that the upper bounds on the cost of Greedy for an access sequence
X are also upper bounds on the cost of Greedy for an insertion sequence X . For details, werefer to [23]. In fact, the observation holds not just for Greedy, but for a broad class of BST
algorithms. (Using Splay instead of OnlineGreedy for sorting is likely a better idea in practice.)
These observations, together with Theorem 4.14 yield a sorting algorithm that can sortO(k)every permutation of size n with an avoided pattern of size k in time n · 2α(n) . Thisalgorithm, which we can call “Greedy-sort”, has several further attractive features:(i) It has worst-case O(n log n) running-time on arbitrary input of size n.
(ii) In contrast to other algorithms proposed in the literature, it does not need to know the
avoided pattern at runtime. Pattern-avoidance is only used in the analysis.
(iii) It is “insertion-sort-like”, i.e. entries of the input are read one by one, and at time i , weonly compare the i th entry with entries previously read.
(iv) It adapts to various other structures besides avoided patterns (like Greedy itself).
The connection to sorting adds another motivation for settling Problem 44. In fact,
settling Problem 47 may be easier, since we are free to use structures other than BSTs.

4.5

W-avoiding sequences

In the first part of this section we strengthen the result of Theorem 4.14 from quasilinear tolinear, in the special case when the access sequence X is k-increasing or k-decreasing, i.e. if¡¢ ¡¢it avoids (k + 1)k . . . 1 or 1 . . . k(k + 1) .
We show the following result.
Theorem 4.17. The cost of Greedy with arbitrary initial tree, for an access sequence X ∈ S n
¡
¢ ¡
¢
2
that avoids (k + 1)k . . . 1 or 1 . . . k(k + 1) is n · 2O(k ) .
The proof of Theorem 4.17 is similar to the proof of Theorem 4.14 but more involved.
As opposed to the earlier proof, in this case we can construct an input-revealing gadgetthat is a permutation point set. This gadget, however, is no longer a simple constant-sized

4.5.

W

-avoiding sequences

89

construction as in Lemma 4.16. Instead, it depends on the pattern that is avoided in theaccess sequence. We stress that the gadget is used only for the purpose of analysing the costof Greedy, the algorithm does not need to know this gadget (or the avoided pattern) during
its runtime.
¡¢¡¢
Lemma 4.18. Assuming that the access sequence X avoids 1 . . . k , respectively k . . . 1 , the¡¢¡¢permutation (k + 1)k . . . 1 , respectively 1 . . . k(k + 1) is an input-revealing gadget for Greedy
with arbitrary initial tree.
Proof. We prove the first case only, the other case is symmetric. Assume therefore that the¡¢access sequence X avoids 1 . . . k . Let Y be the output of Greedy on X , and suppose that Y¡¢
contains (k + 1)k . . . 1 , and let B be a bounding box of Q in Y . Let Q = (q 0 , q 1 , q 2 , . . . , q k ) be¡¢
the x-coordinates of the points in Y ∩ B that form (k + 1)k . . . 1 , and let t 0 , t 1 , . . . , t k be theirrespective y-coordinates (“times”). We have q 0 > q 1 > · · · > q k and t 0 < t 1 < · · · < t k .
Note that for all 1 ≤ i ≤ k, we can assume that there is no point (q i , t i0 ) ∈ Y where t i −1 <0t i < t i , for otherwise we could choose (q i , t i0 ) instead of (q i , t i ). So, for any t ∈ [t i −1 , t i ) wehave that τ(q i −1 , t ) ≥ τ(q i , t ) for all 1 ≤ i ≤ k.
Suppose for contradiction that there is no access point from X in B . Let ` be the xcoordinate of the left margin of B .
By Lemma 4.9(ii), q 1 is hidden in [1, q 0 ) after t 0 . Hence, there must be an access point(p 1 , t p 1 ) ∈ [1, `) × (t 0 , t 1 ], otherwise (q 1 , t 1 ) would not be touched. We choose (p 1 , t p 1 ) such as
to maximize p 1 . If t p 1 < t 1 , then τ(p 1 , t p 1 ), τ(q 0 , t p 1 ) ≥ τ(q 1 , t p 1 ). So by Lemma 4.9(iii), q 1 is
hidden in (p 1 , q 0 ) after t p 1 and hence (q 1 , t 1 ) cannot be touched, a contradiction. Thus wehave t p 1 = t 1 and p 1 < `.
Next, we prove by induction for i = 2, . . . , k that given the access point (p i −1 , t p i −1 ) wheret p i −1 = t i −1 and p i −1 < `, there must be an access point (p i , t p i ) with t p i = t i and p i −1 < p i < `.
Again, by Lemma 4.9(iii), there must be an access point p i ∈ (p i −1 , q i −1 ) × (t i −1 , t i ], otherwise(q i , t i ) would not be touched. We choose the point (p i , t p i ) where p i is maximized. If t p i < t i ,then τ(p i , t p i ), τ(q i −1 , t p i ) ≥ τ(q i , t p i ). Hence by Lemma 4.9(iii), q i is hidden in (p i , q i −1 ) aftert p i and therefore (q i , t i ) cannot be touched. Thus, we have t p i = t i and p i −1 < p i < `. We get
the points (p i , t p i ) ∈ X , such that p 1 < · · · < p k < `, and t p 1 < · · · < t p k , which contradicts the¡¢assumption that X is 1 . . . k -avoiding and concludes the proof. (See Figure 4.12.)¡¢¡¢
Proof of Theorem 4.17. If X avoids P = (k + 1)k . . . 1 , respectively P = 1 . . . k(k + 1) , then¡¢¡¢G = 1 . . . (k+1)(k+2) , resp. G = (k+2)(k+1) . . . 1 is an input-revealing gadget by Lemma 4.18.
Observe that P ⊗ G is a permutation of size O(k 2 ). By Lemma 4.15 the output of Greedy for X
avoids P ⊗G. An application of Lemma 4.11(ii) finishes the proof.

Figure 4.12: Proof of Lemma 4.18.

We remark that recently a linear bound on OPT(X ) for
k-increasing (resp. k-decreasing) sequences was shown via
a different argument (with a better dependence on k). We
briefly sketch the argument (see [26] for details). In § 2.3 wementioned the extended BST model with multiple pointers.
In this model, using the decomposition of k-increasing andk-decreasing sequences (Lemma 4.5) we can serve suchsequences in linear time, even if the underlying tree is astatic path (each pointer serves one of the monotone subsequences). In fact, in this model we can serve in linear timeeven the more general family of k-monotone permutations(decomposable into intermixed increasing and decreasing
sequences). By the result of Demaine, Iacono, Langerman,

90

Chapter 4. Pattern-avoiding accessand Özkan [33], serving an access sequence in this powerful k-pointer model can be simulated in the BST model (with a single pointer and root access) at the cost of an O(k) factor
slowdown.
We ask whether the results on k-increasing and k-decreasing sequences can be extendedW
to k -free sequences. In § 4.7.2 we give some evidence that this may be possible, and wesuspect the question to be an accessible intermediate step towards Problem 44.
W
V
Problem 48. Is there some function f (·) such that for every k -avoiding or k -avoiding
sequence X ∈ S n , it holds that OPT(X ) ≤ n · f (k)? More strongly, can we bound the cost of
Splay or Greedy (with or without initial tree) for such inputs?

4.6 Block-decomposable sequences
In this section we strengthen the result of Theorem 4.14 from quasilinear to linear in anotherspecial case, namely for k-decomposable access sequences. We show the following result.
Theorem 4.19. The cost of Greedy with no initial tree, for an access sequence X ∈ S n that is2
k-decomposable is n · 2O(k ) .
The result implies another kind of “almost-traversal” result: it shows that OnlineGreedy
with a fixed initial tree has cost O(n) on an arbitrary traversal sequence of length n.
It is open whether the “no initial tree” condition of Theorem 4.19 (i.e. the reliance on
a fixed canonical initial tree) can be relaxed, and whether the result can be shown with
arbitrary initial tree. This is open even in very special cases of 2-decomposable sequences(Problems 22 and 45). We mention that Thatchaphol Saranurak has recently found a different argument for proving Theorem 4.19, using the Iacono-Langerman [54] result, with an
improved dependence on k [26].
The proof of Theorem 4.19 is similar to the proof of Theorem 4.17, but more involved: weconstruct an input-revealing gadget whose size depends, in this case, on the decomposition
parameter k. The gadget, denoted G k is defined as follows.
¡¢
Let G k = b(k + 1)/2c , k, 1, k − 1, 2, . . . . In words, G k consists of an initial “middle point”,
Vfollowed by a -type permutation alternating between left and right sides of the middle point.
For example,


•

•

 •
G7 = 
•

•
•

•


.

Lemma 4.20. Assuming that the access sequence X is k-decomposable, the permutation
G k+4 is an input-revealing gadget for Greedy with no initial tree.
Then, the result follows.
Proof of Theorem 4.19. If X is k-decomposable, then by Lemma 4.20 the output Y of Greedy
on X avoids P ⊗G k+4 , for all simple permutations P of size at least k + 1 (using Lemma 4.6).
Observe that P ⊗G is a permutation of size O(k 2 ). An application of Lemma 4.11(ii) finishes
the proof.
In the remainder of the section we prove Lemma 4.20. We first prove the following
technical lemma. Given a box B , we denote by B.ymin, B.ymax the y-coordinates of thelower, resp. upper margin of B , and by B.xmin, B.xmax the x-coordinates of the left, resp.
right margin of B .

4.6. Block-decomposable sequences

91

Lemma 4.21. Let Y be the output of Greedy with no initial tree on k-decomposable input X ,and let B be a bounding box of G k+1 in Y . If there is no access point p ∈ B , then there are kaccess points (p i , t i ), for 1 ≤ i ≤ k, such that B.ymin ≤ t 1 < · · · < t k ≤ B.ymax and B.xmax < p ifor all odd i and p i < B.xmin for all even i .
Proof. Let (q i , t i0 ) for 0 ≤ i ≤ k be points in Y such that t i0 < t i0 +1 for all i and such that the
points (q i , t i0 ) form G k+1 with bounding box B . Suppose that there is no access point in B .
We prove for i = 1, . . . , k, that there exists an access point (p i , t i ) ∈ (B.xmax, n] × (t i0 −1 , t i0 ]for odd i , and (p i , t i ) ∈ [1, B.xmin) × (t i0 −1 , t i0 ] for even i .
For odd i , by Lemma 4.9(i), q i is hidden in (q i −1 , n] after t i0 −1 . So there must be an accesspoint p i ∈ (B.xmax, n] × (t i0 −1 , t i0 ], otherwise q i cannot be touched.
For even i , by Lemma 4.9(ii), q i is hidden in [1, q i −1 ) after t i0 −1 . So there must be an accesspoint p i ∈ [1, B.xmin) × (t i0 −1 , t i0 ], otherwise q i cannot be touched.
Observe that (p i , t i ) for 1 ≤ i ≤ k satisfy B.ymin ≤ t 1 < · · · < t k ≤ B.ymax and B.xmax < p ifor all odd i and p i < B.xmin for all even i .
Let X be a k-decomposable permutation. Suppose that G k+4 appears in the output
Y of Greedy, with bounding box B . Suppose for contradiction that B contains no accesspoint. Then, by Lemma 4.21, there exist access points (p i , t i ) for 1 ≤ i ≤ k + 3, satisfying theconditions B.ymin ≤ t 1 < · · · < t k+3 ≤ B.ymax and B.xmax < p i for odd i and p i < B.xmin foreven i .
Let (q i , t i0 ) for 0 ≤ i ≤ k + 3 denote the points of Y that form G k+4 (where t 00 < t 10 < · · · <0t k+3), and let us denote P = {(p i , t i ) : 1 ≤ i ≤ k + 3}. Let T be a block decomposition tree of X
of arity at most k. We look at each block P ∈ T as a minimal rectangular region in the planethat contains all access points in the block.
Let P ∗ be the smallest block in T that contains two distinct access points (p i , t i ), (p j , t j ) ∈P such that i is odd, and j is even. (Observe that p i is to the right of B , and p j is to the left ofB .)Observe first that the bounding box of P ∗ must contain or intersect both vertical sidesof B , otherwise it could not contain points on both sides of B . Furthermore, the bottom
horizontal side of B must be contained entirely in the bounding box of P ∗ : If that were not thecase, then there would be no accesses below B , and (q 0 , t 00 ) (the lowest point of G k+4 ) would
not be touched by Greedy (since there is no initial tree). The following is the key observationof the proof.
Lemma 4.22. Let k 0 be the largest integer such that P ∗ contains (q i , t i0 ) for 0 ≤ i ≤ k 0 . Then,k 0 < k + 1. In words, P ∗ contains at most the k + 1 lowest points of G k+4 .
Proof. Let P 1 , . . . , P k be the decomposition of P ∗ into k blocks. We claim that each block P j
can contain at most one point from P . First, by the minimality of P ∗ , none of the blocks
P j can contain two access points from P from different sides of B . Furthermore, P j cannot
contain two points from P from the same side of B , because otherwise, assuming w.l.o.g. thatP j contains two points from P from the left of B , it would follow that there is another accesspoint (a, t ) ∈ P on the right side of B , outside of P j , such that (P j ).ymin < t < (P j ).ymax,
contradicting that P j is a block.
Furthermore, observe that except for the block containing (p 1 , t 1 ), none of the blocks P j
can overlap with B . Since we have at most k such blocks in the decomposition, and because0
t i0 ≥ t i for all i , it follows that the top margin of P ∗ must be below t k+1.
Since the bounding box of P ∗ contains (at best) the first k + 1 points of G k+4 , the threeremaining points of G k+4 need to be touched after the last access in P ∗ . In the following weshow that this is impossible.

92

Chapter 4. Pattern-avoiding accessLet (L, t L ) be the topmost access point inside P ∗ to the left of B , such that there is atouched point inside B at time t L . Let (R, t R ) be the topmost access point inside P ∗ to theright of B , such that there is a touched point inside B at time t R . Let L 0 be the rightmost key
inside B touched at time t L , and let R 0 be the leftmost key inside B touched at time of t R .
Lemma 4.23. After time t L , within the interval [B.xmin, L 0 ], only L 0 can be touched. Similarly,
after time t R , within the interval [R 0 , B.xmax], only R 0 can be touched.
Proof. Let L 00 be the rightmost touched key in [L, B.xmin) at time t L , and let R 00 be the leftmost
touched key in (B.xmax, R] at time t R .
We have that τ(L 00 , t L ), τ(L 0 , t L ) ≥ τ(x, t L ), for any x ∈ [B.xmin, L 0 ). Thus, any x ∈ [B.xmin, L 0 )is hidden in (L 00 , L 0 ) after t L .
Above P ∗ there can be no access to a key in [L 00 , L 0 ], since that would contradict the factthat P ∗ is a block. Within P ∗ after t L there can be no access to a key in (L 00 , B.xmin), as thefirst such access would necessarily cause the touching of a point inside B , a contradiction to
the choice of (L, t L ). An access within B is ruled out by our initial assumption.
Thus, there is no access in (L 00 , L 0 ) × (t L , n], and from Lemma 4.9(iii) it follows that anyx ∈ [B.xmin, L 0 ) can not be touched after time t L .
We argue similarly on the right side of B .
As a corollary of Lemma 4.23, note that above P ∗ only elements within [L 0 , R 0 ] can betouched within B . If L 0 = R 0 , then only one element can be touched, and we are done.
Therefore, we assume that L 0 is strictly to the left of R 0 .
We assume w.l.o.g. that t R > t L (the other case is symmetric). Let (Q, tQ ) be the first accesspoint left of B with tQ > t R such that there is a touched point inside B at time tQ . Observethat (Q, tQ ) is outside of P ∗ by our choice of (L, t L ). If no such Q exists, we are done, since wecontradict Lemma 4.21 about the structure of points forced by G k+4 .
Let (Z , t Z ) denote the last touched point with the property that Z ∈ [(P ∗ ).xmi n, L 0 ), andt Z ∈ [t L , tQ ). If there are more such points in the same row, pick Z to be the leftmost. Notethat (Z , t Z ) might coincide with (L, t L ). We have t Z ≤ t R because otherwise (Q, tQ ) cannot
exist. Note than t Z > t R would imply that keys in [L 0 , R 0 ] are hidden in (Z , R) after t R .
Next, we make some easy observations.
Lemma 4.24. The following boxes are empty in Y :1. [B.xmin, B.xmax] × [t R + 1, tQ − 1],
2. [1, Z − 1] × [t Z + 1, t R ],3. [Q, Z − 1] × [t Z + 1, tQ − 1],
4. [Q, R 0 − 1] × [t R + 1, tQ − 1].
Proof.

1. It is clear that there can be no access point inside B by assumption. Suppose
there is a touched point in [B.xmin, B.xmax] × [t R + 1, tQ − 1], and let (Q 0 , tQ 0 ) be thefirst (lowest) such point. Denote the access point at time tQ 0 as (Q 00 , tQ 0 ). Clearly tQ 0 >(P ∗ ).ymax must hold, otherwise the choice of (L, t L ) or (R, t R ) would be contradicted.
Also Q 00 > (P ∗ ).xmax must hold, otherwise the choice of (Q, tQ ) would be contradicted.
But this is impossible, since Q 0 ∈ [L 0 , R 0 ], and τ(Q 0 , tQ 0 − 1) ≤ t R , and thus the rectangle
with corners (Q 00 , tQ 0 ) and (Q 0 , τ(Q 0 , tQ 0 −1)) contains the touch point (R, t R ), contradicting the claim that Greedy touches Q 0 at time tQ 0 .

4.6. Block-decomposable sequences

93

2. All keys in [1, Z − 1] are hidden in [1, Z − 1] after t Z . There can be no access point on
the left of P ∗ , due to the structure of the block decomposition, and there is no accesspoint in [(P ∗ ).xmin, Z − 1] × [t Z + 1, tQ − 1] due to the choice of Z . Hence there cannot
be a touch point in [1, Z − 1] × [t Z + 1, t R ].
3. First there is no access point in [Q, Z − 1] × [t Z + 1, (P ∗ ).ymax] due to the choice of(Z , t Z ) and the structure of the block decomposition. Also, there is no access point in[Q, Z − 1] × ((P ∗ ).ymax, tQ − 1]: Assume there were such an access point (Q 0 , tQ 0 ). Thenit must be the case that Q < Q 0 < (P ∗ ).xmin and (P ∗ ).ymax < tQ 0 < tQ . Any rectangle
formed by (Q, tQ ) and a point in P ∗ ∩ B would have contained (Q 0 , tQ 0 ), a contradiction
to the fact that Greedy touches a point inside B at time tQ .
Next, we argue that there is no non-access touch point (a, t ) ∈ [Q, Z −1]×[t Z +1, tQ −1].
There are three cases.
– (a, t ) ∈ [(P ∗ ).xmin, Z − 1] × [t Z + 1, tQ − 1] contradicts the choice of (Z , t Z ).
– (a, t ) ∈ [Q, (P ∗ ).xmin) × [t Z + 1, (P ∗ ).ymax] contradicts the fact that all elements in[1, Z ) are hidden in [1, Z ) after t Z , and there is no access in [1, Z ) in the time interval[t Z + 1, (P ∗ ).ymax], since P ∗ is a block.
– (a, t ) ∈ [Q, (P ∗ ).xmin) × ((P ∗ ).ymax, tQ − 1], contradicts the claim that at time tQ
Greedy touches a point inside B , since any rectangle formed by (Q, tQ ) and a point
in P ∗ ∩ B would have contained (a, t ).
4. Given the previous claims, it remains only to prove that there is no touched point(a, t ) ∈ [Z , B.xmin) × t ∈ [t R + 1, tQ − 1]. There cannot be such a touched point fort ≤ (P ∗ ).ymax due to the choice of (Z , t Z ). For t > (P ∗ ).ymax, there cannot be souch
an access point due to the structure of the block decomposition. Remains the casewhen (a, t ) is a non-access touched point in [Z , B.xmin) × ((P ∗ ).ymax, tQ − 1. This isalso impossible, as any rectangle formed by (Q, tQ ) and a point in P ∗ ∩ B would havecontained (a, t ), contradicting the choice of (Q, tQ ).
Lemma 4.25. At time tQ we touch R 0 . Let L ∗ be the leftmost key touched in [L 0 , R 0 ] at time tQ(it is possible that L ∗ = R 0 ). After time tQ , only L ∗ and R 0 can be touched within [L 0 , R 0 ].
Proof. The first part follows from the emptiness of rectangles in Lemma 4.24. That is, thelemma implies that the rectangle formed by (Q, tQ ) and (R 0 , t R ) is empty, so Greedy touches
R 0 at time tQ .
The keys a ∈ (L ∗ , R 0 ) cannot be touched because they are hidden in (L ∗ , R 0 ) after tQ , andthere is no access point in this range after tQ , due to the structure of the block decomposition.
Suppose that some key a ∈ [L 0 , L ∗ ) is touched (for the first time) at some time t > tQ byaccessing element x. So the rectangle formed by (x, t ) and (a, τ(a, t − 1)) is empty, and weknow that τ(a, t − 1) < t R . Notice that x < (P ∗ ).xmin, for otherwise (R, t R ) would have been in
the rectangle formed by (x, t ) and (a, τ(a, t −1)), a contradiction. Furthermore, τ(a, t −1) > t Z ,for otherwise, (Z , t Z ) would have been in the rectangle formed by (x, t ) and (a, τ(a, t − 1)), a
contradiction. Now, since τ(a, t − 1) > t Z , Lemma 4.24 implies that the rectangle formed by(Q, tQ ) and (a, τ(a, t − 1)) must be empty, therefore a is touched at time tQ . This contradicts
the choice of L ∗ .
Lemma 4.22, 4.23, and 4.25 together imply that in total at best the k + 3 lowest points of
G k+4 can be touched (out of the k + 4 needed). This means that our assumption that B is freeof access points was false. Therefore G k+4 is an input-revealing gadget, finishing the proof of
Lemma 4.20. See Figure 4.13 for an illustration.

94

Chapter 4. Pattern-avoiding accessFigure 4.13: Proof of Lemma 4.20

4.7 Upper bounds on the lower bounds
4.7.1 Bound on MIR
In this section we show that the techniques developed in the previous sections can be used
to prove an upper bound on the quantity MIR(X ) for pattern-avoiding X . Recall from § 2.7.3
that MIR(X ) is the strongest known lower bound for OPT(X ), conjectured to asymptoticallymatch OPT(X ). We show that if X avoids an arbitrary fixed pattern, then MIR(X ) is linear.
The proof has the same structure as the earlier proofs, but the gadget is simpler.
Recall from § 2.7.3 that MIR(X ) equals (up to a constant factor) costG  (X ) + costG  (X ),where the two terms are the costs of the Greedy , respectively Greedy algorithms with input
X.
Greedy and Greedy turn out to be easier to analyze than Greedy. We show the following.
Theorem 4.26. The cost of Greedy , resp. Greedy with an arbitrary initial tree, for an accesssequence X ∈ S n that avoids an arbitrary pattern π ∈ S k is n · 2O(k) .
The same asymptotic upper bound on MIR(X ) follows immediately from Theorem 4.26.
We make use of the following observation.
Lemma 4.27. G  = ( • • ) is an input-revealing gadget for Greedy with arbitrary initial tree.
G  = ( • • ) is an input-revealing gadget for Greedy with arbitrary initial tree.
Proof. We prove the first claim only, the other is symmetric. Let Y be the output of Greedy
for input X , and let (a, t a ), (b, t b ) ∈ Y order-isomorphic to G  , such that a < b. Let B be thebox with corners (a, t a ), (b, t b ). As τ(a, t a ) ≥ τ(b, t a ), element b is hidden in (a, b] after t a . If
there is no access point in B , then (b, t b ) cannot be touched, a contradiction.
Proof of Theorem 4.26. Observe that π ⊗ G  and π ⊗ G  are permutations of size O(k), andby Lemma 4.27 they are avoided in the output of Greedy , resp. Greedy . An application ofLemma 4.11(ii) finishes the proof.

4.8. Comparisons with other bounds

95

4.7.2 Bound on Wilber’s boundIn this section we use a different argument to bound from above a lower bound on OPT(X ),in this case Wilber’s second lower bound W 2 (X ). More precisely, we show that if X ∈ S n
W
W
is k -avoiding, i.e. it avoids some -type permutation of size k, then W 2 (X ) = n · O(k).
¢¡Assuming that the conjectured W 2 (X ) = Θ OPT(X ) holds, we obtain that for all X thatW
avoid a constant-sized -type permutation, OPT(X ) is linear.
We use the definition of W 2 from Figure 2.7 in § 2.6.2. Consider the access sequence
X = (x 1 , . . . , x n ) ∈ S n . For a given entry x j , we define the offline stair off(xj ) as the subsequenceof entries x i for i < j such that x i and x j form an unsatisfied pair in X . The number ofalternations for x j , denoted n j is the number of consecutive entries in off(xj ) that are onPdifferent sides of x j . Recall that W 2 (X ) = n + i n i .
Theorem 4.28. If X ∈ S n is aW

k -avoiding permutation, then W

2(X ) = n · O(k).

Proof. By the above definition of W 2 (X ), we observe that if n i = t , for an arbitrary i , thenW
X contains an “alternating -type permutation” of size t , as a subsequence of off(xi ). By¡
W“alternating -type permutation” of size t we mean the permutation P t = dt /2e , dt /2e +¢1, dt /2e − 1, . . . . For instance,•
P7 = 

•

•

•

•
•

•


.

W
W
Observe that P 2k contains every -type permutation of size k. Therefore, if X is k avoiding, then n i < 2k, for all i , therefore W 2 (X ) = n · O(k).
V
For k -free permutations we can obtain the same bound for
Wilber’s second bound computed in reverse. If W 2 is, as conjectured,tight, then the forward and reverse variants are asymptotically equal.
It appears to be open however, how big the gap between the two W 2variants can be.
A similar argument can also be used to bound W 2 (X ) for someother types of sequences. We illustrate this with an example. Recall that 2-decomposable (a.k.a. separable) permutations are exactly
Figure 4.14: Proof of Lemma 4.29. those that avoid both 2413 and 3142. In § 4.6 we showed that thethatµ {x} ∪ off(x)contains cost of Greedy is linear for this type of access sequences. Now weµObserve
¶
• ¶
•
•
•
(highlighted). bound W 2 for the more general family of sequences that avoid at• and •••
least one of 2413 and 3142.

Theorem 4.29. Let X ∈ S n avoiding 2413 or 3142. Then W 2 (X ) ≤ n · O(1).
Proof. Consider the previous definition of W 2 and observe that if n i ≥ 5, then off(xi ) together
with x i contain both 2413 and 3142. The claim follows. (See Figure 4.14.)

4.8 Comparisons with other bounds
We argue that the bounds for pattern-avoiding sequences shown in this section are notsubsumed by previously known bounds (see e.g. § 2.4). We illustrate this by exhibiting two
sequences X 1 and X 2 , both of which have linear cost.
¡¢
The first example sequence is defined as X 1 = 1, n, 2, n − 1, . . . . It is easy to verify thatX 1 is 2-decomposable. Even more strongly, X 1 avoids 231 and 213. Therefore, the fact that
OPT(X ) ≤ n · O(1) follows from the results of this chapter. However, the dynamic finger

96

Chapter 4. Pattern-avoiding accessbound for X 1 is easily seen to be Ω(n log n). (Most consecutive entries have rank-differenceΩ(n).) This shows that, in general, the dynamic finger bound is not stronger than the patternavoiding bounds. See Figure 4.15(i) for illustration. The second example shows that thereverse is also not true.
Sequence X 2 ∈ S n consists of a grid-like construction of size f (n)-by- f (n) where f (n) =pn/ log n. Then, the sequence continues with a sequential access of length n − f (n)2 . The
structure of the grid-like construction is illustrated in Figure 4.15(ii). The construction con¡¢tains all patterns of size up to Ω f (n) , therefore the pattern-avoiding results cannot show
any non-trivial bound on OPT(X 2 ). However, the dynamic finger bound is for this sequence
O(n). To see this, observe that in the “grid” part of the sequence the differences between con¢¡secutive entries are O f (n) , except for at most f (n) pairs, which have difference O( f (n)2 ).
In the second part, the differences are all constant. Thus, the contribution of the first part tothe dynamic finger bound is o(n), whereas the second part contributes an O(n) term only.
See Figure 4.15(ii) for illustration. We refer to [24] for further observations, and to [26] forstronger separations between various bounds.
We have seen that k-decomposable sequences have linear cost (for constant k). It is
tempting to conjecture that the only permutations with nonlinear cost are those that can not
be recursively decomposed (i.e. simple permutations). As it is known that the vast majorityof permutations is simple [21], this would be consistent with Theorem 2.20. This conjectureis, however, false: there are examples of simple permutations that have linear cost, even for
Greedy, such as X 3 = ( n2 , n, 1, n − 1, 2, . . . ); see Figure 4.15(iii).

Figure 4.15: From left to right: (i) example with low pattern-avoidance parameter and high dynamic finger bound, with Greedy execution, (ii) example
with low dynamic finger bound, and high pattern-avoidance parameter,(iii) non-decomposable permutation with linear cost Greedy execution.

4.9 Discussion and open questions
As discussed in § 1 and § 2, “easiness” of an access sequence in the BST model (i.e. linear cost)is more the exception than the rule. This makes it important to understand the structures thatmake an input sequence easy. One could even hope for an eventual “proof by exhaustion”:
a list of all reasons for which access sequences can have small cost, and an algorithm thatmatches the optimum in all these cases. This motivated our study of pattern-avoidance inaccess sequences.
From a theoretical point of view, we find interesting the prospect that an arbitrary avoided
pattern may make the access sequence easy, and find such a phenomenon analogous tostatements in other mathematical domains (e.g. the Erdős-Hajnal conjecture on graphs thathave an arbitrary forbidden induced subgraph.)4.9. Discussion and open questions

97

The understanding of pattern-avoiding inputs with respect to the BST optimum and withrespect to the cost of online algorithms is far from complete. The arguments using forbidden
submatrices appear quite clean, but loose with the parameters, therefore, we expect that thebounds can be improved significantly. It would be interesting to extend the results obtained
for special classes of permutations to more general classes.
There are limits on how far the bounds can be theoretically improved. Such barriers canbe derived from enumerative results from combinatorics (i.e. how many permutations are
there that avoid a certain pattern). We refer to [26] for observations in this direction.
Perhaps most interesting is the question of how well Splay does on pattern-avoiding
permutations. Showing an example where Splay (or some other online algorithm) has highcost would disprove the dynamic optimality of the algorithm in question (Problem 46).
Finally, let us ponder what exactly makes pattern-avoidance a useful property in the BST
model. For other structural bounds, such as dynamic finger or working set, the intuitive
reason is “locality of reference”. By contrast, the avoidance of a fixed pattern seems a rather
global, as well as a rather finicky property – the addition of a single entry may create apattern that was previously avoided. It is perhaps intuitive that the offline optimum can takeadvantage of pattern-avoidance, as it “knows” which pattern is missing. But why should we
expect a simple online algorithm like Greedy or Splay to learn such a property on the fly?
This intuition may be misleading. A single additional entry may indeed destroy thepattern-avoidance property of a sequence, but the modified sequence is still easy. An eventual
theory of access sequences should be robust to such perturbations. In the static BST model,
a search sequence is easy if its elements are drawn from a low entropy distribution. In
the dynamic BST model, one could also describe a family of access sequences through the
distribution of the next access, when the entire sequence is picked at random from a familyof sequences. For classical “easy families”, such as those with low dynamic finger or working
set bound, the “next-access distribution” is still a very low entropy distribution: for dynamic
finger, most of the probability mass is concentrated around the last accessed key; for working
set, most of the mass is on the last few accesses. In this model, the “next-access distribution”
is no longer stationary as in the static case, but for both dynamic finger and working set,
the distribution appears to change quite slowly from one access to the next. It is therefore
reasonable to expect a BST to be able to track the change in distribution.
How does pattern-avoidance fit into this picture? Can we gain more insight from viewing
it as a particular way to restrict “next-access distributions” and the step-by-step change ofthis distribution? It remains to be seen whether and how the easiness of pattern-avoiding
sequences can be reconciled with the other, more “quantitative” structures into a coherent
understanding of the BST model.

99

Chapter 5

Binary search trees andrectangulations
Strangers passing in the street
By chance two separate glances meet
And I am you and what I see is me.

— P INK F LOYD, Echoes (1970)

In this chapter we present a correspondence between sequences of rotations that servean access sequence in the dynamic BST model and sequences of flips that transform one
rectangulation into another. Rectangulations are well-studied combinatorial objects, also
known as mosaic floorplans. Of particular interest to us are rectangulations constrainedby points, also studied in the literature (see [3, 1] and references therein). A flip is a local
operation that transforms a rectangulation by a minimal amount (analogously to rotations intrees).
The resulting view of BST executions in terms of flips in rectangulations is closely related
to the geometric view of Demaine et al. [31], with some marked differences. Recall that in
the geometric view of Demaine et al. we represent nodes of the tree that are touched at a
certain time as points in the plane. The elegance and usefulness of the model lies in the factthat the exact details of the rotations are hidden. Online algorithms emerge in the geometricview as a natural class of geometric algorithms (those that operate in a sweepline-fashion).
Particularly Greedy appears as a natural online algorithm in this view. (In fact, Greedy is sonatural in the geometric view that it is not clear why any algorithm should deviate from it.)In our rectangulation-view the online/offline distinction seems less relevant. The flipsequence between rectangulations constructs the execution trace of a BST algorithm not lineby-line, but in an order that is constrained by the internal structure of the access sequence.
Greedy still has a natural interpretation in this view (in fact, several equivalent interpretations)– but the order in which the Greedy output is constructed in our rectangulation view isneither the temporal-, nor the keyspace-order. Various concepts of the BST model can bereinterpreted in rectangulation-view. In some sense, the rectangulation-view feels more“algorithm-friendly” than the geometric view. We think that it may prove useful for the design
and analysis of offline BST algorithms.

5.1 Rectangulations and Manhattan networks
A rectangulation1 of an axis-parallel rectangle R is a subdivision of R into rectangles byaxis-parallel line segments, no two of which may cross. A rectangulation is called slicing (orguillotine) if it can be obtained by recursively cutting a rectangle with a horizontal or verticalline into two smaller rectangles. See Figure 5.1 for illustration.
1 Alternative names include rectangular layout, subdivision, dissection, tesselation, or mosaic floorplan

100

Chapter 5. Binary search trees and rectangulations

Figure 5.1: Rectangulations. From left to right: (i) slicing rectangulation,(ii) non-slicing rectangulation, (iii) rectangulation constrained by points.

The study of rectangulations in the literature is motivated by several applications. For geometric problems such as point location, nearest neighbor, or range searching, the commonlyused data structures rely on spatial subdivisions such as trapezoidations or rectangulations [14, 87]. The popular k-d tree corresponds (in the planar case) exactly to a slicing
rectangulation [12]. Rectangulations also appear in geometric approximation algorithms [74].
In communication complexity, a comparison protocol [64] for a bivariate function f corresponds to a slicing rectangulation in which every rectangle is f -monochromatic. Rectangulations are also used to model problems in VLSI circuit design [73, § 53]. In data visualization,“cartograms” based on rectangulations have been used for almost a century to represent bothquantitive and relational information [38, 63], or even as a form of art.
Several theoretical aspects of rectangulations have been studied in the combinatorics
literature. In particular, it is known that the number of combinatorially different rectangulations with n rectangles is given by the nth Baxter number [107, 95], and the numberof combinatorially different slicing rectangulations with n rectangles is given by the nth
Schröder number [107, 94]. Explicit bijections from rectangulations (general, respectively,
slicing) have been given to natural classes of permutations counted by Baxter, respectively,
Schröder numbers [2]. Felsner [40] considers various ways in which rectangulations canrepresent certain classes of (planar) graphs.
Most relevant to our work is the recent paper of Ackerman et al. [1] that studies certain
local operations (called flip and rotate) that transform one rectangulation into another.
Following the definition of Ackerman et al. we additionally constrain a rectangulation with aset P of points (no two points on the same vertical or horizontal line), requiring that every
point in P is contained in the interior of a segment of the rectangulation (Figure 5.1). The flipand rotate operations in rectangulations were first introduced in [3].
Ackerman et al. [1] study sequences of rectangulations constrained by the same set P ofpoints. In particular, they are interested in the flip diameter of rectangulations: the maximum
number of flip and rotate operations that may be required to transform one rectangulation
into another.
The main result of this chapter can be summarized as follows. Let X ∈ S n be a permutation, viewed at the same time as a permutation point set X ⊂ [n] × [n]. The “trace” of aflip-sequence between two particular rectangulations constrained by X is a satisfied superset of X (and by the results of Demaine et al. described in § 2.7, it can be viewed as theexecution trace of a BST algorithm serving X ). Thus, the problem of efficiently serving anaccess sequence is reduced to the problem of finding a short flip sequence between two
rectangulations. (We postpone to § 5.2 a more formal statement of results.) The source andtarget rectangulations are the two that are (intuitively) furthest apart: the rectangulationconsisting of only vertical lines and the rectangulation consisting of only horizontal lines.

5.1. Rectangulations and Manhattan networks

101

A converse of the result also holds: every sequence of BST re-arrangements that serves
the access sequence (i.e. every satisfied superset) encodes a valid sequence of flips between
the all-vertical and the all-horizontal rectangulations.
Our definition of the flip operation (§ 5.2) is slightly different from the definition used byAckerman et al. [1]. Nevertheless, there is a close connection between the two definitions,which allows us to answer an open question raised by Ackerman et al. concerning the flip
diameter of rectangulations. The equivalence also leads to a simplified proof of a result
shown by Ackerman et al., which arises now as an immediate corollary of known results for
the BST problem. We explore this topic in § 5.3.
We further transform the obtained rectangulation-view, to arrive at a particularly simple
formulation of the BST problem, as a problem resembling edge relaxations in a shortest pathtree. The interpretation of Greedy in these models is simple and natural. We make somepreliminary observations about the BST problem in rectangulation-view in § 5.5.
Small Manhattan Networks. We also describe Small Manhattan Network, a problem withknown connections to the BST problem (see e.g. Harmon [52]), in terms of (modified) flips
between rectangulations.
A Manhattan-path of length k between two points x, y ∈ A with respect to B ⊇ A, is asequence of distinct points (x = x 1 , x 2 , . . . , x k = y) ∈ B k , such that for all i = 1, . . . , k − 1 thetwo neighboring points x i , x i +1 are on the same horizontal or vertical line, and both thex-coordinates and the y-coordinates of (x 1 , . . . , x k ) form a monotone sequence.
Recall the definition of a satisfied point set from § 2.7, as a set of points without pairs
forming the corners of an empty rectangle. An alternative definition of a satisfied point set
given by Harmon [52] is the following.
Lemma 5.1 ([52]). A point set Y ⊆ [n] × [n] is satisfied, if for any two points a, b ∈ Y , there isa Manhattan-path between a and b with respect to Y .
Verifying the equivalence between the two definition is an easy exercise.
Based on the previous paragraphs and the results described in § 2.7, the BST problem
of serving access sequence X can equivalently be formulated as finding a point set Y ⊇ X
of small cardinality in which there are Manhattan-paths with respect to Y between every
pair of points in Y . An obvious easier problem is to find a point set Y ⊇ X , such that
there are Manhattan-paths with respect to Y between every pair of points in X . As shown
by Harmon [52], the optimum of this easier problem asymptotically equals the MIR lower
bound on OPT (see § 2.7.3). We call the set Y of points a Manhattan-network of X . Such a
construction is also known as an L 1 -spanner.
The problem of connecting a given set of points in the plane by a Manhattan network is aclassical network design problem that has received significant attention. The variant which
we describe, i.e. where the number of added points is minimized, was studied in 2007 by
Gudmundsson, Klein, Knauer, and Smid [51].
The connection between Manhattan networks and the BST problem seems not widely
known. In particular, using this connection, some of the results of Gudmundsson et al.
arise as corollaries of known facts about BSTs. We make this connection explicit, and weformulate further properties of small Manhattan networks, following from BST results. We
also interpret Manhattan networks in the rectangulation-view outlined earlier. As mentioned(§ 2.7.3, Problem 33), the relation between MIR and OPT is mysterious. Our hope is that

102

Chapter 5. Binary search trees and rectangulations

reinterpreting both quantities in a similar setting will lead to new insight about the possible
gap between them.

5.2 The main equivalences
Recall the definition of the dynamic BST problem described in § 2.2. In this chapter we areconcerned with offline BST algorithms (defined in either the first or the second model). In
fact, we will ignore trees, and focus only on the geometric view of the BST problem, i.e. theproblem of finding a small satisfied superset of a set of points (§ 2.7). We refer to this problem
simply as Satisfied Superset. By Theorem 2.24, all statements in this view can be translated tostatements about trees.
We consider only permutation point sets X ⊂ [n] × [n] as inputs. For any point p, wedenote by p.x and p.y the x-coordinate and the y-coordinate of p respectively.

5.2.1 Rectangulation problem
Variants of this problem have been studied in the literature. The formulation we describe
here is new, but closely related to the problem studied by Ackerman et al. [1]. The exact
difference between our model and the model of Ackerman et al., and the implications of thisdifference are explored in § 5.3.
Let n be an arbitrary integer (the problem size). We define the set of planar points©
ª ©
ª
S = 0, 1, . . . , n + 1 × 0, 1, . . . , n + 1 .

The set C of corner points is:©
ª
C = (0, 0), (0, n + 1), (n + 1, 0), (n + 1, n + 1) .

The set M of margin points is:©
ª
M = (i , 0), (i , n + 1), (0, i ), (n + 1, i ) : i ∈ [n] .

Corner-points will not be used in any way. The remaining points of S, i.e. those in S \(M ∪C ) =[n] × [n], are called non-margin points.
A state (P, L) of the Rectangulation problem consists of a set P ⊆ (S \C ) of points and a set
L of horizontal and vertical line segments (in the following, simply segments) with endpoints
in P .
A state (P, L) is valid iff it fulfills the following conditions (see Figure 5.2):(i) (completeness) Each segment in L contains exactly two points from P , namely its two
endpoints. (This implies that no point from P is in the interior of a segment in L.)(ii) (non-crossing) No two segments in L intersect each other (except possibly at endpoints).

q
x

x

q

(iii) (elbow-free) Each non-margin point in P is contained in at least two segments of L,
and if it is contained in exactly two segments, then the two segments must either beboth vertical or both horizontal. (We cannot have the shapes ( ), ( ), ( ), ( ).)The initial state (P 0 , L 0 ) is defined with respect to an input permutation point set X of sizen. The set P 0 is equal to X ∪ M . The set L 0 contains for each non-margin point (x, y) ∈ P 0 \ M

5.2. The main equivalences103

two vertical segments: the one between (x, 0) and (x, y), and the one between (x, y) and(x, n + 1). It is easy to see that the initial state is valid.
An end state (P ∗ , L ∗ ) is a valid state that consists of a point set P ∗ ⊇ P 0 , and a set ofsegments L ∗ , all of them horizontal, such that they cover every point {0, 1, . . . , n + 1} × [n]. See
Figure 5.2 for illustration.
Given a permutation point set X , an algorithm A for the Rectangulation problem transforms the initial state (P 0 , L 0 ) determined by X into an end state (P ∗ , L ∗ ), through a sequenceof valid flips, defined below. The cost of the algorithm, denoted costA (X ), is the number offlips in this sequence. In words, the goal is to go from the all-vertical state to the all-horizontal
state through a minimum number of valid flips.
Let (P, L) be a valid state. Two points a, b ∈ S \C define a flip, denoted 〈a, b〉. A flip 〈a, b〉transforms the state (P, L) into a new state (P 0 , L 0 ) as follows. First, we let P 0 = P ∪ {a, b}, andL 0 = L ∪ {[a, b]}. If there exists some segment [x, y] ∈ L that contains a in its interior, weremove [x, y] from L 0 , and add the segments [x, a], and [a, y] to L 0 . Similarly, if there exists
some segment [z, t ] ∈ L that contains b in its interior, we remove [z, t ] from L 0 , and add thesegments [z, b], and [b, t ] to L 0 .
For 〈a, b〉 to be a valid flip, it must hold that the resulting state (P 0 , L 0 ) is a valid state. In
particular, we can only add a segment [a, b] if it is horizontal or vertical, and if it does notintersect existing segments (except at a or b). After every flip we can remove from L 0 an
arbitrary number of segments. By removing segments we must not violate the elbow-freeproperty. For instance, we can only remove a vertical segment if its non-margin endpoints arecontained in two horizontal segments of L 0 (in other words, the endpoints have extensions
both to the left and to the right).

Figure 5.2: Rectangulation problem. From left to right: (i) initial state corresponding to X = (2, 6, 4, 3, 1, 5), (ii) a valid intermediate state, (iii) a valid
end state, (iv) an invalid intermediate state (observe that the state is notelbow-free). Margin points are not shown.

The following theorem captures the connection (in one direction) between Rectangulation and Satisfied Superset.
Theorem 5.2. Any algorithm A for the Rectangulation problem can be transformed (inpolynomial time) into an algorithm B for the Satisfied Superset problem, such that for all¡¢
inputs X , we have costB (X ) = O costA (X ) .
Proof. Consider an algorithm A for Rectangulation, executed from initial state (P 0 , L 0 ), defined by an input permutation X . As we run A, we construct a set Y ⊇ X , that is a solution
for Satisfied Superset (this is our new algorithm B ). The process is straightforward: Initially
we let Y = X . Whenever A performs a flip 〈a, b〉, we let Y = Y ∪ ({a, b} \ M ). In words, weconstruct a superset of X by adding every non-margin endpoint created while flipping fromthe all-vertical to the all-horizontal state in Rectangulation. The cost of A is equal to the104

Chapter 5. Binary search trees and rectangulations

Figure 5.3: A sequence of valid flips from initial state to end state. Margin
points are not shown.

number of flips. Since each flip adds at most two points to Y , the claim on the cost of B isimmediate.
It remains to show that the point set Y thus constructed is satisfied. Suppose otherwise,that in the end there are two points a, b ∈ Y , that are not on the same horizontal or vertical line,
and the rectangle with corners a, b contains no other point of Y . Without loss of generality,
assume that a is above and to the left of b. Let 〈a, a 0 〉 be the last flip in the execution of A
such that a 0 is on the same horizontal line as a and to the right of a. Let 〈b 0 , b〉 be the last flip
such that b 0 is on the same horizontal line as b and to the left of b. (There have to be such
flips, otherwise A would not produce a valid end state.) Since the rectangle with corners a, b
is empty, b 0 must be to the left of a, and a 0 must be to the right of b.
Suppose that the flip 〈b 0 , b〉 occurs earlier than the flip 〈a, a 0 〉 (the other case is symmetric),
and consider the state before the flip 〈a, a 0 〉. In that state there must be a vertical segmentwith top endpoint at a, otherwise a would be contained in at most two segments, not bothhorizontal or vertical, contradicting the elbow-free property. Let a ∗ be the bottom endpointof the vertical segment with top endpoint a. The point a ∗ must be strictly below b, forotherwise the rectangle with corners a, b would contain it. This means that [a, a ∗ ] intersects[b 0 , b], contradicting that we are in a valid state. We conclude that Y is a satisfied superset ofX.
The following converse of Theorem 5.2 also holds.
Theorem 5.3. Any algorithm B for the Satisfied Superset problem can be transformed (inpolynomial time) into an algorithm A for the Rectangulation problem, such that for all inputs¡¢
X , we have costA (X ) = O costB (X ) .
Proof. Consider an algorithm B for Satisfied Superset that for input X outputs a point set
Y ⊇ X . We construct a sequence of flips that transform the initial state (P 0 , L 0 ) of the Rectangulation problem determined by X into an end state (P ∗ , L ∗ ), such that P ∗ \ M = Y (this is
our new algorithm A). We define A such that every flip creates a new horizontal segment
whose endpoints are in Y ∪ M , and no horizontal segment is ever removed during the courseof the algorithm. The claim on the cost of A is immediate, since each flip can be charged to
one of its (non-margin) endpoints, and each point in Y has at most two flips charged to it.
The removal of vertical segments does not contribute to the cost.
We run algorithm A until we reach an end state, maintaining the invariant that in every
state (P, L), we have (P \ M ) ⊆ Y . The invariant clearly holds in the initial state (P 0 , L 0 )determined by X . Algorithm A consists of two types of greedy steps, executed in any order:(1) if at any point, some valid flip 〈a, b〉 is possible, such that a, b ∈ Y ∪ M , then execute it,5.2. The main equivalences105

and (2) if at any point, some vertical segment [a, b] ∈ L that contains no point from Y (except
possibly its endpoints) can be removed, then remove it.
It remains to be shown that the algorithm does not get stuck, i.e. that there is always anoperation of type (1) or (2) that can be executed, unless we have reached a valid end state.
Consider an intermediate state (P, L) during the execution of A and suppose for contradictionthat there is no available operation of either type.
Consider two points q, q 0 ∈ Y ∪ M on the same horizontal line, q to the left of q 0 , suchthat [q, q 0 ] is not in L, and the segment [q, q 0 ] contains no point of Y in its interior. (Notethat q and q 0 are not necessarily in P .) If there is no such pair of points, then we are done,
since all horizontal lines are complete, and all remaining vertical segments can be removed.
Among such pairs, consider the one where q is the rightmost, in case of a tie, choose the one
where q 0 is the leftmost.
Call a point q ∈ P left-extensible if it is not the right endpoint of a segment in L, andright-extensible if it is not the left endpoint of a segment in L.
Observe that throughout the execution of A, for any state (P, L), every point in Y iscontained in some segment of L. Since 〈q, q 0 〉 is not a valid flip, [q, q 0 ] must intersect somevertical line [z, z 0 ] ∈ L (assume w.l.o.g. that z is strictly above, and z 0 is strictly below [q, q 0 ]).
Observe that [z, z 0 ] cannot contain a point of Y in its interior. If it were to contain such a
point z ∗ , then z ∗ would be the left endpoint of some segment missing from L, contradicting
the choice of q. Thus, since removing [z, z 0 ] is not a valid step, it must be that one of z andz 0 is a non-margin point that is left- or right-extensible. If z or z 0 were right-extensible, thatwould contradict the choice of q. Therefore, one of them must be left-extensible. Assume
w.l.o.g. that z is left-extensible.
Since Y is satisfied, by Lemma 5.1 there has to be a point w ∈ Y \ {z, q} either on thehorizontal segment [(q.x, z.y), z], or on the vertical segment [z, (z.x, q.y)]. Since [z, z 0 ] cannot
contain a point of Y in its interior, it must be the case that w is on [(q.x, z.y), z], and choose
w to be closest to z. But then the segment [w, z] is missing from L, contradicting the choiceof q, q 0 because q.x ≤ w.x ≤ z.x < q 0 .x.
Theorem 5.2 and Theorem 5.3 state that the Rectangulation and Satisfied Superset problems are polynomial-time equivalent. Observe that the proofs, in fact, show somethingstronger: for an arbitrary permutation point set X , a point set Y ⊇ X is a solution for Satisfied
Superset exactly if Y ∪ M is the point set of a valid (and reachable) end state for Rectangulation.

5.2.2 A tree relaxation problem©
ªConsider again a permutation point set X = (x i , i ) : i ∈ [n] as input. We define a monotone
tree on X to be a rooted tree that has X as the set of vertices, and whose edges are all goingaway from the root according to the vertical ordering of the points. That is, if two pointsa = (a.x, a.y), b = (b.x, b.y), with a, b ∈ X are the endpoints of an edge in a monotone tree on
X , then a is closer to the root than b (in graph-distance) iff a.y < b.y. Recall that all points in
X have distinct x- and y-coordinates. It follows that (x 1 , 1) is the root of every monotone tree
on X .
We are concerned with two special monotone trees on X . The treap on X is the binary
search tree with the x-coordinates as keys, and the y-coordinates as heap-priorities. Thatis, the lowest point (x 1 , 1) ∈ X is the root of the tree, and the points left of (x 1 , 1) form its left
subtree, and the points right of (x 1 , 1) form its right subtree, defined in a recursive fashion.
The path on X is a tree that connects all elements through a path by increasing y-coordinate,i.e. in the order (x 1 , 1), . . . , (x n , n). It is easy to verify that both the treap and the path defined

106

Chapter 5. Binary search trees and rectangulations

on X are unique and that they form monotone trees on X . Observe that the definition of amonotone tree does not require the tree to fulfill the search tree property or even to be binary.
See Figure 5.4 for illustration.
Given a permutation point set X , an algorithm A for the Tree Relaxation problem transforms the treap on X to the path on X through a sequence of valid edge-flips, defined below.
The cost of the algorithm, denoted costA (X ), is the number of edge-flips in this sequence.
Let T be a monotone tree on X . A valid edge-flip in T is defined as follows. Consider
a vertex r of T that has at least two children. Sort the children of r by their x-coordinate,
and let a and b be two children that are neighbors in this sorted order, such that a is belowb (the y-coordinate of a is smaller than the y-coordinate of b). Then the edge-flip (a → b)
adds the edge (a, b) to T and removes the edge (r, b) from T . It is easy to verify that a valid
edge-flip maintains the monotone tree property of T . The edge-flip operation is reminiscentof an edge-relaxation in shortest-path algorithms (performed in reverse). See Figure 5.5 forillustration.

Figure 5.4: Tree relaxation problem. From left to right: (i) treap on X =(2, 6, 4, 3, 1, 5), (ii) an intermediate monotone tree on X , (iii) path on X , (iv) aninvalid intermediate state (tree is not monotone).

Figure 5.5: A sequence of valid edge-flips from initial (treap) state to end(path) state.

The Tree Relaxation problem is closely related to the Rectangulation problem (and as aconsequence, to the BST problem), as shown by the following theorem.
Theorem 5.4. Any algorithm A for the Tree Relaxation problem can be transformed (inpolynomial time) into an algorithm B for the Rectangulation problem, such that for all inputs¡¢
X of size n, we have costB (X ) = O costA (X ) + n .
Proof. We start B with an initial phase, then we simultaneously run algorithm A for Tree
Relaxation on X , and output the operations of B for Rectangulation on X , such that we
output at most two flips in B for every edge-flip in A. We finish B with a cleanup phase. Boththe initial phase and the cleanup phase consist of O(n) flips, to be specified later. In the end
we show that B reaches a valid end state of Rectangulation. Since the total number of flips
performed is at most O(n) + 2 · costA (X ), the claim on the cost follows.
After the initial phase, we maintain three invariants, denoted I 1 , I 2 , and I 3 . Informally,
the role of the invariants is to enforce that the current monotone tree of A is, at all times, thesegment visibility graph of the horizontal segments in the current rectangulation of B .
In any given state (P, L) during the execution of B , let Hi denote the set of horizontal
segments in L at height i .

5.2. The main equivalences107

I 1 (contiguity): For all i , the union of the horizontal segments in Hi form a contiguous
horizontal segment, which we denote h i .
I 2 (nesting): For all i , denote the x-coordinate of the left (resp. right) endpoints of h i as
`i (resp. r i ). Let x i 1 , . . . , x i k be the children of x t in the current monotone tree on X , sorted byx-coordinate (i.e. x i 1 < · · · < x i k ). We have that the endpoints of the segments h i 1 , . . . , h i k arealigned, and not overhanging the parent segment h t . More precisely, `t ≤ `i 1 , and r i k ≤ r t ,and for all j = 1, . . . , k − 1, we have r i j = `i j +1 . For the root x 1 of the tree, we have `1 = 0, andr 1 = n + 1.
I 3 (visibility): Let x i 1 , . . . , x i k , x t be defined as before. For j = 1, . . . , k, let us denote by R j
the axis-aligned rectangle with corners (`i j , i j ), (r i j , t ). Let R0 be the rectangle with corners(`t , t ), (`i 1 , n + 1), and let R j +1 be the rectangle with corners (r i k , n + 1), (r t , t ). We have thatthe interiors of the rectangles R0 , R1 , . . . , R j +1 are not intersected by any segment in L in
the current state of B . Furthermore, the vertical sides of the rectangles R0 , R1 , . . . , R j +1 areeither touching the margin, or fully covered by segments in L.
It remains to describe the steps of the algorithm B .
Initial phase. For each (i = n, . . . , 1), flip 〈L i , x i 〉 and 〈x i , R i 〉, where L i (R i ) is the leftmost(rightmost) point such that the corresponding flip is valid. After every flip, remove all possible
vertical segments from the current state before proceeding to the next i . In particular, remove
the vertical segment with endpoints (x i , 0), (x i , i ).
Recall that in the beginning, A is in the state that the current tree is the treap on X .
Let T be the treap on X . We show that the invariants hold after the initial phase. Observethat I 1 holds trivially: after the initial phase we have the horizontal contiguous segments
h i = [L i , R i ].
We prove I 2 and I 3 by induction. Clearly, if |X | = 1, the invariants hold. Consider the laststep, when we flip 〈L 1 , x 1 〉 and 〈x 1 , R 1 〉, for suitable L 1 , R 1 . Denote by v the vertical segmentwith x-coordinate equal to x 1 . Observe that for all i > 1, the segments h i can intersect v
only at their endpoints (L i and R i ). Since none of these points are extended both to the left
and to the right, no portion of v has been removed before this step. This means that therectangulations on the two sides of v are independent of each other, i.e. they would havebeen the same even if the input on the other side of v were different. In particular, this means
that, by induction I 2 and I 3 hold for the rectangulations on the two sides of v, corresponding
to the left and right subtrees of x 1 in the treap T .
Let x i and x j be the left, respectively right child of x 1 in T (one of the two might be
missing, in case x 1 = 1 or x 1 = n). By I 2 , we have that h i extends horizontally from 0 to x 1 ,and h j extends horizontally from x 1 to n + 1. Since the vertical segments below every pointx i have been removed, we can execute the flips 〈(0, 1), x 1 〉 and 〈x 1 , (n + 1, 1)〉. Finally, since x 1
is complete, we can remove the vertical segment with top endpoint x 1 .
Both I 2 and I 3 are established for the full tree T , completing the induction.
Flips during the execution of A. Let x i and x j be neighboring children of x t in the current
tree, such that i < j , and the valid edge-flip (x i → x j ) is executed in A. Assume w.l.o.g. thatx i < x j . By I 1 , there exist contiguous horizontal segments h i and h j . Observe that h i is below
h j . Let `i , ` j , and `t (r i , r j , and r t ) denote the x-coordinates of the left (right) endpoints

108

Chapter 5. Binary search trees and rectangulationsof h i , h j , and h t . By I 2 , we have `t ≤ `i < r i = ` j < r j ≤ r t . Let L = (r i , i ), and let R = (r j , i ).
Then the flip 〈L, R〉 is executed in B .
Let us verify that the flip is valid. Due to invariant I 3 , the rectangle with corners (r i , i ) and(r j , j ) has empty interior, therefore the flip intersects no vertical segment. Moreover, by I 3 ,the right side of the rectangle is covered by segments. Therefore, the flip creates no crossing,elbow, or point of degree one, it is therefore a valid flip.
After the flip, x j is the child of x i , and x i is the child of x t . It is easy to verify that theinvariants are maintained, except for the following case: Let x k be the rightmost child of x i
before the flip, with endpoints `k and r k . After the flip, x k and x j are neighboring siblings,
but it may happen that their endpoints are not aligned, i.e. r k < ` j . If this is the case, we needto perform an additional flip. Suppose that h k is lower than h j . Then execute in B the flip〈(r k , j ), (` j , j )〉. In the case when h j is lower than h k , execute the flip 〈(r k , k), (` j , k)〉. The
flips are valid by I 3 before the edge-flip in A, and by the flip, I 3 is re-established using at mosttwo flips.
In the end, if A is a correct algorithm for Tree Relaxation, it will end with a path tree. Let
h 1 , . . . , h n be the horizontal lines corresponding to the current state in the execution of B .
Cleanup phase. From invariants I 1 , I 2 , and I 3 , it follows that `1 ≤ `2 ≤ · · · ≤ `n < r n ≤ · · · ≤r 1 . We can transform this state to a valid end state for Rectangulation, with the valid flips (inthis order): 〈0, `1 〉 , 〈0, `2 〉 , . . . , 〈0, `n 〉 , 〈r 1 , n + 1〉 , . . . , 〈r n , n + 1〉.
From the previous proof it seems that algorithms for Tree Relaxation correspond toalgorithms for Rectangulation of a very restricted kind. Whether the restriction is reallysignificant, remains an intriguing open question. Therefore, we ask the following.
Problem 49. Does a converse of Theorem 5.4 hold?

5.2.3 Signed satisfied supersets and rectangulations
We define the “one-sided” (alternatively: “signed”) variants of the studied problems.
Signed Satisfied Superset. Recall the definition of - and -type pairs of points (§ 2.7.3).
A point set Y ⊆ [n] × [n] is -satisfied if it has no unsatisfied -type pair, and it is -satisfied
if it has no unsatisfied -type pair. Note that Y is satisfied if and only if it is both -satisfied
and -satisfied.
Given a permutation point set X of size n, an algorithm A for the - (-) Satisfied
Superset problem outputs a point set Y with X ⊂ Y ⊆ [n] × [n], such that Y is -satisfied(-satisfied). The cost of A is the size of the set Y , denoted costA (X ). We generally call the- and -Satisfied Superset problems Signed Satisfied Superset.
Let OPT (X ) and OPT (X ) be the optimum cost for the -, resp. -Satisfied Superset
problem for X . Demaine et al. [31] show that Greedy and Greedy (described in § 2.7.3)
compute the optimum solution, i.e.
costG  (X ) = OPT (X ),costG  (X ) = OPT (X ).
Recall from § 2.7.3 that SG(X ) denotes the sum of the two quantities, and that SG(X ) =¡¢Θ MIR(X ) .

5.2. The main equivalences

109

x
q

Signed Rectangulation. Let [p, q] be a vertical segment, and [q, r ] be a horizontal segment.
We say that [p, q] and [q, r ] form a ( )-elbow if (i) p is above q and r is on the right of q, or(ii) p is below q and r is on the left of q. Symmetrically, we say that [p, q] and [q, r ] form a( )-elbow if (i) p is above q and r is on the left of q, or (ii) p is below q and r is on the rightof q.
A state (P, L) of the Rectangulation problem is ( )-elbow-free, respectively ( )-elbow-free
if each non-margin point in P is contained in at least two segments of L, and if it is containedin exactly two segments, then they must not form a ( )-elbow, resp. ( )-elbow.
We define the ( )-Rectangulation problem the same way as Rectangulation, exceptthat we only require that each state (P, L) of the ( )-Rectangulation problem is ( )-elbowfree instead of elbow-free (i.e. the ( )-elbows are allowed). We similarly define the ( )Rectangulation problem. We generally call the ( )- and ( )-Rectangulation problems
Signed Rectangulation.
Given any set S of allowed elbows, we can similarly define the S-Rectangulation problem
in an obvious way, e.g. ( )-Rectangulation problem or (xx)-Rectangulation problem.

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x
q

x

x

x

x
q

x
q

Theorem 5.5. Any algorithm A for the ( )- or ( )-Rectangulation problem can be transformed (in polynomial time) into an algorithm B for the -, respectively -Satisfied Superset¡¢
problem, such that for all inputs X , we have costB (X ) = O costA (X ) .

xq

Proof. We only show the case of ( )-Rectangulation. The other case is symmetric. The
argument is similar as in Theorem 5.2. Initially, let Y = X . We construct an algorithm B fromA by adding to Y every non-margin endpoint created while flipping from the all-vertical tothe all-horizontal state in Rectangulation. The cost of A is equal to the number of flips. Since
each flip adds at most two points to Y , the claim on the cost of B is immediate.
We claim that Y is -satisfied. Suppose otherwise, that there are two points a, b ∈ Y
where a is above and to the left of b. Let 〈a, a 0 〉 be the last flip in the execution of A suchthat a 0 is on the same horizontal line as a and to the right of a. Let 〈b 0 , b〉 be the last flip suchthat b 0 is on the same horizontal line as b and to the left of b. (There have to be such flips,
otherwise A would not produce a valid end state.) Since the rectangle with corners a, b is
empty, b 0 must be to the left of a, and a 0 must be to the right of b.
Suppose that the flip 〈b 0 , b〉 occurs earlier than the flip 〈a, a 0 〉 (the other case is symmetric),
and consider the state before the flip 〈a, a 0 〉. In that state there must be a vertical segment with
top endpoint at a, otherwise a would be contained in ( )-elbow. (This is the only difference
from the proof of Theorem 5.2.) Let a ∗ be the bottom endpoint of the vertical segment with
top endpoint a. The point a ∗ must be strictly below b, for otherwise the rectangle withcorners a, b would contain it. This means that [a, a ∗ ] intersects [b 0 , b], contradicting that weare in a valid state. We conclude that Y is a -satisfied superset of X .

x
qx

Theorem 5.6. Any algorithm B for the -Satisfied Superset problem can be transformed (inpolynomial time) into an algorithm A for the ( )-Rectangulation problem, such that for all¡¢
inputs X , we have costA (X ) = O costB (X ) .

x

Proof. The argument is similar as in Theorem 5.3. Let Y be a -satisfied set constructed by
B . We construct an algorithm A that maintains the state (P, L) with the following operations
in a greedy manner: (1) if some valid flip 〈a, b〉 is possible where a, b ∈ Y ∪ M , then execute
it, and (2) if some vertical segment [a, b] ∈ L containing no point from Y (except possibly its
endpoints) can be removed, then remove it. Here, the valid flip is defined according to the( )-Rectangulation problem. We claim that A reaches an end state. The cost of A follows
with the same argument as in Theorem 5.3. Suppose for contradiction that A gets stuck at anintermediate state (P, L).

110

Chapter 5. Binary search trees and rectangulationsx

As in Theorem 5.3, consider two points q, q 0 ∈ Y ∪ M on the same horizontal line, q to
the left of q 0 , such that [q, q 0 ] is not in L, and the segment [q, q 0 ] contains no point of Y in
its interior. If there is no such pair of points, then we are done, since all horizontal lines arecomplete, and all remaining vertical segments can be removed. Among such pairs, consider
the one where q is the rightmost, in case of a tie, choose the one where q 0 is the leftmost.
Left-extensibility and right-extensibility are defined as in the proof of Theorem 5.3.
Observe that throughout the execution of A, for any state (P, L), every point in Y iscontained in some segment of L. Since 〈q, q 0 〉 is not a valid flip, [q, q 0 ] must intersect somevertical line [z, z 0 ] ∈ L (assume w.l.o.g. that z is strictly above, and z 0 is strictly below [q, q 0 ]).
Observe that [z, z 0 ] cannot contain a point of Y in its interior. If it were to contain such a pointz ∗ , then z ∗ would be the left endpoint of some segment missing from L, contradicting the
choice of q. Thus, since removing [z, z 0 ] is not a valid step according to ( )-Rectangulation
problem, it must be that either z is left-extensible, z is right-extensible or z 0 is right-extensible.
If z or z 0 were right-extensible, that would contradict the choice of q. Therefore, z is leftextensible.
Since Y is -satisfied, by the statement analogous to Lemma 5.1 there has to be a pointw ∈ Y \ {z, q} either on the horizontal segment [(q.x, z.y), z], or on the vertical segment[z, (z.x, q.y)]. Since [z, z 0 ] cannot contain a point of Y in its interior, it must be the case thatw is on [(q.x, z.y), z], and choose w to be closest to z. But then the segment [w, z] is missing
from L, contradicting the choice of q, q 0 because w.x ≥ q.x.

qxqTheorems analogous to Theorem 5.6 for ( ),( ),( )-Rectangulation can be shown similarly. By Theorems 5.5 and 5.6 we have that (i) -Satisfied Superset problem, ( ),( ),( )Rectangulation problems are equivalent, and (ii) -Satisfied Superset problem, ( ),( ),( )Rectangulation problems are equivalent.
Let us also consider the case of allowing two types of elbows that are neighbors in thex), ( ), (x )-Rectangulation
clockwise ordering of the four possible elbows, i.e. the ( ), ( xproblems. Together with ( ) and ( ), these are all possible cases with two types of allowed
elbows. We argue that ( )-Rectangulation is trivial: for every input of size n there is a flipx),
sequence of length O(n). Due to the symmetries of the problem, the same holds for the ( xx( ), ( ) cases, and consequently, also for Rectangulation with three or four types of allowed
elbows.
The algorithm for obtaining a linear sequence of flips for ( )-Rectangulation is as follows.
First execute an inital phase as in the proof of Theorem 5.4, then complete the horizontal
rectangulation line by line, from top to bottom. At step k, assume that the horizontal lines
k, . . . , n are completed. Remove every vertical segment whose top endpoint is at height k(observe that this can only create ( )-elbows). Then, complete the horizontal line at heightk − 1, by flipping horizontal segments at height k − 1 to the maximum extent possible (thiscan not create crossings, since we removed vertical segments in the previous step).

x

x

x

x
q

q

x
q
x

q
x
x
q

x

x

x
q

x

x

x

x

x

x

x

x

x

5.3 Consequences for rectangulations
In this section we study the Flip Diameter problem introduced by Ackerman et al. [1]. Ackerman et al. study the distance between two rectangulations constrained by the same set ofpoints, where distance refers to the shortest sequence of local operations that transform one
rectangulation into the other.
The concept of rectangulation studied by Ackerman et al. is the same as the one wedefined in § 5.2.1, apart from the fact that we keep track of all intersection points that are
created in the sequence of transformations from one rectangulation to another, whereas in
the problem studied by Ackerman et al. this is not explicitly needed. Their definition of a

5.3. Consequences for rectangulations

111

rectangulation is essentially the union of all segments in L, for a given state (P, L). In thissection we adopt the same convention, i.e. we consider two states (P, L) and (P 0 , L 0 ) equivalent
if the union of all segments in L equals the union of all segments in L 0 .
The Flip Diameter problem asks, given a set of points constraining rectangulations,
to find the largest possible distance between two rectangulations. This is in contrast to
the problem described in § 5.2.1, where we are concerned with the distance between two
particular rectangulations, namely the all-horizontal, and the all-vertical one.
Finally, the local operations used by Ackerman et al. are slightly different from the flip
operation defined in § 5.2.1. In the following, we describe the rotate and flip operation usedby Ackerman et al. in the context of our Rectangulation problem. We call these two operations
A-rotate and A-flip.
Given a valid state (P, L) of Rectangulation, an A-rotate operationconsists of removing a segment [x, y] from L, and adding a new
segment [x, z] to L. If z is contained in the interior of some segment[a, b] ∈ L, we remove [a, b] from L, and add [a, z] and [z, b] to L.
We denote the resulting set of segments L 0 and we let P 0 = P ∪ {z}.
The A-rotate operation is valid, if [x, y] and [x, z] have different
orientations (i.e. one of them horizontal, the other vertical), and if
the resulting state (P 0 , L 0 ) is a valid state of Rectangulation.
Given a valid state (P, L) of Rectangulation, an A-flip operationconsists of removing two segments [x, y] and [y, z] from L and
Figure 5.6: (above) A-rotate
adding new segments [v, y] and [y, w] to L. If v is contained inoperations. (below) A-flip
the interior of some segment [a, b] ∈ L, we remove [a, b] from L andoperations.
add [a, v] and [v, b]. Similarly, if w is contained in the interior ofsome segment [c, d ] ∈ L, we remove [c, d ] from L and add [c, w] and [w, d ]. We denote theresulting set of segments L 0 and we let P 0 = P ∪{v, w}. The A-flip operation is valid, if [x, y] and[y, z] have the same orientiation (i.e. both horizontal or both vertical), [v, y] and [y, w] havethe same orientation (i.e. both horizontal or both vertical), different from the orientationof [x, y], and if the resulting state (P 0 , L 0 ) is a valid state of Rectangulation. We illustrate the
A-rotate and A-flip operations in Figure 5.6.
We make the simple observation that both an A-rotate and an A-flip can be simulatedwith one, respectively two flip operations as defined in § 5.2.1.
Let R1 and R2 be two valid states of Rectangulation given by a permutation point
set X . Let d (R1 , R2 ) denote the shortest number of A-rotate and A-flip operations thattransform R1 to R2 , and let d 0 (R1 , R2 ) be the shortest number of flip operations (according
to the definitions in § 5.2.1) that transform R1 to R2 . The Flip Diameter problem studied by©
ªAckerman et al. asks for the quantity diam(X ) = maxR1 ,R2 d (R1 , R2 ) , where the maximum
is over all valid states of Rectangulation determined by X . Let OPTR (X ) = minA costA (X ), i.e.
the smallest cost of any algorithm for the Rectangulation problem with input X , as definedin § 5.2.1. We make the following easy observation.
Theorem 5.7. For an arbitrary permutation X , we have

OPTR (X ) ≤ 2 · diam(X ).
Proof. By the observation that two flip operations can simulate an A-rotate or an A-flip, we
have that d 0 (R1 , R2 ) ≤ 2 · d (R1 , R2 ), for all R1 , R2 .
©
ª
Let diam0 (X ) = maxR1 ,R2 d 0 (R1 , R2 ) , where the maximum is over all valid states ofRectangulation reachable from the initial state determined by X . By the previous observation,
we have diam0 (X ) ≤ 2 · diam(X ). Furthermore, diam0 (X ) ≥ OPTR (X ), since OPTR (X ) refers to
the shortest number of flips between two particular Rectangulations. The claim follows.

112

Chapter 5. Binary search trees and rectangulations

We give a new interpretation of a result of Ackerman et al. They prove the following.
Theorem 5.8 ([1, § 3]). There exists a permutation X of size n such that diam(X ) = Ω(n log n).
The proof of Ackerman et al. uses the bitwise reversal permutation R n (§ 2.6) and argues
about certain geometric constraints that hold for any possible sequence of A-rotate and A-flip
operations on rectangulations constrained by this permutation.
We give a very simple alternative proof: from Theorem 2.21 we know that for every BST
algorithm A it holds that costA (R n ) = Ω(n log n). Using the equivalences between the BST
problem and Satisfied Superset (Theorem 2.24), respectively, between Satisfied Superset
and Rectangulation (Theorem 5.2), it follows that OPTR (R n ) = Ω(n log n). The application ofTheorem 5.7 finishes the proof.
Ackerman et al. raise the open question of computing the average of diam(X ) over all
permutation point sets X of size n. A simple argument shows that this value is Ω(n log n).
Theorem 5.9. For a random permutation X of size n, we have E X [diam(X )] = Ω(n log n).
Proof. It is known (Theorem 2.20) that E X [costA (X )] = Ω(n log n) for any BST algorithm A.
For any algorithm B for Rectangulation, there is a BST algorithm A such that costA (X ) =¡¢O costB (X ) for all X (Theorems 2.24 and 5.2). Thus, E X [costB (X )] = Ω(n log n) for every
Rectangulation algorithm B . Since costB (X ) ≤ 2 · diam(X ) for some algorithm B for Rectangulation (Theorem 5.7), the claim follows.
It would be of interest to describe natural classes of inputs X of size n, for which thevalue of diam(X ) is small, i.e. linear in n. For the BST problem there has been extensive
research on query sequences that can be served with linear total cost (e.g. § 2.4, § 4). For any
such sequence X we obtain (via Theorems 2.24 and 5.3) that d 0 (V, H ) = O(n), where V is the
Rectangulation initial state determined by X , and H is any Rectangulation valid end statereachable from V .
The claim that easy (linear cost) permutations for the BST problem are also easy (linearcost) for the Flip Diameter problem follows immediately, if the following two conjectures
hold.
Problem 50. Prove or disprove:¡¢• For any two Rectangulation states R1 and R2 , we have d (R1 , R2 ) = O d 0 (R1 , R2 ) .
¡¢• For any two Rectangulation states R1 and R2 , we have d 0 (R1 , R2 ) = O d 0 (H ,V ) .
The first conjecture claims that A-rotate and A-flip operations are essentially equivalent
with our flip operation, and the second conjecture claims that the distance between the
all-vertical and any all-horizontal state is asymptotically the largest among all distances.
For instance, Ackerman et al. state the open question of whether diam(X ) is linear, if X is aseparable permutation. Recall Theorem 4.19, stating that separable permutations are linearcost for the BST problem. Thus, if the above conjectures hold, then we get an affirmative
answer to this question.
Based on Theorems 2.24, 5.2, and 5.3, we know that our flip operation between rectangulations captures every possible BST algorithm. It would be interesting to give a characterizationof the class of BST algorithms that are captured by the A-flip and A-rotate operations.
Ackerman et al. [1, § 2] show that diam(X ) = O(n log n), for all permutations X of size n.
The proof is constructive (an algorithm with worst-case O(n log n) operations). The proposed
algorithm and its analysis are quite sophisticated, for instance, the proof relies on the Fourcolor theorem. However, if we interpret this algorithm in the special case of transforming theall-vertical rectangulation to the all-horizontal rectangulation (i.e. for our Rectangulation

5.4. Consequences for Manhattan networks

113

problem), the output of the algorithm is rather simple: it corresponds to a static balanced
binary search tree (whose cost for serving X is clearly O(n log n)).
We know that A-flip and A-rotate operations can capture non-trivial BST algorithms (i.e.
other than static trees), since Ackerman et al. show that the flip diameter of a diagonal point
set is O(n). In the language of binary search trees, this means that the sequence S = (1, 2, . . . , n)is accessed in time O(n), i.e. the sequential access condition. Recall that no static BST canachieve this bound. It is instructive to interpret the algorithm of Ackerman et al. [1, § 4]
given for this particular input in terms of BST rotations (the algorithm corresponds to astraightforward offline BST algorithm tailored for serving the access sequence S). As we haveseen, in the BST world, such a bound is achieved by several general-purpose algorithms,
including Splay and Greedy.

5.4 Consequences for Manhattan networks
We stated that given an input permutation point set X , a set Y ⊇ X is a solution for theSatisfied Superset problem, if and only if for all a, b ∈ Y , there is a Manhattan path between aand b with respect to Y (Lemma 5.1).
As mentioned in § 5.1, a straightforward relaxation of the Satisfied Superset problem is torequire Manhattan paths only between pairs of points from the input point set X . This is the
Small Manhattan Network problem, which is of independent interest.
More precisely, an algorithm A for Small Manhattan Network outputs, given a permutation point set X , a point set Y ⊇ X , such that for all a, b ∈ X , there is a Manhattan path
between a and b with respect to Y . The cost of A, denoted costA (X ) is the size of the set Y .
In the context of the BST problem, Small Manhattan Network was defined by Harmon [52]as a lower bound for the BST optimum. In a geometric setting, the problem was studied by
Gudmundsson, Klein, Knauer, and Smid [51].
Let OPTM (X ) = minA costA (X ), i.e. the optimum Small Manhattan Network solution for
input X .
From the above definition of Small Manhattan Network as a less restricted Satisfied
Superset problem, the following result is immediate.
Theorem 5.10 ([52]). For an arbitrary permutation X we have

OPTM (X ) = O OPT(X ) .
¡¢In § 5.2.3 we described the Signed Satisfied Superset problem and we denoted by SG(X )the Signed Satisfied Superset optimum for X , i.e. the sum of the - and -Satisfied Superset
optima:SG(X ) = OPT (X ) + OPT (X ).

x
q

x
q

x
q

x
q

Further, if OPTR (X ) and OPTR (X ) denote the optima for ( )- and ( )-Rectangulation( )( )(defined in § 5.2.3), let us denote by OPTsR (X ) the Signed Rectangulation optimum for X , i.e.

x
q

x
q

R
OPTsR (X ) = OPTR( ) (X ) + OPT( ) (X ).

The following statement extends Theorems 2.30 and 2.31. The equivalences were shownby Demaine et al. [31] and Harmon [52], except for the new quantity OPTsR (X ), whose
relation with the other quantities follows from Theorems 5.5 and 5.6.
Theorem 5.11. For an arbitrary permutation X we have (up to constant factors):

SG(X ) = OPTsR (X ) = MIR(X ) = OPTM (X ).

114

Chapter 5. Binary search trees and rectangulations¢¡
For completeness, we give an alternative proof of the statement OPTM (X ) = Ω MIR(X ) .
¡¢(The other direction OPTM (X ) = O MIR(X ) follows from the fact that the union of theGreedy and Greedy outputs for X is on one hand, a feasible Manhattan Network solution,on the other hand, a constant-approximation for MIR(X ).) The following proof is inspiredby a proof of a similar flavor given by Demaine et al. [31] for a different statement, and issomewhat simpler than the proof given by Harmon [52].

Proof. Recall from § 2.7.3 the definitions of R ⊆ I X and R ⊆ I X as the largest -independent,
respectively -independent sets of rectangles defined by X . Let OPTM
 (X ) be the size of thesmallest point set Y ⊇ X such that for all pairs of points a, b ∈ X such that a is above andto the right of b, there is a Manhattan path between a and b in Y . Let OPTM
 (X ) the sizeof the smallest point set Y ⊇ X such that for all pairs of points a, b ∈ X such that a is above
and to the left of b, there is a Manhattan path between a and b in Y . The proof relies on thefollowing lemma.
Lemma 5.12. For all permutations X , we have

OPTM
 (X ) ≥ |X | + | R (X )|,OPTM
 (X ) ≥ |X | + | R (X )|.
©
ªM
As we have OPTM (X ) ≥ max OPTM
 (X ), OPT (X ) , using Lemma 5.12, we obtain:

1
2

1
2

OPTM (X ) ≥ |X | + | R (X )| + | R (X )| = θ MIR(X ) .
¡¢It remains to prove Lemma 5.12. We prove the first statement only, as the other statement
is entirely symmetric.
Let R be a maximally wide rectangle in R (X ), and let v be a vertical line segment withendpoints on the opposite horizontal sides of R, such that none of the other rectangles inR (X ) intersect v. (Such a v exists by the maximality of R, and the independence-propertyof R (X ).) To simplify the argument, take v such that the x- coordinate of v is fractional. Let
a and b be the corners of R, such that a is above and to the right of b. Consider a Manhattan
path P ab = (a = x 1 , . . . , x k = b), where x i ∈ Y , and Y is the solution achieving OPTM (X ). Let
p and q be the unique neighboring points in P ab such that p is to the left of v, and q is to
the right of v. (Observe that p and q are on the same horizontal line, and there is no point of
Y in the interior of [p, q].) Charge the cost of the rectangle (a, b) to the pair (p, q). Remove
R from R (X ), and continue the process. Observe that the pair (p, q) can not be charged
again in the future (since no other rectangle intersects v). Furthermore, the number of pairs
to which the rectangles can be charged is at most OPTM
 − |X |. The claim follows.
Equipped with these observations, we revisit the Small Manhattan Network problem
studied by Gudmundsson et al. [51] and reinterpret some of their results. Gudmundsson etal. show the following.
Theorem 5.13 ([51, Thm. 1]). For every point set X of size n we have OPTM (X ) = O(n log n).
The solution given by Gudmundsson et al. is constructive, i.e. an algorithm that constructs
a Manhattan network with O(n log n) points. We can sketch it as follows: Split X with a verticalline v into two equal subsets, and add the projection of all points in X to v to the solution.
Repeat the process recursively on the subsets of X on the two sides of v. It is straightforward
to verify both that the resulting point set is a valid Manhattan Network solution, and that its
size is O(n log n).

5.5. Consequences for BSTs

115

We observe that an alternative way to prove OPTM (X ) = O(n log n) is simply to note that
OPT(X ) = O(n log n), and apply Theorem 5.10. The upper bound on OPT(X ) follows fromthe observation that a BST access sequence can be served with logarithmic cost per access.
In fact, it is not hard to see that the algorithm given by Gudmundsson et al. corresponds tothe execution trace of a static balanced BST that serves access sequence X . (The vertical line
v corresponds to the root of the tree, that is touched by every access, and the same holds atevery recursive level.)
Gudmundsson et al. further show the following result.
Theorem 5.14 ([51, Thm. 4]). For some point set X of size n we have OPTM (X ) = Ω(n log n).
The instance used to show this is (essentially) the bitwise reversal sequence R n described in § 2.6. Again, the result can be shown in an alternative way, observing that
MIR(R n ) = Ω(n log n) (Theorem 2.21), and using the correspondence of Theorem 5.11.
The correspondence between Small Manhattan Network and BST yields further results
for the Small Manhattan Network problem. In particular, for the BST problem we haveseveral fine-grained bounds on the cost of the optimum solution, such as dynamic finger,
working set, lazy finger, or the traversal bound (§ 2.4). Results of this type give immediate
upper bounds on the complexity of the Small Manhattan Network solution for inputs withparticular structure. (Although some of these structures may seem unusual in a geometricsetting.)
More importantly, by computing the union of the Greedy and Greedy outputs fora point set X we obtain a polynomial time O(1)-approximation for the Small Manhattan
Network problem.
Furthermore, similarly to the result for Flip Diameter, we obtain the following.
Theorem 5.15. For a random point set X of size n, the complexity of the Small Manhattan
Network optimum is Θ(n log n).
Since only the relative ordering of the points matters for Small Manhattan Network (andnot the distances between points), by random point set we mean a point set in general
position whose relative ordering corresponds to a random permutation. Again, the proof
only needs the result of Wilber [106] or its stronger form by Blum et al. (Theorem 2.20) and its
variant that holds for permutations [24].
In § 4.7.1 we showed that for a point set X that avoids an arbitrary constant-size permutation pattern, it holds that MIR(X ) = O(n). This yields the following observation.
Theorem 5.16. Every planar point set that avoids a fixed permutation pattern admits a
Manhattan network of linear complexity.

5.5 Consequences for BSTs
The “flip” and “tree-relax” models of the BST problem (described in § 5.2) give new interpretations of several well-studied concepts in the BST world (e.g. upper and lower bounds). We
list some preliminary observations and questions in this direction.
Upper bounds. For an arbitrary pair (u, v) of points, where u = (u.x, u.y), and v = (v.x, v.y),
let us define the height of (u, v) as h(u, v) = |u.y − v.y|, and the width of (u, v) as w(u, v) =|u.x − v.x|. For an arbitrary monotone tree T , let h(T ) be the sum of heights of all edges in T ,and let w(T ) be the sum of widths of all edges in T .

116

Chapter 5. Binary search trees and rectangulations

Consider a permutation access sequence X ∈ S n and the corresponding treap T on X , aswell as the path P on X (both are defined in § 5.2.2). Consider an edge-flip operation (a → b)
in some tree T 0 that adds the edge (a, b) and removes the edge (r, b), where r is the parent ofb in T 0 . Let the resulting tree be T 00 . We make the following two observations:h(T 0 ) − h(T 00 ) = h(r, b) − h(a, b) = h(r, a) ≥ 1,
0

and

00

w(T ) − w(T ) = w(r, b) − w(a, b) = −w(r, a) ≤ −1.
In words, the total height strictly decreases, and the total weight strictly increases in everyedge-relax operation. We also observe that h(P ) = n − 1 (in the end, every edge is of height 1).
It follows that the quantities H = h(T ) − h(P ) = h(T ) − n + 1, and W = w(P ) − w(T ) are upperbounds on the cost of every algorithm for the Tree Relaxation problem. Given X , both W and
T can be easily computed. The bounds are however, not very strong, as both W and T can beas large as Θ(n 2 ). Nevertheless, for certain highly structured inputs, such as for permutations
close to the sequential access (1, . . . , n), the quantities can yield asymptotically tight bounds
for OPT.
We may conjecture that both bounds can be strengthened, by summing the logarithms of
the heights, respectively weights. More precisely, we define for an arbitrary monotone tree T
the quantitiesX¡¢
H 0 (T ) =log h(u, v) ,(u,v)∈T
0

W (T ) =X¡¢
log w(u, v) .

(u,v)∈T

If T is the initial treap on X , and P is the path on X , then W 0 (P ) is the classical dynamic
finger bound, and H 0 (T ) is (essentially) the classical working set bound [91]. (Working set istypically defined in the literature with respect to the last occurrence of the same element inan access sequence. However, for permutation access sequences it is natural to consider theoccurrence of the nearest successor or predecessor among the already seen elements, whichis exactly what the quantity H 0 (T ) captures.) The bounds W 0 (P ) and H 0 (T ) no longer holdfor every algorithm, but we know that W 0 (P ) is asymptotically matched by Splay [29, 28] andby Greedy [54]. Is H 0 (T ) a valid upper bound on OPT(X )?
A different upper bound on the cost of every Tree Relaxation algorithm can be computedby summing for all vertices in the monotone tree, the distance to the root. (By distance wemean the number of edges on the path to the root.) Again, it can be seen that this quantity
strictly increases with ever edge-flip operation, reaching in the end the value n(n − 1)/2.
New heuristics. The above quantities suggest natural greedy heuristics for Tree Relaxation.
For instance, in every step we may perform the edge-flip that decreases the total edge heightthe most, or that increases the total edge width the most, or that increases the total distancefrom-the-root the most. We leave for further research the question of how efficient (and how
natural) the corresponding BST algorithms are.
In the Rectangulation problem we flip from the all-vertical to the all-horizontal state.
Natural measures of quality for any intermediate state include the total length of remaining
vertical segments, the total length of horizontal segments, or the difference between thetwo quantities. It would seem natural to perform flips that greedily optimize any of thesequantities. It remains open whether the resulting BST algorithms are efficient.

5.5. Consequences for BSTs

117

Interpretations of Greedy. Refer to § 2.7.1 for the description of GeometricGreedy, and let
costGG (X ) denote its cost for input permutation X . Let us define the following algorithms for
the Rectangulation and Tree Relaxation problems.
GreedyRectangle is an algorithm for Rectangulation defined as follows. In the initial
phase, for every i = n, . . . , 1, execute the flips 〈L i , x i 〉, and 〈x i , R i 〉 where L i (R i ) is the leftmost(rightmost) point such that the corresponding flip is valid. After every flip remove as many
vertical segments as possible.
Afterwards, in every step of the algorithm (until we reach an end state), let k be the largest
value such that the horizontal lines with y-coordinates 1, . . . , k are fully covered by segmentsin the current state (P, L). Let q be the highest point in P such that (i) q is visible from below(i.e. the vertical segment between q and the kth horizontal line does not contain any pointsof P in its interior and its interior is not intersected by any horizontal segment in L), and (ii)q is left- or right-extensible. Observe that there must be such a point q, unless we are in an
end state. If q is left- (right-) extensible, then execute the flip 〈L, q〉 (resp. 〈q, R〉), where L(R) is the leftmost (rightmost) point such that the flip is valid. Note that q is either left- orright-extensible, but not both. After the flip, remove as many vertical segments as possible.
Let costGR (X ) denote the cost of GreedyRectangle.
GreedyRelax is an algorithm for Tree Relaxation defined as follows. In every step of the algorithm (until we reach the path monotone tree), let T be the current monotone tree (initiallythe treap on X ). Let r be the nearest node to the root (in graph-distance) that has at least twochildren. Possibly r is the root itself. Let b be the child of r with highest y-coordinate, andlet a be the sibling of b that is its neighbor in the ordering by x-coordinates. If there are twosuch neighboring siblings, let a be the one with higher y-coordinate. Perform the edge-flip(a → b). Let costGT (X ) denote the cost of GreedyRelax.
Theorem 5.17. For every permutation X of size n the quantities costGG (X ), costGR (X ), andcostGT (X ) are equal, up to a constant factor and an additive term O(n).
Proof sketch. costGG (X ) = costGR (X ).
Let Y be the output of Greedy for X . We run GreedyRectangle and maintain a number ofinvariants similar to those in the proof of Theorem 5.4.
I 1 (contiguity): For all i , the union of the horizontal segments at height i form a contiguous horizontal segment, which we denote h i .
I 20 (modified nesting): For all i , denote the left (resp. right) endpoints of h i as `i (resp.
r i ). Two segments h i , h j do not “overhang”, i.e. assuming i < j , either ` j ≥ r i or `i ≥ r j(avoidance) or `i ≤ ` j < r j ≤ r i (containment) holds. Thus, the segments h i for i = 1, . . . , n
induce a tree over {x 1 , . . . , x n } by the visibilities between the segments h i (two horizontal
segments see each other if there is a vertical segment properly intersecting both of them anddoes not touch any of the other horizontal segments). Denote this tree as T , and observe that
it is a monotone tree on X .
I 200 (modified nesting): Let x i 1 , . . . , x i k be the children of x t in the current tree T , sortedby x-coordinate (i.e. x i 1 < · · · < x i k ). We have that the endpoints of the segments h i 1 , . . . , h i k
are not overlapping, and not overhanging the parent segment h t . More precisely, `t ≤ `i 1 ,and r i k ≤ r t , and for all j = 1, . . . , k − 1, we have r i j ≤ `i j +1 . For the root x 1 of the tree, we have
`1 = 0, and r 1 = n + 1.

118

Chapter 5. Binary search trees and rectangulations(Observe that we allow gaps between the siblings.)
I 30 (modified visibility): Let x i 1 , . . . , x i k , x t be defined as before. For j = 1, . . . , k, let us
denote by R j the axis-aligned rectangle with corners (`i j , i j ), (r i j , t ). Let R0 be the rectangle
with corners (`t , t ), (`i 1 , n + 1), and let R j +1 be the rectangle with corners (r i k , n + 1), (r t , t ).
Also for j = 1, . . . , k − 1 let R0j be the rectangle with corners (r i j , t ), (`i j +1 , n + 1).
We have that the interiors of the rectangles R0 , R1 , . . . , R j +1 and R01 , . . . , R0k−1 are notintersected by any segment in L in the current state of GreedyRectangle. Furthermore, thevertical sides of the rectangles R0 , R1 , . . . , R j +1 and R01 , . . . , R0k−1 are either touching themargin, or fully covered by segments in L.
(The novelty is that the gaps between siblings also define empty rectangles.)I 4 (equivalence): For every segment h i , the points in h i ∩ P are exactly those in h i ∩ Y(i.e. what Greedy would add). Since the h i s cover everything in the end, this invariant leads
to the proof.
Finally, a technical invariant.
I 5 (satisfaction): For any i and j such that x i is the ancestor of x j in the current monotone tree, there are no points x ∈ P ∩ h i and y ∈ P ∩ h j , such that x and y form an unsatisfied
pair (with respect to the current point set P ).
We need to show that all invariants hold after the initial phase, and that they are maintained through every flip. The claim follows from invariant I 4 and the observation that
GreedyRectangle terminates, i.e. it reaches a valid end state, since it can always pick a validflip.
We omit the details, except for the maintenance of invariant I 4 .
Consider a step of GreedyRectangle when the first k lines are completed and we flip 〈L, q〉.
Suppose q ∈ h i . By choice of q, we know that x i is the child of x k , and x k , . . . , x 1 form a pathto the root.
If L is at the margin, no new point in P is created. If L is not at the margin, then L.x is
the right boundary of some h j where x j is a sibling of x i to the left of x i . (Either x j and x iare neighboring siblings and there was a gap between them, or there is one sibling betweenthem). Observe that j < i .
To show that I 4 is maintained, we need to prove that: (1) L is part of the Greedy output Y ,and (2) there is no point of Y in the interior of [L, q].
(2) Suppose for contradiction that Greedy would add some point in [L, q]. We use the following observation: running Greedy on the original X produces the same output as running
Greedy on the current P . If we run Greedy on current P and it adds something in [L, q], itmeans that the stair of q contains some point below with x coordinate between L.x and q.x.
But such a point cannot be in the “empty rectangle”, so it must be in an ancestor segment ofx i in T , contradicting I 5 .
(1) Suppose for contradiction that Greedy would not add point L. This would mean thatsome other point is added by Greedy in the rectangle between q and (L.x, r j ) (that would
hide (L.x, r j )). But then I 5 is contradicted, the same way as before.

5.6. Discussion

119

The costGR (X ) = costGT (X ) claim of the theorem follows from the simulation of GreedyRelax by a Rectangulation algorithm, according to Theorem 5.4, and observing that the Rectangulation algorithm maintains the invariants. We omit the details.
We remark that the correspondence to Greedy can be maintained even if we choose thenext flip differently from the above description of GreedyRectangle. As long as we performa flip from a left- or right-extensible point q visible from below (conditions (i) and (ii)), we
need not pick the highest such q. A sufficient condition is that the endpoint of the flip (L or
R) is either a margin point, or a non-margin point that is not visible from below. This yields afamily of algorithms, all producing the same solution as Greedy, but in different orders. We
omit the details.

5.6 Discussion
There exist known connections between rectangulations and BSTs. In particular, slicing
rectangulations have a straightforward BST-representation, which is useful in geometricapplications such as planar point location. For general rectagulations more complex BSTbased representations are known, such as the twin binary tree structure given by Yao, Chen,
Cheng, and Graham [107].
Intriguingly, we are not aware of any connection between these connections and theconnection described in this chapter. Despite the fact that we relate a sequence of rectangulations with a sequence of BSTs, we stress that we do not directly match rectangulations to trees
and flips to rotations. An intermediate rectangulation in our proposed model corresponds
to an abstract state of a BST algorithm, in which some partial structure of the intermediate
trees has been committed to, while other structure is still left undecided. We find it an interesting question, whether the known BST-based representations of rectangulations have any
relevance to the connection discussed here.
A further – as of yet – unrelated correspondence is the one between slicing rectangulations and separable permutations, both counted by the Schröder numbers [2]. (We studied
separable permutations in § 4 as a particularly easy class of access sequences.)
It remains interesting to explore the analogies between various concepts in the BST,
respectively, rectangulation models. For instance, what is the class of BST algorithms that
correspond to rectangulation flip sequences restricted to slicing rectangulations? Whatis the class of algorithms for Rectangulation that correspond to BST algorithms with thesearch-path-only restriction? Which BST algorithms are captured by the tree-relaxation
view (Problem 49)? We expect such questions to yield further insight into the combinatorial
structures in question. Ultimately, however, the value of the presented connections should
be judged depending on whether they lead to progress on the fundamental questions aboutbinary search trees.

\ o [

121

List of open problems
Chapter 1
Problem 1. Can the rotation-distance between two BSTs be computed in polynomial time?

Chapter 2
Problem 2. Given the access frequencies of n elements, can the optimum static BST becomputed in time o(n 2 )?
Problem 3. Given X ∈ [n]m is it possible to compute OPT (X ) in polynomial time? What isthe best approximation computable in polynomial time?
¡¢
Problem 4. Does it hold for all X that OPTsp,root (X ) = O OPTsp (X ) ?
Problem 5. Do any of the following statements hold for all X ?
¡¢• OPTstr,root (X ) = O OPTstr (X ) ,¡¢• OPTstr (X ) = O OPTsp (X ) ,¡¢• OPTsp (X ) = O OPT(X ) .
Problem 6. Is there a strict online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?
Problem 7. Is there a strict online algorithm A such that for all X we have costA (X ) =¡¢O OPTstr,root (X ) ?
Problem 8. Do any of the following statements hold for all X ?
¡¢• OPTstr (X ) = O OPTlen (X ) ,¡¢• OPTlen (X ) = O OPT(X ) .
Problem 9. Is there a lenient online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?
Problem 10. Is there an unlimited online algorithm A such that for all X we have costA (X ) =¡¢O OPT(X ) ?
Problem 11. Is there an o(log n)-competitive strict online algorithm? Is there an o(log log n)competitive lenient or unlimited online algorithm?
Problem 12. Characterize the sequences X ∈ [n]m (or at least X ∈ S m ) for which OPT(X ) =O(m).
Problem 13. Is there a strict online algorithm (with a fixed initial tree of its choice) that has
cost O(n) on every traversal sequence of length n?
Problem 14. Is there a strict online algorithm that matches the lazy finger bound?
Problem 15. Is there a simpler proof that Splay matches the dynamic finger bound?
Problem 16. Does Splay match the lazy finger bound?

122

Chapter 5. Binary search trees and rectangulations

Problem 17.
• Is the cost of Splay (with every initial tree) O(n) for every traversal sequence of lengthn?
• Is the cost of Splay (with some fixed initial tree) o(n log n) for every traversal sequenceof length n?
Problem 18. Is Splay c-competitive for some c = o(log n)?
Problem 19. Is there some c = o(log n), such that the cost of Splay for X is at most c ·OPTstr,root (X )?
Problem 20. Is there some c = o(log n), such that the cost of GreedyFuture for X is at mostc · OPT (X )?
Problem 21. Is there some c = o(log n), such that the cost of GreedyFuture for X is at mostc · OPTstr,root (X )? Even more specifically, can we bound the cost of GreedyFuture as c times
the cost of Splay?
Problem 22. Is the cost of GreedyFuture O(n) for every traversal sequence of length n withevery initial tree?
Problem 23. Is there a strict online algorithm A, and some c = o(log n), such that the cost of
A for every (sufficiently long) input sequence X is at most c times the cost of GreedyFuture
for X ? In particular, is Splay such an algorithm?
¡¢
Problem 24. Prove or disprove that W 1 (X ) = Θ OPT(X ) for all X ∈ [n]m .
¡¢Problem 25. Let T be a balanced BST over [n]. Prove or disprove that W 1T (X ) = Θ OPT(X )for all X ∈ S n .
¡¢Problem 26. Prove or disprove that W 2 (X ) = Θ OPT(X ) for all X ∈ [n]m .
¡¢Problem 27. Prove or disprove that W 1 (X ) = Θ W 2 (X ) for all X ∈ [n]m .
Problem 28. Is costGG (X ) ≤ 43 · OPT(X ) for every X ?
Problem 29. Is the cost of GeometricGreedy asymptotically the same on X and X rot , where
X rot is X rotated by 90 degrees?
Problem 30. Is costGG (X ) ≤ OPT(X ) + O(m) for every X ∈ [n]m ?
Problem 31. Is minimum satisfied superset NP-hard for point sets with one point in every
row?
¡
¢
¡
¢
Problem 32. Prove or disprove that W 1 (X ) = Θ MIR(X ) or W 2 (X ) = Θ MIR(X ) hold for
all X ∈ [n]m .
¡¢Problem 33. Prove or disprove that MIR(X ) = Θ OPT(X ) for all X ∈ [n]m .

Chapter 3
Problem 34. Is the cost of PathBalance m · O(log n) for every (sufficiently long) access sequence X ∈ [n]m ?
Problem 35. Can Theorem 3.20 be strengthened in any of the following ways?
1. Involving in the statement (instead of the sequential access condition) the balance
condition, the access lemma, or some other measure of efficiency.

5.6. Discussion

123

2. Involving in the statement the quantity z (number of zigzags).
3. Relaxing the condition that every transformation must create only few leaves.
4. Relaxing the dependence on the monotonicity condition.
5. Relaxing the bound n o(1) to, say, o(n) or o(|Q|).
Problem 36. Does every weakly depth-halving strict online algorithm satisfy the balance
condition? More strongly, does the access lemma hold for every such algorithm? How about
the sequential access, dynamic finger, lazy finger, and O(1)-competitiveness properties?
Problem 37. Find a natural definition of depth-halving that Splay satisfies, and show that it
implies the access lemma (or at least the balance condition).
Problem 38. Does every algorithm that satisfies the conditions of Theorem 3.4 have any of
the sequential access, dynamic finger, lazy finger, and O(1)-competitiveness properties?
Problem 39. Is there a (natural) non-monotone strict online BST algorithm with access-toroot property that satisfies the balance condition?
Problem 40. If every transformation creates Ω(|P |) leaves, is the balance condition guaranteed? How about the sequential, dynamic finger, lazy finger, O(1)-competitiveness properties?
Problem 41. If every transformation creates Ω(|P | − z) leaves, where z is the number ofzigzags in P , is the balance condition guaranteed? How about the other properties?
Problem 42. Characterize the class of strict online algorithms that satisfy the sequential
access property.
Problem 43. Characterize the class of strict online algorithms that satisfy the dynamic finger,
lazy finger (if any), or O(1)-competitiveness (if any) properties.

Chapter 4
Problem 44. Is there some fixed function f (·) such that for every access sequence X ∈ [n]mthat avoids an arbitrary fixed pattern π ∈ S k , we have OPT(X ) ≤ m · f (k)? More strongly, doessuch an upper bound hold for the cost of some online algorithm?

Problem 45. Is the cost of Greedy, Splay, or some other online BST algorithm O(n) on allV-type permutations of size n with every initial tree?
Problem 46. Find an upper bound on the cost of Splay for every access sequence X ∈ S n thatavoids an arbitrary pattern π ∈ S k .
Problem 47. Is there a sorting algorithm that can sort in linear time every permutation thatavoids an arbitrary fixed pattern?
W
V
Problem 48. Is there some function f (·) such that for every k -avoiding or k -avoiding
sequence X ∈ S n , it holds that OPT(X ) ≤ n · f (k)? More strongly, can we bound the cost of
Splay or Greedy (with or without initial tree) for such inputs?

Chapter 5
Problem 49. Does a converse of Theorem 5.4 hold?
Problem 50. Prove or disprove:¡¢• For any two Rectangulation states R1 and R2 , we have d (R1 , R2 ) = O d 0 (R1 , R2 ) .
¡¢• For any two Rectangulation states R1 and R2 , we have d 0 (R1 , R2 ) = O d 0 (H ,V ) .

125

List of figures
1.1
1.2
1.3
1.4

Binary search example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
BST Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Rotation in a BST. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Treap example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.1 Rotate-once execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Move-to-root execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Splay local operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 GreedyFuture execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Bitwise reversal sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6 Wilber’s first lower bound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7 Wilber’s second lower bound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8 Geometric view of BST. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9 BST algorithms in geometric view. . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.10 Stair in geometric view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.11 Geometric view of initial tree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.12 GeometricGreedy non-optimal example. . . . . . . . . . . . . . . . . . . . . . . .
2.13 GeometricGreedy large approximation error. . . . . . . . . . . . . . . . . . . . . .
2.14 Counterexample to additive error conjecture for Greedy. . . . . . . . . . . . . . .
2.15 Independent rectangles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23
29
31
35
37
38
39
42
43
44
47
48
49
50
51

3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8

Transition graphs of strict online algorithms. . . . . . . . . . . . . . . . . . . . . .
Global view of Splay. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Parameters of the search path and the after-tree. . . . . . . . . . . . . . . . . . .
Proof of Theorem 3.20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Proof of Theorem 3.23. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Depth-halving example 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Depth-halving example 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Depth-halving example 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

54
57
58
66
69
72
72
72

4.1 Pattern avoidance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Tilted grid permutation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
W
4.3-type permutation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Simple permutation and block decomposition. . . . . . . . . . . . . . . . . . . .
4.5 Preorder sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.6 Tensor product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.7 Hidden element in geometric view. . . . . . . . . . . . . . . . . . . . . . . . . . .
4.8 Proof of Theorem 4.12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.9 Counterexample to naïve approach. . . . . . . . . . . . . . . . . . . . . . . . . . .
4.10 Proof of Theorem 4.13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.11 Proof of Lemma 4.15 and 4.16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.12 Proof of Lemma 4.18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.13 Proof of Lemma 4.20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76
77
78
80
80
81
82
84
85
85
87
89
94

126

List of figures

4.14 Proof of Lemma 4.29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.15 Examples comparing pattern-avoidance and other bounds. . . . . . . . . . . . . 96
5.1
5.2
5.3
5.4
5.5
5.6

Rectangulation examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Rectangulation problem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
A sequence of valid flips in a rectangulation. . . . . . . . . . . . . . . . . . . . . . 104
Tree relaxation problem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
A sequence of edge-relaxations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
A-rotate and A-flip operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

127

Bibliography[1]

Eyal Ackerman, Michelle M. Allen, Gill Barequet, Maarten Löffler, Joshua Mermelstein,
Diane L. Souvaine, and Csaba D. Tóth. “The Flip Diameter of Rectangulations andConvex Subdivisions”. In: LATIN 2014, pp. 478–489 (pages 99–102, 110, 112, 113).

[2]

Eyal Ackerman, Gill Barequet, and Ron Y. Pinter. “A bijection between permutations
and floorplans, and its applications”. In: Discrete Applied Mathematics 154.12 (2006),
pp. 1674 –1684 (pages 100, 119).

[3]

Eyal Ackerman, Gill Barequet, and Ron Y. Pinter. “On the number of rectangulations ofa planar point set”. In: Journal of Combinatorial Theory, Series A 113.6 (2006), pp. 1072
–1091 (pages 99, 100).

[4]G. M. Adelson-Velskiı̆ and E. M. Landis. “An algorithm for organization of information”. In: Dokl. Akad. Nauk SSSR 146 (1962), pp. 263–266 (page 8).

[5]Oswin Aichholzer, Wolfgang Mulzer, and Alexander Pilz. “Flip Distance Between
Triangulations of a Simple Polygon is NP-Complete”. In: Discrete & Computational
Geometry 54.2 (2015), pp. 368–389 (page 9).

[6]

Susanne Albers and Marek Karpinski. “Randomized splay trees: Theoretical andexperimental results”. In: Information Processing Letters 81.4 (2002), pp. 213 –221
(page 26).

[7]

Brian Allen and Ian Munro. “Self-Organizing Binary Search Trees”. In: J. ACM 25.4
(Oct. 1978), pp. 526–535 (pages 3, 23, 29).

[8]

Sanjeev Arora, Elad Hazan, and Satyen Kale. “The Multiplicative Weights Update
Method: a Meta-Algorithm and Applications”. In: Theory of Computing 8.6 (2012),
pp. 121–164 (page 24).

[9]David Arthur. “Fast Sorting and Pattern-avoiding Permutations”. In: ANALCO 2007,
pp. 169–174 (page 88).

[10]

R. Balasubramanian and Venkatesh Raman. “Path Balance Heuristic for Self-Adjusting
Binary Search Trees”. In: FSTTCS 1995, pp. 338–348 (pages 63, 68).

[11]

Jérémy Barbay and Gonzalo Navarro. “On compressing permutations and adaptive
sorting”. In: Theoretical Computer Science 513 (2013), pp. 109 –123 (pages 79, 87).

[12]

Jon Louis Bentley. “Multidimensional Binary Search Trees Used for Associative Searching”. In: Commun. ACM 18.9 (Sept. 1975), pp. 509–517 (page 100).

[13]

Jon Louis Bentley and Andrew Chi-Chih Yao. “An almost optimal algorithm for unbounded searching”. In: Information Processing Letters 5.3 (1976), pp. 82 –87 (page 27).

[14]

Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. Computational
Geometry: Algorithms and Applications. 3rd ed. Springer-Verlag, 2008 (page 100).

[15]

Daniel Bienstock and Ervin Györi. “An Extremal Problem on Sparse 0-1 Matrices”. In:
SIAM J. Discrete Math. 4.1 (1991), pp. 17–27 (page 83).

[16]

Avrim Blum, Shuchi Chawla, and Adam Kalai. “Static Optimality and Dynamic Searchoptimality in Lists and Trees”. In: SODA 2002, pp. 1–8 (pages 25, 26, 37).

128

BIBLIOGRAPHY[17]

Miklós Bóna. “A Survey of Stack-Sorting Disciplines”. In: Electr. J. Comb. on.2 (2002)(page 79).

[18]

Miklós Bóna. Combinatorics of Permutations. CRC Press, Inc., 2004 (page 75).

[19]

Prosenjit Bose, Jonathan F Buss, and Anna Lubiw. “Pattern matching for permutations”. In: Information Processing Letters 65.5 (1998), pp. 277–283 (pages 75, 80).

[20]

Prosenjit Bose, Karim Douïeb, John Iacono, and Stefan Langerman. “The Power and
Limitations of Static Binary Search Trees with Lazy Finger”. In: ISAAC 2014, pp. 181–
192 (pages 26, 28, 31).

[21]

Robert Brignall. “A Survey of Simple Permutations”. In: CoRR abs/0801.0963 (2008)(pages 80, 81, 96).

[22]

Marie-Louise Bruner and Martin Lackner. “The computational landscape of permutation patterns”. In: CoRR abs/1301.0340 (2013) (page 75).

[23]

Parinya Chalermsook, Mayank Goswami, László Kozma, Kurt Mehlhorn, and Thatchaphol
Saranurak. “Greedy Is an Almost Optimal Deque”. In: WADS 2015. Preprint URL : http://arxiv.org/abs/1506.08319, pp. 152–165 (pages 84, 88).

[24]

Parinya Chalermsook, Mayank Goswami, László Kozma, Kurt Mehlhorn, and Thatchaphol
Saranurak. “Pattern-Avoiding Access in Binary Search Trees”. In: FOCS 2015. Preprint
URL : http://arxiv.org/abs/1507.06953, pp. 410–423 (pages ix, 37, 75, 84, 85, 87,
96, 115).

[25]

Parinya Chalermsook, Mayank Goswami, László Kozma, Kurt Mehlhorn, and Thatchaphol
Saranurak. “Self-Adjusting Binary Search Trees: What Makes Them Tick?” In: ESA
2015. Preprint URL : http://arxiv.org/abs/1503.03105, pp. 300–312 (pages ix, 48,
62).

[26]

Parinya Chalermsook, Mayank Goswami, László Kozma, Kurt Mehlhorn, and Thatchaphol
Saranurak. “The landscape of bounds for binary search trees”. In: CoRR abs/1603.04892(2016). Preprint URL : http://arxiv.org/abs/1603.04892 (pages 27, 28, 32, 33, 89,
90, 96, 97).

[27]

R. Chaudhuri and H. Höft. “Splaying a Search Tree in Preorder Takes Linear Time”. In:
SIGACT News 24.2 (Apr. 1993), pp. 88–93 (pages 32, 77).

[28]

R. Cole. “On the Dynamic Finger Conjecture for Splay Trees. Part II: The Proof”. In:
SIAM Journal on Computing 30.1 (2000), pp. 44–85 (pages 30, 116).

[29]

Richard Cole, Bud Mishra, Jeanette Schmidt, and Alan Siegel. “On the Dynamic Finger
Conjecture for Splay Trees. Part I: Splay Sorting Log n-Block Sequences”. In: SIAM J.
Comput. 30.1 (Apr. 2000), pp. 1–43 (pages 30, 116).

[30]

Thomas H. Cormen, Clifford Stein, Ronald L. Rivest, and Charles E. Leiserson. Introduction to Algorithms. 2nd. McGraw-Hill Higher Education, 2001 (pages 3, 77,
87).

[31]

Erik D. Demaine, Dion Harmon, John Iacono, Daniel M. Kane, and Mihai Pǎtraşcu.
“The geometry of binary search trees”. In: SODA 2009, pp. 496–505 (pages 5, 13, 34, 35,
41, 42, 45, 47, 49–52, 75, 99, 108, 113, 114).

[32]

Erik D. Demaine, Dion Harmon, John Iacono, and Mihai Pǎtraşcu. “Dynamic Optimality - Almost”. In: SIAM J. Comput. 37.1 (2007), pp. 240–251 (pages 13, 14, 37, 38,
40).

[33]

Erik D. Demaine, John Iacono, Stefan Langerman, and Özgür Özkan. “Combining
Binary Search Trees”. In: ICALP 2013, pp. 388–399 (pages 26, 90).

BIBLIOGRAPHY

129

[34]

Jonathan C. Derryberry, Daniel D. Sleator, and Chengwen C. Wang. “A lower boundframework for binary search trees with rotations”. In: Tech. Rep. CMU-CS-05-187,
Carnegie Mellon Univ. (2005) (pages 5, 50).

[35]

P. Diaconis, R. Graham, and R.L. Graham. Magical Mathematics: The Mathematical
Ideas that Animate Great Magic Tricks. Princeton University Press, 2011 (page 78).

[36]

C.H.J. Edwards. The Historical Development of the Calculus. Springer Study Edition.
Springer New York, 2012 (page 1).

[37]

Amr Elmasry. “On the sequential access theorem and deque conjecture for splay
trees”. In: Theoretical Computer Science 314.3 (2004), pp. 459 –466 (page 31).

[38]

David Eppstein, Elena Mumford, Bettina Speckmann, and Kevin Verbeek. “AreaUniversal and Constrained Rectangular Layouts”. In: SIAM J. Comput. 41.3 (2012),
pp. 537–564 (page 100).

[39]

Vladmir Estivill-Castro and Derick Wood. “A Survey of Adaptive Sorting Algorithms”.
In: ACM Comput. Surv. 24.4 (Dec. 1992), pp. 441–476 (page 87).

[40]

Stefan Felsner. Rectangle and Square Representations of Planar Graphs , in: Pach, J.,
Thirty Essays on Geometric Graph Theory. Algorithms and combinatorics. Springer
New York, 2012, pp. 213–248 (page 100).

[41]

Jacob Fox. “Stanley-Wilf limits are typically exponential”. In: CoRR abs/1310.8378(2013) (page 84).

[42]

Kyle Fox. “Upper Bounds for Maximally Greedy Binary Search Trees”. In: WADS 2011,
pp. 411–422 (pages 36, 59).

[43]

Michael L. Fredman. “How good is the information theory bound in sorting?” In:
Theoretical Computer Science 1.4 (1976), pp. 355 –361 (page 87).

[44]

Zoltán Füredi. “The maximum number of unit distances in a convex n-gon”. In: J.
Comb. Theory, Ser. A 55.2 (1990), pp. 316–320 (page 83).

[45]

Zoltán Füredi and Péter Hajnal. “Davenport-Schinzel theory of matrices”. In: Discrete
Mathematics 103.3 (1992), pp. 233 –251 (pages 76, 84).

[46]

Martin Fürer. “Randomized Splay Trees”. In: Proceedings of the Tenth Annual ACMSIAM Symposium on Discrete Algorithms. SODA 1999, pp. 903–904 (page 26).

[47]

George F. Georgakopoulos. “Chain-splay trees, or, how to achieve and prove loglogNcompetitiveness by splaying”. In: Inf. Process. Lett. 106.1 (2008), pp. 37–43 (page 40).

[48]

George F. Georgakopoulos and David J. McClurkin. “Generalized Template Splay: A
Basic Theory and Calculus”. In: Comput. J. 47.1 (2004), pp. 10–19 (pages 32, 36, 55, 57,
62, 68).

[49]

Sally Goldman, Adam Kalai, and Santosh Vempala. “Learning Theory 2003 Efficientalgorithms for online decision problems”. In: Journal of Computer and System Sciences
71.3 (2005), pp. 291 –307 (page 26).

[50]

Navin Goyal and Manoj Gupta. “On Dynamic Optimality for Binary Search Trees”. In:
CoRR abs/1102.4523 (2011) (page 36).

[51]

Joachim Gudmundsson, Oliver Klein, Christian Knauer, and Michiel Smid. “Small
manhattan networks and algorithms for the earth mover’s distance”. In: EWCG 2007.
2007, pp. 174–177 (pages 101, 113–115).

[52]

Dion Harmon. “New Bounds on Optimal Binary Search Trees”. PhD thesis. Massachusetts Institute of Technology, 2006 (pages 41, 50, 101, 113, 114).

130

BIBLIOGRAPHY[53]John Iacono. “In Pursuit of the Dynamic Optimality Conjecture”. English. In: SpaceEfficient Data Structures, Streams, and Algorithms. Vol. 8066. Lecture Notes in Computer Science. Springer Berlin Heidelberg, 2013, pp. 236–250 (pages 4, 19, 21, 24,
39).

[54]

John Iacono and Stefan Langerman. “Weighted dynamic finger in binary search trees”.
In: SODA 2016. Chap. 49, pp. 672–691 (pages 26, 28, 35, 36, 90, 116).

[55]

Karel Culik II and Derick Wood. “A note on some tree similarity measures”. In: Information Processing Letters 15.1 (1982), pp. 39 –42 (page 8).

[56]

S. Kitaev. Patterns in Permutations and Words. Monographs in Theoretical Computer
Science. An EATCS Series. Springer, 2011 (page 75).

[57]

Martin Klazar. “The Füredi-Hajnal Conjecture Implies the Stanley-Wilf Conjecture”.
English. In: Formal Power Series and Algebraic Combinatorics. Ed. by Daniel Krob,
AlexanderA. Mikhalev, and AlexanderV. Mikhalev. Springer Berlin Heidelberg, 2000,
pp. 250–255 (page 76).

[58]

Donald E. Knuth. “Optimum binary search trees”. In: Acta Informatica 1.1 (1971),
pp. 14–25 (page 12).

[59]

Donald E. Knuth. The Art of Computer Programming, Volume 1 (3rd Ed.): Fundamental
Algorithms. Redwood City, CA, USA: Addison Wesley Longman Publishing Co., Inc.,
1997 (page 75).

[60]

Donald E. Knuth. The Art of Computer Programming, Volume 3: (2nd Ed.) Sorting and
Searching. 1998 (pages 1, 12, 87).

[61]

Donald E. Knuth. The Art of Computer Programming, Volume I: Fundamental Algorithms. Addison-Wesley, 1968 (page 75).

[62]

László Kozma and Thatchaphol Saranurak. “Binary search trees and rectangulations”.
In: CoRR abs/1603.08151 (2016). Preprint URL : http : / / arxiv . org / abs / 1603 .
08151 (page ix).

[63]

Marc J. van Kreveld and Bettina Speckmann. “On rectangular cartograms”. In: Comput. Geom. 37.3 (2007), pp. 175–187 (page 100).

[64]

E. Kushilevitz and N. Nisan. Communication Complexity. Cambridge University Press,
2006 (page 100).

[65]

André E. Kézdy, Hunter S. Snevily, and Chi Wang. “Partitioning permutations into
increasing and decreasing subsequences”. In: Journal of Combinatorial Theory, Series
A 73.2 (1996), pp. 353 –359 (page 79).

[66]

Christos Levcopoulos and Ola Petersson. “Sorting shuffled monotone sequences”. In:
SWAT 1990. Ed. by John R. Gilbert and Rolf Karlsson, pp. 181–191 (pages 79, 87).

[67]

Anna Lubiw and Vinayak Pathak. “Flip distance between two triangulations of a point
set is NP-complete”. In: Comput. Geom. 49 (2015), pp. 17 –23 (page 9).

[68]

Joan M. Lucas. “Canonical forms for competitive binary search tree algorithms”. In:
Tech. Rep. DCS-TR-250, Rutgers University (1988) (pages 16, 34).

[69]

Heikki Mannila. “Measures of Presortedness and Optimal Sorting Algorithms (Extended Abstract)”. In: ICALP 1984, pp. 324–336 (page 87).

[70]

Adam Marcus and Gábor Tardos. “Excluded permutation matrices and the StanleyWilf conjecture”. In: Journal of Combinatorial Theory, Series A 107.1 (2004), pp. 153–160 (pages 76, 84).

BIBLIOGRAPHY

131

[71]

Kurt Mehlhorn. Data Structures and Algorithms. Monographs in Theoretical Computer Science - An Eatcs Series v. 1. Springer-Verlag, 1984 (pages 32, 87).

[72]

Kurt Mehlhorn. “Nearly optimal binary search trees”. In: Acta Informatica 5.4 (1975),
pp. 287–295 (page 12).

[73]

Dinesh P. Mehta and Sartaj Sahni. Floorplan Representation in VLSI, in: Handbook Of
Data Structures And Applications. Chapman & Hall/CRC, 2004 (page 100).

[74]

Joseph S. B. Mitchell. “Guillotine Subdivisions Approximate Polygonal Subdivisions:
A Simple Polynomial-Time Approximation Scheme for Geometric TSP, k-MST, andRelated Problems”. In: SIAM J. Comput. 28.4 (Mar. 1999), pp. 1298–1309 (page 100).

[75]

Alistair Moffat and Ola Petersson. “An Overview of Adaptive Sorting”. In: AustralianComputer Journal 24.2 (1992), pp. 70–77 (page 87).

[76]

J. Ian Munro. “On the Competitiveness of Linear Search”. English. In: ESA 2000,
pp. 338–345 (pages 34, 49).

[77]

J. Ian Munro and Philip M. Spira. “Sorting and Searching in Multisets”. In: SIAM J.
Comput. 5.1 (1976), pp. 1–8 (page 87).

[78]

Gabriel Nivasch. “Improved bounds and new techniques for Davenport–Schinzel
sequences and their generalizations”. In: J. ACM 57.3 (2010) (page 84).

[79]

Igor Pak. “History of Catalan numbers”. In: arXiv preprint arXiv:1408.5711 (2014)(pages 1, 7).

[80]Seth Pettie. “Applications of Forbidden 0-1 Matrices to Search Tree and Path Compressionbased Data Structures”. In: SODA 2010, pp. 1457–1467 (pages 31, 48, 84).

[81]

Seth Pettie. “Sharp Bounds on Formation-free Sequences”. In: SODA 2015, pp. 592–
604 (page 84).

[82]

Seth Pettie. “Splay Trees, Davenport-Schinzel Sequences, and the Deque Conjecture”.
In: SODA 2008, pp. 1115–1124 (pages 48, 84).

[83]

Alexander Pilz. “Flip distance between triangulations of a planar point set is APXhard”. In: Comput. Geom. 47.5 (2014), pp. 589–604 (page 9).

[84]

Lionel Pournin. “The diameter of associahedra”. In: arXiv preprint arXiv:1207.6296(2014) (page 9).

[85]Vaughan R. Pratt. “Computing Permutations with Double-ended Queues, Parallel
Stacks and Parallel Queues”. In: STOC 1973, pp. 268–277 (page 75).

[86]

James H. Schmerl and William T. Trotter. “Critically indecomposable partially ordered sets, graphs, tournaments and other binary relational structures”. In: Discrete
Mathematics 113.1–3 (1993), pp. 191 –205 (page 81).

[87]

Raimund Seidel and Udo Adamy. “On the Exact Worst Case Query Complexity of
Planar Point Location”. In: J. Algorithms 37.1 (2000), pp. 189–217 (page 100).

[88]

Raimund Seidel and Cecilia R. Aragon. “Randomized Search Trees”. In: Algorithmica
16.4/5 (1996), pp. 464–497 (pages 9, 32).

[89]

Rodica Simion and Frank W. Schmidt. “Restricted Permutations”. In: European Journalof Combinatorics 6.4 (1985), pp. 383 –406 (page 75).

[90]

Daniel D. Sleator and Robert E. Tarjan. “Amortized Efficiency of List Update andPaging Rules”. In: Commun. ACM 28.2 (Feb. 1985), pp. 202–208 (page 4).

[91]

Daniel D. Sleator and Robert E. Tarjan. “Self-adjusting Binary Search Trees”. In: J. ACM
32.3 (July 1985), pp. 652–686 (pages 3, 28, 30–34, 53, 61, 68, 116).

132

BIBLIOGRAPHY[92]

Daniel D. Sleator, Robert E. Tarjan, and William P. Thurston. “Rotation distance,
triangulations, and hyperbolic geometry”. In: J. Amer. Math. Soc. 1.3 (1988), pp. 647–
681 (page 9).

[93]

Sloane N. J. A. The On-Line Encyclopedia of Integer Sequences. http://oeis.org.
Sequence A000108 (page 7).

[94]

Sloane N. J. A. The On-Line Encyclopedia of Integer Sequences. https://oeis.org/

A006318. Sequence A006318 (pages 81, 100).
[95]

Sloane N. J. A. The On-Line Encyclopedia of Integer Sequences. https://oeis.org/

A001181. Sequence A001181 (page 100).
[96]

Richard P. Stanley. Catalan Numbers. Cambridge University Press, 2015 (pages 7, 8).

[97]Richard P. Stanley. Catalan Numbers. Cambridge University Press, 2015 (page 9).

[98]Richard P. Stanley. Enumerative Combinatorics. Volume 2. Cambridge studies inadvanced mathematics. Cambridge University Press (page 7).

[99]

Ashok Subramanian. “An Explanation of Splaying”. In: J. Algorithms 20.3 (1996),
pp. 512–525 (pages 36, 55–57, 62, 68, 73).

[100]

R. Sundar. “Twists, turns, cascades, deque conjecture, and scanning theorem”. In:
FOCS 1989, pp. 555–559 (page 31).

[101]

Robert Endre Tarjan. “Sequential access in splay trees takes linear time”. In: Combinatorica 5.4 (1985), pp. 367–378 (page 31).

[102]

Robert Endre Tarjan. “Sorting Using Networks of Queues and Stacks”. In: J. ACM 19.2
(Apr. 1972), pp. 341–346 (page 75).

[103]

Vincent Vatter. “Permutation classes”. In: CoRR abs/1409.5159 (2014) (page 75).

[104]

Jean Vuillemin. “A Unifying Look at Data Structures”. In: Commun. ACM 23.4 (Apr.
1980), pp. 229–239 (page 9).

[105]

Chengwen C. Wang, Jonathan C. Derryberry, and Daniel D. Sleator. “O(Log Log N)competitive Dynamic Binary Search Trees”. In: SODA 2006, pp. 374–383 (page 40).

[106]

R. Wilber. “Lower Bounds for Accessing Binary Search Trees with Rotations”. In: SIAM
Journal on Computing 18.1 (1989), pp. 56–67 (pages 13, 16, 37–39, 115).

[107]

Bo Yao, Hongyu Chen, Chung-Kuan Cheng, and Ronald Graham. “Floorplan Representations: Complexity and Connections”. In: ACM Trans. Des. Autom. Electron. Syst.
8.1 (Jan. 2003), pp. 55–80 (pages 81, 100, 119).