• No results found

Monotonicity and locality

In 1995 Balasubramanian and Raman [10] showed the upper bound of m·O³log n ·log log log nlog log n ´ on 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.3almost matches

this bound.

First we observe that since the after-tree in PathBalance is a balanced BST, the number of 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Ω(logn). Thus, we cannot directly apply Theorem3.4. Nevertheless, the techniques developed in §3.3can be used to show the following result for PathBalance.

Lemma 3.15. |P | ≤ Φ(P) − Φ0(P ) + O³¡1 + log|P|¢¡1 + logw (x)W ¢´.

Proof. We decompose P into sets P0to Pc, where Pk contains the nodes of depth k in the after-tree. Each Pkis subtree-disjoint. An application of Theorem3.9completes the proof.

Theorem 3.16. PathBalance has cost at most m · O¡ logn · loglogn¢ when accessing X = (x1, . . . , xm) ∈ [n]m.

Proof. We choose the uniform weight function: w (a) = 1 for all a ∈ [n]. Let cibe the cost of accessing xi, for 1 ≤ i ≤ m, and let C =P1≤i ≤mcibe the total cost of accessing X = (x1, . . . , xm). Note thatQ

ici≤ (C /m)m. SinceΦ(T ) ≤ n logn for any BST T over [n], we have

C ≤ n logn + X 1≤i ≤m

O¡¡1 + logci¢¡1 + logn¢¢ = m ·O(logn) · log(C/m)

by Lemma3.15. Assume C = K · m logn for some K . Then K = O(1) + O(1) · log(K · logn) and hence K = O(loglogn).

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 the case 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ΓAcan be

partitioned into w monotone sets. By Lemma3.13, this is equivalent with the condition that for 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 is local 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 mono- tone sets. As a corollary of Lemma3.13, A contains a sequence of elements x1, x2, . . . , xw +1 such that either (a) x < x1< · · · < xw +1, or (b) xw +1< xw< · · · < x1< x holds, and xi +1is a descendant of xifor all i . Assume that case (a) holds, the other case is symmetric.

Let i0be the first index for which xw +1∈ Pi0. From the (window-size) condition we know that Pi0contains at most w elements, and thus there exists some index j < w + 1 such that

xj ∉ Pi

0

. As xj is a descendant of xw +1in the search path P , it was on some path Pi

00

for

i00< i0, and due to the (no-revisit) condition it will not be on another path in the future. Thus, it is impossible that xjbecomes an ancestor of xw +1, so no local algorithm can create Q from

P , a contradiction.

(ii) We give an explicit local algorithm

A

that creates the tree Q from the path P . As in Lemma3.13, we decompose Q into Q>x= R1∪ · · · ∪RwRand Q<x= L1∪ · · · ∪LwLwhere Ri (respectively Li) denote the set of elements whose search path contains exactly i edges of type

(resp. of type). In other words, Riand Lidenote the set of elements with right-depth, resp. left-depth equal to i . Let L0= R0= {x}. Denote as P = (x1, x2, . . . , xk= x) the search path for x, i.e., x1is the root of the current tree and xj +1is a child of xj. For any j , let tj(Ri) be the element in Ri∩ {xj, . . . , xk} with minimal index, and define tj(Li) analogously.

For any node s of Q, let the first right ancestor FRA(s) be the first ancestor of s in Q that is 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 = {xj, . . . , xk}, consider any i ≥ 1, and let s = tj(Ri). (i) If s is a right child in Q then its parent belongs to S ∩ Ri −1.

(ii) If s is a left child in Q then FRA(s) 6∈ S and FLA(s) = tj(Ri −1).

(iii) If s is a right child and FRA(s) ∈ S then all nodes insubtreeQ(s) belong to S. (iv) If FRA(s) ∈ S then FRA(tj(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 = (x1, x2, . . . , xk= x). Assume that we have reached node xj. Let S = {xj, . . . , xk} (the already seen nodes). We maintain an active set A of nodes. It consists of all tj(Ri) such that FRA(tj(Ri)) 6∈ S and all tj(Li) such that FLA(tj(Li)) 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 that parent(y) ∈ S. Then y must be a right child (since, otherwiseparent(y) ∉ S, by definition of

A). Furthermore, FRA(y) 6∈ S. Since FRA(y) = FRA(parent(y)), it follows thatparent(y) is also active.

By part (iv) of Lemma3.18, there are indices` and r such that exactly the nodes tj(L`) to

tj(Rr) are active. When j = k, only tj(R0) = tj(L0) = x is active. We maintain the active nodes

in a path P0. By the preceding paragraph, the nodes in S \ A form subtrees of Q. We attach them to P0at the appropriate places and we also attach P0to the initial segment x1to xj −1of

P .

What are the actions required when we move from xj to xj −1? Assume xj −1> x and let

S0= {x

j −1, . . . , xk}. Also assume that xj −1belongs to Riand hence xj −1= tj −1(Ri). For all` 6= i,

tj(R`) = tj −1(R`). Notice that xj −1is larger than all elements in S and hence FRA(xj −1) 6∈ S0. Thus xj −1becomes an active element and the tj(R`) for` < i are active and will stay active. All tj(R`),` > i, with FRA(tj(R`)) = xj −1will become inactive and part of the subtree of Q formed by the inactive nodes between tj(Ri) and xj −1. We change the path P0accordingly.

Verifying that the algorithm satisfies conditions (i)-(v) of a local algorithm is straightfor- ward: the path P0is 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 Liand Ri), and once a node becomes inactive (leaves P0), it never becomes active again.