23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

≤ r ′(x)−r(x)<br />

≤ 3(r ′(x)−r(x)).<br />

Proposition 10.4: Let T be a splay tree with root t, <strong>and</strong> let Δ be the total<br />

variation of r(T) caused by splay<strong>in</strong>g a node x at depth d. We have<br />

Δ ≤ 3(r(t) − r(x)) − d+2.<br />

Justification: Splay<strong>in</strong>g node x consists of p = d/2 splay<strong>in</strong>g substeps,<br />

each of which is a zig-zig or a zig-zag, except possibly the last one, which is a zig<br />

if d is odd. Let r 0 (x) = r(x) be the <strong>in</strong>itial rank of x, <strong>and</strong> for i = 1, …, p, let r i (x) be<br />

the rank of x after the ith substep <strong>and</strong> δ i be the variation of r(T) caused by the ith<br />

substep. By Lemma 10.3, the total variation Δ of r(T) caused by splay<strong>in</strong>g x is<br />

= 3(r p (x) − r 0 (x)) − 2p + 2<br />

≤ 3(r(t) − r(x)) − d + 2 .<br />

By Proposition 10.4, if we make a payment of 3(r(t) − r(x)) + 2 cyber-dollars<br />

towards the splay<strong>in</strong>g of node x, we have enough cyber-dollars to ma<strong>in</strong>ta<strong>in</strong> the<br />

<strong>in</strong>variant, keep<strong>in</strong>g r(v) cyber-dollars at each node v <strong>in</strong> T, <strong>and</strong> pay for the entire<br />

splay<strong>in</strong>g work, which costs d dollars. S<strong>in</strong>ce the size of the root t is 2n + 1, its rank<br />

r(t) = log(2n+ 1). In addition, we have r(x) < r(t). Thus, the payment to be made<br />

for splay<strong>in</strong>g is O(logn) cyber-dollars. To complete our analysis, we have to<br />

compute the cost for ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g the <strong>in</strong>variant when a node is <strong>in</strong>serted or deleted.<br />

When <strong>in</strong>sert<strong>in</strong>g a new node v <strong>in</strong>to a splay tree with n keys, the ranks of all the<br />

ancestors of v are <strong>in</strong>creased. Namely, let v 0 , v i , …, v d be the ancestors of v, where<br />

v 0 = v, v i is the parent of v i−1 , <strong>and</strong> v d is the root. For i = 1,…,d, let n ′(v i ) <strong>and</strong> n(v i )<br />

be the size of v i before <strong>and</strong> after the <strong>in</strong>sertion, respectively, <strong>and</strong> let r ′(v i ) <strong>and</strong> r(v i )<br />

be the rank of v i before <strong>and</strong> after the <strong>in</strong>sertion, respectively. We have<br />

n ′{v i ) = n{v i ) + 1.<br />

625

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!