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.

(10.3)<br />

> 2 i · n(h − 2i).<br />

That is, n(h) > 2 i · n(h − 2i), for any <strong>in</strong>teger i, such that h − 2i ≥ 1. S<strong>in</strong>ce we already<br />

know the values of n(1) <strong>and</strong> n(2), we pick i so that h − 2i is equal to either 1 or 2.<br />

That is, we pick<br />

.<br />

By substitut<strong>in</strong>g the above value of i <strong>in</strong> formula 10.3, we obta<strong>in</strong>, for h ≥ 3,<br />

.<br />

(10.4)<br />

By tak<strong>in</strong>g logarithms of both sides of formula 10.4, we obta<strong>in</strong><br />

log n(h) > h/2 − 1,<br />

from which we get<br />

h < 2logn(h) + 2,<br />

(10.5)<br />

which implies that an AVL tree stor<strong>in</strong>g n entries has height at most 2logn + 2.<br />

By Proposition 10.2 <strong>and</strong> the analysis of b<strong>in</strong>ary search trees given <strong>in</strong> Section 10.1,<br />

the operations f<strong>in</strong>d <strong>and</strong> f<strong>in</strong>dAll, <strong>in</strong> a dictionary implemented with an AVL tree,<br />

run <strong>in</strong> time O(logn) <strong>and</strong> O(logn + s), respectively, where n is the number of entries<br />

<strong>in</strong> the dictionary <strong>and</strong> s is the size of the collection returned. Of course, we still have<br />

to show how to ma<strong>in</strong>ta<strong>in</strong> the height-balance property after an <strong>in</strong>sertion or removal.<br />

10.2.1 Update Operations<br />

601

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

Saved successfully!

Ooh no, something went wrong!