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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The dictionary we store at each node v is known as a secondary data structure, for<br />

we are us<strong>in</strong>g it to support the bigger, primary data structure. We denote the<br />

dictionary stored at a node v of T as D(v). The entries we store <strong>in</strong> D(v) will allow<br />

us to f<strong>in</strong>d which child node to move to next dur<strong>in</strong>g a search operation.<br />

Specifically, for each node v of T, with children v 1 ,…,v d <strong>and</strong> entries (k 1 ,x 1 ), …,<br />

(kd−1,x d−1 ), we store <strong>in</strong> the dictionary D(v) the entries<br />

(k 1 , (x 1 , v 1 )), (k 2 , (x 2 , v 2 )), ..., (k d − 1 , (x d − 1 , v d − 1 )), ( + ∞, (φ, v d ))<br />

That is, an entry (k i , (x i ,v i )) of dictionary D(v) has key k i <strong>and</strong> value (x i , v i ). Note<br />

that the last entry stores the special key +∞.<br />

With the realization of the multi-way search tree T above, process<strong>in</strong>g a d-node v<br />

while search<strong>in</strong>g for an entry of T with key k can be done by perform<strong>in</strong>g a search<br />

operation to f<strong>in</strong>d the entry (k i ,(x i ,v i )) <strong>in</strong> D(v) with smallest key greater than or<br />

equal to k. We dist<strong>in</strong>guish two cases:<br />

• If k < k i , then we cont<strong>in</strong>ue the search by process<strong>in</strong>g child v i . (Note that if<br />

the special key k d = +∞ is returned, then k is greater than all the keys stored at<br />

node v, <strong>and</strong> we cont<strong>in</strong>ue the search process<strong>in</strong>g child v d ).<br />

• Otherwise (k =k i ), then the search term<strong>in</strong>ates successfully.<br />

Consider the space requirement for the above realization of a multi-way search<br />

tree T stor<strong>in</strong>g n entries. By Proposition 10.7, us<strong>in</strong>g any of the common<br />

realizations of ordered dictionaries (Chapter 9) for the secondary structures of the<br />

nodes of T, the overall space requirement for T is O(n).<br />

Consider next the time spent answer<strong>in</strong>g a search <strong>in</strong> T. The time spent at a d-node v<br />

of T dur<strong>in</strong>g a search depends on how we realize the secondary data structure D(v).<br />

If D(v) is realized with a sorted array (that is, an ordered search table), then we<br />

can process v <strong>in</strong> O(logd) time. If <strong>in</strong>stead D(v) is realized us<strong>in</strong>g an unsorted list<br />

<strong>in</strong>stead, then process<strong>in</strong>g v takes O(d) time. Let dmax denote the maximum<br />

number of children of any node of T, <strong>and</strong> let h denote the height of T. The search<br />

time <strong>in</strong> a multi-way search tree is either O(hd max ) or O(hlogd max ), depend<strong>in</strong>g on<br />

the specific implementation of the secondary structures at the nodes of T (the<br />

dictionaries D(v)). If d max is a constant, the runn<strong>in</strong>g time for perform<strong>in</strong>g a search<br />

is O(h), irrespective of the implementation of the secondary structures.<br />

Thus, the primary efficiency goal for a multi-way search tree is to keep the height<br />

as small as possible, that is, we want h to be a logarithmic function of n, the total<br />

number of entries stored <strong>in</strong> the dictionary. A search tree with logarithmic height,<br />

such as this, is called a balanced search tree. We discuss a balanced search tree<br />

that caps d max at 4 next.<br />

Def<strong>in</strong>ition of a (2,4) Tree<br />

.<br />

631

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

Saved successfully!

Ooh no, something went wrong!