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.

Also, s<strong>in</strong>ce n(v i )+1 ≤ n(v i+1 ), for i = 0,1,…, d − 1, we have the follow<strong>in</strong>g for each<br />

i <strong>in</strong> this range:<br />

r ′(v i ) = log(n ′(v i )) = log(n(v i ) + 1) ≤ log(n(v i+1 )) = r(v i+1 ).<br />

Thus, the total variation of r(T) caused by the <strong>in</strong>sertion is<br />

= r ′(v d )−r(v 0 )<br />

≤ log(2n+1).<br />

Therefore, a payment of O(logn) cyber-dollars is sufficient to ma<strong>in</strong>ta<strong>in</strong> the<br />

<strong>in</strong>variant when a new node is <strong>in</strong>serted.<br />

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

ancestors of v are decreased. Thus, the total variation of r(T) caused by the<br />

deletion is negative, <strong>and</strong> we do not need to make any payment to ma<strong>in</strong>ta<strong>in</strong> the<br />

<strong>in</strong>variant when a node is deleted. Therefore, we may summarize our amortized<br />

analysis <strong>in</strong> the follow<strong>in</strong>g proposition (which is sometimes called the "balance<br />

proposition" for splay trees):<br />

Proposition 10.5: Consider a sequence ofm operations on a splay tree,<br />

each one a search, <strong>in</strong>sertion, or deletion, start<strong>in</strong>g from a splay tree with zero keys.<br />

Also, let n i be the number of keys <strong>in</strong> the tree after operation i, <strong>and</strong> n be the total<br />

number of <strong>in</strong>sertions. The total runn<strong>in</strong>g time for perform<strong>in</strong>g the sequence of<br />

operations is<br />

which is O(m log n).<br />

In other words, the amortized runn<strong>in</strong>g time of perform<strong>in</strong>g a search, <strong>in</strong>sertion, or<br />

deletion <strong>in</strong> a splay tree is O(logn), where n is the size of the splay tree at the time.<br />

Thus, a splay tree can achieve logarithmic-time, amortized performance for<br />

implement<strong>in</strong>g an ordered dictionary ADT. This amortized performance matches<br />

the worst-case performance of AVL trees, (2,4) trees, <strong>and</strong> red-black trees, but it<br />

does so us<strong>in</strong>g a simple b<strong>in</strong>ary tree that does not need any extra balance<br />

<strong>in</strong>formation stored at each of its nodes. In addition, splay trees have a number of<br />

other <strong>in</strong>terest<strong>in</strong>g properties that are not shared by these other balanced search<br />

trees. We explore one such additional property <strong>in</strong> the follow<strong>in</strong>g proposition<br />

(which is sometimes called the "Static Optimality" proposition for splay trees):<br />

626

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

Saved successfully!

Ooh no, something went wrong!