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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

When we perform a splay<strong>in</strong>g, we pay a certa<strong>in</strong> number of cyber-dollars (the exact<br />

value of the payment will be determ<strong>in</strong>ed at the end of our analysis). We<br />

dist<strong>in</strong>guish three cases:<br />

• If the payment is equal to the splay<strong>in</strong>g work, then we use it all to pay for<br />

the splay<strong>in</strong>g.<br />

• If the payment is greater than the splay<strong>in</strong>g work, we deposit the excess <strong>in</strong><br />

the accounts of several nodes.<br />

• If the payment is less than the splay<strong>in</strong>g work, we make withdrawals from<br />

the accounts of several nodes to cover the deficiency.<br />

We will show, <strong>in</strong> the rest of this section, that a payment of O(logn) cyber-dollars<br />

per operation is sufficient to keep the system work<strong>in</strong>g, that is, to ensure that each<br />

node keeps a nonnegative account balance.<br />

A Cyber-dollar Invariant for Splay<strong>in</strong>g<br />

We use a scheme <strong>in</strong> which transfers are made between the accounts of the nodes<br />

to ensure that there will always be enough cyber-dollars to withdraw for pay<strong>in</strong>g<br />

for splay<strong>in</strong>g work when needed.<br />

In order to use the account<strong>in</strong>g method to perform our analysis of splay<strong>in</strong>g, we<br />

ma<strong>in</strong>ta<strong>in</strong> the follow<strong>in</strong>g <strong>in</strong>variant:<br />

Before <strong>and</strong> after a splay<strong>in</strong>g, each node v of T has r(v) cyber-dollars <strong>in</strong> its<br />

account.<br />

Note that the <strong>in</strong>variant is "f<strong>in</strong>ancially sound," s<strong>in</strong>ce it does not require us to make<br />

a prelim<strong>in</strong>ary deposit to endow a tree with zero keys.<br />

Let r(T) be the sum of the ranks of all the nodes of T. To preserve the <strong>in</strong>variant<br />

after a splay<strong>in</strong>g, we must make a payment equal to the splay<strong>in</strong>g work plus the<br />

total change <strong>in</strong> r(T). We refer to a s<strong>in</strong>gle zig, zig-zig, or zig-zag operation <strong>in</strong> a<br />

splay<strong>in</strong>g as a splay<strong>in</strong>g substep. Also, we denote the rank of a node v of T before<br />

<strong>and</strong> after a splay<strong>in</strong>g substep with r ′(v) <strong>and</strong> r(v), respectively. The follow<strong>in</strong>g<br />

proposition gives an upper bound on the change of r(T) caused by a s<strong>in</strong>gle<br />

splay<strong>in</strong>g substep. We will repeatedly use this lemma <strong>in</strong> our analysis of a full<br />

splay<strong>in</strong>g of a node to the root.<br />

Proposition 10.3: Let δ be the variation ofr(T) caused by a s<strong>in</strong>gle splay<strong>in</strong>g<br />

substep (a zig, zig-zig, or zig-zag) for a node x <strong>in</strong> T. We have the follow<strong>in</strong>g:<br />

• δ ≤ 3(r ′(x)−r(x))−2 if the substep is a zig-zig or zig-zag.<br />

• δ ≤ 3(r ′(x) − r(x)) if the substep is a zig.<br />

623

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

Saved successfully!

Ooh no, something went wrong!