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.

A multi-way search tree that keeps the secondary data structures stored at each<br />

node small <strong>and</strong> also keeps the primary multi-way tree balanced is the (2,4) tree,<br />

which is sometimes called 2–4 tree or 2–3–4 tree. This data structure achieves<br />

these goals by ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g two simple properties (see Figure 10.20):<br />

Size Property: Every <strong>in</strong>ternal node has at most four children.<br />

Depth Property: All the external nodes have the same depth.<br />

Figure 10.20: A (2,4) tree.<br />

Aga<strong>in</strong>, we assume that external nodes are empty <strong>and</strong>, for the sake of simplicity,<br />

we describe our search <strong>and</strong> update methods assum<strong>in</strong>g that external nodes are real<br />

nodes, although this latter requirement is not strictly needed.<br />

Enforc<strong>in</strong>g the size property for (2,4) trees keeps the nodes <strong>in</strong> the multi-way search<br />

tree simple. It also gives rise to the alternative name "2–3–4 tree," s<strong>in</strong>ce it implies<br />

that each <strong>in</strong>ternal node <strong>in</strong> the tree has 2, 3, or 4 children. Another implication of<br />

this rule is that we can represent the dictionary D(v) stored at each <strong>in</strong>ternal node v<br />

us<strong>in</strong>g an unordered list or an ordered array, <strong>and</strong> still achieve O(1)-time<br />

performance for all operations (s<strong>in</strong>ce d max = 4). The depth property, on the other<br />

h<strong>and</strong>, enforces an important bound on the height of a (2,4) tree.<br />

Proposition 10.8: The height of a (2,4) tree stor<strong>in</strong>g n entries is O(log n).<br />

Justification: Let h be the height of a (2,4) tree T stor<strong>in</strong>g n entries. We<br />

justify the proposition by show<strong>in</strong>g that the claims<br />

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

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

632

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

Saved successfully!

Ooh no, something went wrong!