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.

h≤log(n+1) (10.10)<br />

are true.<br />

To justify these claims note first that, by the size property, we can have at most 4<br />

nodes at depth 1, at most 4 2 nodes at depth 2, <strong>and</strong> so on. Thus, the number of<br />

external nodes <strong>in</strong> T is at most 4 h . Likewise, by the depth property <strong>and</strong> the<br />

def<strong>in</strong>ition of a (2,4) tree, we must have at least 2 nodes at depth 1, at least 2 2<br />

nodes at depth 2, <strong>and</strong> so on. Thus, the number of external nodes <strong>in</strong> T is at least 2 h<br />

In addition, by Proposition 10.7, the number of external nodes <strong>in</strong> T is n+ 1.<br />

Therefore, we obta<strong>in</strong><br />

2 h ≤n+1<br />

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

n+1≤4 h .<br />

Tak<strong>in</strong>g the logarithm <strong>in</strong> base 2 of each of the above terms, we get that<br />

h≤log(n+1)<br />

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

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

which justifies our claims (10.9 <strong>and</strong> 10.10).<br />

Proposition 10.8 states that the size <strong>and</strong> depth properties are sufficient for keep<strong>in</strong>g<br />

a multi-way tree balanced (Section 10.4.1). Moreover, this proposition implies<br />

that perform<strong>in</strong>g a search <strong>in</strong> a (2,4) tree takes O(logn) time <strong>and</strong> that the specific<br />

realization of the secondary structures at the nodes is not a crucial design choice,<br />

s<strong>in</strong>ce the maximum number of children d max is a constant (4). We can, for<br />

example, use a simple ordered dictionary implementation, such as an array-list<br />

search table, for each secondary structure.<br />

10.4.2 Update Operations for (2,4) Trees<br />

Ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g the size <strong>and</strong> depth properties requires some effort after perform<strong>in</strong>g<br />

<strong>in</strong>sertions <strong>and</strong> removals <strong>in</strong> a (2,4) tree, however. We discuss these operations next.<br />

Insertion<br />

To <strong>in</strong>sert a new entry (k,x), with key k, <strong>in</strong>to a (2,4) tree T, we first perform a<br />

search for k. Assum<strong>in</strong>g that T has no entry with key k, this search term<strong>in</strong>ates<br />

633

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

Saved successfully!

Ooh no, something went wrong!