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 355priv<strong>at</strong>e TTNode inserthelp(TTNode rt,Key k, E e) {TTNode retval;if (rt == null) // Empty tree: cre<strong>at</strong>e a leaf node for rootreturn new TTNode(k, e, null, null,null, null, null);if (rt.isLeaf()) // At leaf node: insert herereturn rt.add(new TTNode(k, e, null, null,null, null, null));// Add to internal nodeif (k.compareTo(rt.lkey()) < 0) { // Insert leftretval = inserthelp(rt.lchild(), k, e);if (retval == rt.lchild()) return rt;else return rt.add(retval);}else if((rt.rkey() == null) ||(k.compareTo(rt.rkey()) < 0)) {retval = inserthelp(rt.cchild(), k, e);if (retval == rt.cchild()) return rt;else return rt.add(retval);}else { // Insert rightretval = inserthelp(rt.rchild(), k, e);if (retval == rt.rchild()) return rt;else return rt.add(retval);}}10.5 B-TreesFigure 10.15 The 2-3 tree insert routine.This section presents the B-tree. B-trees are usually <strong>at</strong>tributed to R. Bayer <strong>and</strong>E. McCreight who described the B-tree in a 1972 paper. By 1979, B-trees had replacedvirtually all large-file access methods other than hashing. B-trees, or somevariant of B-trees, are the st<strong>and</strong>ard file organiz<strong>at</strong>ion for applic<strong>at</strong>ions requiring insertion,deletion, <strong>and</strong> key range searches. They are used to implement most modernfile systems. B-trees address effectively all of the major problems encounteredwhen implementing disk-based search trees:1. B-trees are always height balanced, with all leaf nodes <strong>at</strong> the same level.2. Upd<strong>at</strong>e <strong>and</strong> search oper<strong>at</strong>ions affect only a few disk blocks. The fewer thenumber of disk blocks affected, the less disk I/O is required.3. B-trees keep rel<strong>at</strong>ed records (th<strong>at</strong> is, records with similar key values) on thesame disk block, which helps to minimize disk I/O on searches due to localityof reference.4. B-trees guarantee th<strong>at</strong> every node in the tree will be full <strong>at</strong> least to a certainminimum percentage. This improves space efficiency while reducing thetypical number of disk fetches necessary during a search or upd<strong>at</strong>e oper<strong>at</strong>ion.

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

Saved successfully!

Ooh no, something went wrong!