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.

Proposition 10.6: 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 T with zero<br />

keys. Also, let f(i) denote the number of times the entry i is accessed <strong>in</strong> the splay<br />

tree, that is, its frequency, <strong>and</strong> let n denote the total number of entries. Assum<strong>in</strong>g<br />

that each entry is accessed at least once, then the total runn<strong>in</strong>g time for<br />

perform<strong>in</strong>g the sequence of operations is<br />

We omit the proof of this proposition, but it is not as hard to justify as one might<br />

imag<strong>in</strong>e. The remarkable th<strong>in</strong>g is that this proposition states that the amortized<br />

runn<strong>in</strong>g time of access<strong>in</strong>g an entry i is O(log(m/f(i))).<br />

10.4 (2,4) Trees<br />

Some data structures we discuss <strong>in</strong> this chapter, <strong>in</strong>clud<strong>in</strong>g (2,4) trees, are multi-way<br />

search trees, that is, trees with <strong>in</strong>ternal nodes that have two or more children. Thus,<br />

before we def<strong>in</strong>e (2,4) trees, let us discuss multi-way search trees.<br />

10.4.1 Multi-Way Search Trees<br />

Recall that multi-way trees are def<strong>in</strong>ed so that each <strong>in</strong>ternal node can have many<br />

children. In this section, we discuss how multi-way trees can be used as search<br />

trees. Recall that the entries that we store <strong>in</strong> a search tree are pairs of the form (k,x),<br />

where k is the key <strong>and</strong> x is the value associated with the key. However, we do not<br />

discuss how to perform updates <strong>in</strong> multi-way search trees now, s<strong>in</strong>ce the details for<br />

update methods depend on additional properties we wish to ma<strong>in</strong>ta<strong>in</strong> for multi-way<br />

trees, which we discuss <strong>in</strong> Section 14.3.1.<br />

Def<strong>in</strong>ition of a Multi-way Search Tree<br />

Let v be a node of an ordered tree. We say that v is a d-node if v has d children.<br />

We def<strong>in</strong>e a multi-way search tree to be an ordered tree T that has the follow<strong>in</strong>g<br />

properties, which are illustrated <strong>in</strong> Figure 10.19a:<br />

• Each <strong>in</strong>ternal node of T has at least two children. That is, each <strong>in</strong>ternal<br />

node is a d-node such that d > 2.<br />

• Each <strong>in</strong>ternal d-node v of T with children v 1 ,…, v d stores an ordered set of<br />

d − 1 key-value entries (k 1 ,x 1 ),…, (k d − 1 ,x d − 1 ), where k 1 ≤ … ≤ k d − 1 .<br />

• Let us conventionally def<strong>in</strong>e k 0 = − ∞ <strong>and</strong> k d = +∞. For each entry (k,x)<br />

stored at a node <strong>in</strong> the subtree of v rooted at v , i = 1,…,d, we have that k i − 1 ≤k≤<br />

k i .<br />

627

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

Saved successfully!

Ooh no, something went wrong!