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

Create successful ePaper yourself

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

Sec. 10.5 B-Trees 3634845 4748 50 52(a)231833101215 18 19 20 2122 23 30 31 4547485052(b)Figure 10.24 Deleting the record with key value 33 from the B + -tree of Figure10.18 via collapsing siblings. (a) The two leftmost leaf nodes merge togetherto form a single leaf. Unfortun<strong>at</strong>ely, the parent node now has only one child.(b) Because the left subtree has a spare leaf node, th<strong>at</strong> node is passed to the rightsubtree. The placeholder values of the root <strong>and</strong> the right internal node are upd<strong>at</strong>edto reflect the changes. Value 23 moves to the root, <strong>and</strong> old root value 33 moves tothe rightmost internal node./** Delete a record with the given key value, <strong>and</strong>return true if the root underflows */priv<strong>at</strong>e boolean removehelp(BPNode rt, Key k) {int currec = binaryle(rt.keys(), rt.numrecs(), k);if (rt.isLeaf())if (((BPLeaf)rt).keys()[currec] == k)return ((BPLeaf)rt).delete(currec);else return false;else // Process internal nodeif (removehelp(((BPInternal)rt).pointers(currec),k))// Child will merge if necessaryreturn ((BPInternal)rt).underflow(currec);else return false;}Figure 10.25 Java-like pseudocode for the B + -tree delete algorithm.

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

Saved successfully!

Ooh no, something went wrong!