• No results found

Sufficient conditions for efficiency

In this section we give conditions on the transition functionΓAof 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 ΓAof

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 Figure3.3.

Let z denote the number of edges on the search path connecting nodes on different sides of 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, respectivelyedges on the path from the root to v. We will consider left- and right-depth mostly in the after-tree. We illustrate these parameters (and others) in Figure3.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) and the 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 for every 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 T0 be the tree after the re-arrangement. (Remember, that the search path P and the after-tree Q are subtrees of T , respectively, T0.) In the following, we writesubtreeT(x) for the subtree of x in T , and we writesubtreeT0(x), for

the subtree of x in T0.

The main task in proving Theorem3.4is to relate the potential differenceΦT− ΦT0 to

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 ΦT(X ) =Pa∈Xlog¡w¡subtreeT(a)¢¢.

Again, observe that the potential change is determined only by the nodes on the search path, i.e.

ΦT− ΦT0= ΦT(P ) − ΦT0(P ).

Further, observe that we can argue about disjoint sets of nodes separately. Lemma 3.5. Let P be the search path to x. Let X =Sk

i =1Xiwhere the sets Xi are pairwise disjoint. ThenΦT(X ) − ΦT0(X ) =Pk

i =1 ¡

ΦT(Xi) − ΦT0(Xi)¢.

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 Figure3.3for illustra- tion.

A set of nodes X ⊆ P is subtree-disjoint ifsubtreeT0(a) ∩subtreeT0(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 (a0, a1, . . . , 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= {ai, ai +1} if aiand ai +1lie on different sides of x, and let Zi= ; otherwise. The zigzag set ZPis defined as ZP=SiZi. In words, the number of non-empty sets Zi is exactly the number of zigzags in the search path, and the cardinality of ZPis the number 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 have the 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 s0(x) for

w¡

subtreeT0(x)¢. Further, we use the standard notation for open, closed, and mixed intervals

of 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

w s(x)+ ΦT(X ) − ΦT0(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) − ΦT0(X≥x) + 4 · log W w s(x).

A symmetric statement holds for X<x. We only give the proof for X≥x.

Denote X≥x by Y = {a0, a1, . . . , aq} where x = a0< . . . < aq. Before the access, x is a descendant of a0, a0 is a descendant of a1, and so on. LetsubtreeT(a0) = [c,d]. Then

[x, a0] ⊆ [c,d] and d < a1. Let w0= w s(a0). For j ≥ 0, define σj as the largest index` such that w¡[c, a`]¢ ≤ 2j

· w0. Thenσ0= 0 since weights are positive and [c, d] is a proper subset of

[c, a1]. The set {σ0, . . .} contains at most

l logwW

0

m

distinct elements. It contains a0and aq. Now we bound from above the number of indices i with the propertyσj≤ i < σj +1. We call such an element aiheavy if w s0(ai) > 2j −1· w0. There can be at most 3 heavy elements

as otherwise

w¡[c, aj +1]¢ ≥ X σj≤k<σj +1

a contradiction.

Next we count the number of light (a.k.a. non-heavy) elements. For every light element

ai, we have w s0(ai) ≤ 2j −1· w0. We also have w s(ai +1) ≥ w¡[c, ai +1]¢ > w¡[c, aσj]¢ and thus

w s(ai +1) > 2j· w0by the definition ofσj. Thus the ratio ri=w s(aw s0(ai +1i))≥ 2 whenever ai is a light element. Moreover, for any i = 0,..., q − 1 (for which aiis not necessarily light), we have

ri≥ 1. Thus,

2number of light elements≤ Y

0≤i ≤q−1 ri= Ã Y 0≤i ≤q w s(ai) w s0(ai) ! ·w s 0(aq) w0 .

So the number of light elements is at mostΦT(Y ) − ΦT0(Y ) + logWw 0.

Putting the bounds together, and denoting L = logwW

0, we obtain

|Y | ≤ 1 + 3(dLe − 1) + ΦT(Y ) − ΦT0(Y ) + L ≤ 1 + 4L + ΦT(Y ) − ΦT0(Y ).

We look next at monotone sets. We first make a simple observation, then we bound the contribution 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} is monotone, thensubtreeT0(a) ⊆subtreeT(b).

Proof. Clearly [x, b] ⊆subtreeT(b). The smallest item insubtreeT0(a) is larger than x, and

since a and b have the same right-depth, b is larger than all elements insubtreeT0(a).

Lemma 3.8. Let X be a monotone set of nodes. Then Φ(X ) − Φ0(X ) + log W

w (x)≥ 0.

Proof. We order the elements in X = {a1, . . . , aq} such that aiis a proper descendant of ai +1 in the search path for all i . ThensubtreeT0(ai) ⊆subtreeT(ai +1) by monotonicity, and hence

Φ(X ) − Φ0(X ) = log

Q

a∈Xw s(a) Q

a∈Xw s0(a)= log

w s(a1) w s0(aq)+ q−1 X i =1 logw s(ai +1) w s0(ai) .

The second sum is nonnegative. ThusΦ(X ) − Φ0(X ) ≥ logw sw s(a0(a1)q)≥ log

w (x) W .

Theorem 3.9. Suppose that for every access to an element x, we can partition the elements on the search path P into k subtree-disjoint sets D1to Dk and` monotone sets M1to M`. Then

X i ≤k

|Di| ≤ ΦT(S) − ΦT0(S) + 2k + (8k + `) · log W w (x).

The proof of Theorem3.9follows immediately from Lemma3.6and3.8.

Finally, we look at zigzag sets. We view the transformation as a two-step process, i.e. we first 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 + logw s(x)W ´.

Proof. Because x becomes the root, and ancestor relationships are otherwise preserved,

subtreeT0(a) =subtreeT(a) ∩ (−∞, x) if a < x, andsubtreeT0(a) =subtreeT(a) ∩ (x,∞) if a > x. We first deal with a single zigzag.

3.3. Sufficient conditions for efficiency 61

Lemma 3.11. 2 ≤ Φ(Zi) − Φ0(Zi) + logw s(aw s(ai +1i)).

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 ai> x and ai +1< x, as the other case is symmetric. Let a0 be the left ancestor of a

i +1in P and let a00be the right ancestor of ai in P . If these elements do not exist, we set the values to −∞ and +∞, respectively. Let W1= w¡(a0, 0)¢, W2= w¡(0, a00)¢, and W0= w¡(ai +1, 0)¢. In T we have w s(ai) = W0+w(x)+W2and w s(ai +1) =

W1+ w(x) + W2, and in T0we have w s0(ai) = W2and w s0(ai +1) = W1.

Thus

Φ(Zi) − Φ0(Zi) + log

W1+ w(x) + W2 W0+ w(x) + W2

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

+ logW1+ w(x) + W2

W0+ w(x) + W2

≥ 2 · log(W1+ W2) − logW1− logW2

≥ 2,

since (W1+ W2)2≥ 4W1W2for all W1,W2.

Let Zeven(Zodd) be the union of the Zisets with even (odd) indices. One of the two sets has cardinality at least|ZP|

2 . Assume that it is the former, the other case is symmetric. We sum

the statement of the claim over all i in Zevenand obtain

X i ∈Zeven µ Φ(Zi) − Φ0(Zi) + log w s(ai +1) w s(ai) ¶ ≥ 2 · |Zeven| ≥ |ZP| . The elements in ZP\ Zevenform two monotone sets and hence

Φ(ZP\ Zeven) − Φ0(ZP\ Zeven) + 2 · log

W w s(x)≥ 0.

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 subtree- disjoint sets D1to Dkand at most` monotone sets M1to M`. Then

X i ≤k |Di| + |ZP| ≤ Φ(P ) − Φ0(P ) + O µ ¡k + `¢¡1 + log W w (x) ¢ ¶ .

Proof. We view the transformation as a two-step process, i.e. we first rotate x to the root and

then transform the left and right subtrees of x. LetΦ00be the potential of the intermediate tree. By Lemma3.10, |ZP| ≤ Φ(P ) − Φ00(P ) + O µ 1 + log W w s(x) ¶ . By Theorem3.9, X i ≤k |Di| ≤ Φ00(P ) − Φ0(P ) + O µ ¡k + `¢¡1 + log W w (x) ¢ ¶ .

To prove the main theorem, we just need the following proposition that follows directly from 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 can be 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 Theorem3.4. Let

L

be the set of leaves of Q. By assumption (i) there is a positive constant c such that |

L

| ≥|Q|−zc . Then |Q| ≤ c · |

L

| + z. We decompose P \ {x} into

L

and` monotone sets. By assumption (ii)` = O(1). An application of Theorem3.12with k = 1 and

` = O(1) completes the proof.