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.

We can also show that a variation of the above algorithm performs operation<br />

f<strong>in</strong>dAll(k) <strong>in</strong> time O(h + s), where s is the number of entries returned.<br />

However, this method is slightly more complicated, <strong>and</strong> the details are left as an<br />

exercise (C-10.1).<br />

Admittedly, the height h of T can be as large as n, but we expect that it is usually<br />

much smaller. Indeed, we will show how to ma<strong>in</strong>ta<strong>in</strong> an upper bound of O(logn)<br />

on the height of a search tree T <strong>in</strong> Section 10.2. Before we describe such a<br />

scheme, however, let us describe implementations for dictionary update methods.<br />

10.1.2 Update Operations<br />

B<strong>in</strong>ary search trees allow implementations of the <strong>in</strong>sert <strong>and</strong> remove operations<br />

us<strong>in</strong>g algorithms that are fairly straightforward, but not trivial.<br />

Insertion<br />

Let us assume a proper b<strong>in</strong>ary tree T supports the follow<strong>in</strong>g update operation:<br />

<strong>in</strong>sertAtExternal(v,e): Insert the element e at the external node v, <strong>and</strong><br />

exp<strong>and</strong><br />

v to be <strong>in</strong>ternal, hav<strong>in</strong>g new (empty) external node children;<br />

587

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

Saved successfully!

Ooh no, something went wrong!