11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

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.

Sec. 10.5 B-Trees 3593318234810 12 15 18 19 20 21 2223 30 31 33 45 4748 50 52Figure 10.18 Example of a B + -tree of order four. Internal nodes must storebetween two <strong>and</strong> four children. For this example, the record size is assumed to besuch th<strong>at</strong> leaf nodes store between three <strong>and</strong> five records.node in a B + -tree of order m might have enough room to store more or less thanm records. The requirement is simply th<strong>at</strong> the leaf nodes store enough records toremain <strong>at</strong> least half full. The leaf nodes of a B + -tree are normally linked togetherto form a doubly linked list. Thus, the entire collection of records can be traversedin sorted order by visiting all the leaf nodes on the linked list. Here is a Java-likepseudocode represent<strong>at</strong>ion for the B + -tree node interface. Leaf node <strong>and</strong> internalnode subclasses would implement this interface./** Interface for B+ Tree nodes */public interface BPNode {public boolean isLeaf();public int numrecs();public Key[] keys();}An important implement<strong>at</strong>ion detail to note is th<strong>at</strong> while Figure 10.17 showsinternal nodes containing three keys <strong>and</strong> four pointers, class BPNode is slightlydifferent in th<strong>at</strong> it stores key/pointer pairs. Figure 10.17 shows the B + -tree as itis traditionally drawn. To simplify implement<strong>at</strong>ion in practice, nodes really doassoci<strong>at</strong>e a key with each pointer. Each internal node should be assumed to holdin the leftmost position an additional key th<strong>at</strong> is less than or equal to any possiblekey value in the node’s leftmost subtree. B + -tree implement<strong>at</strong>ions typically storean additional dummy record in the leftmost leaf node whose key value is less thanany legal key value.B + -trees are exceptionally good for range queries. Once the first record inthe range has been found, the rest of the records with keys in the range can beaccessed by sequential processing of the remaining records in the first node, <strong>and</strong>then continuing down the linked list of leaf nodes as far as necessary. Figure 10.18illustr<strong>at</strong>es the B + -tree.Search in a B + -tree is nearly identical to search in a regular B-tree, except th<strong>at</strong>the search must always continue to the proper leaf node. Even if the search-keyvalue is found in an internal node, this is only a placeholder <strong>and</strong> does not provide

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

Saved successfully!

Ooh no, something went wrong!