12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

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.4 2-3 Trees 37118332320233020301921 24 31 19 21 24 31(a)(b)2318331220304810 15 19 21 24(c)3145 47 50 52Figure 10.13 Example of inserting a record that causes the 2-3 tree root <strong>to</strong> split.(a) The value 19 is added <strong>to</strong> the 2-3 tree of Figure 10.9. This causes the nodecontaining 20 <strong>and</strong> 21 <strong>to</strong> split, promoting 20. (b) This in turn causes the internalnode containing 23 <strong>and</strong> 30 <strong>to</strong> split, promoting 23. (c) Finally, the root node splits,promoting 23 <strong>to</strong> become the left record in the new root. The result is that the treebecomes one level higher.postponed until the next section, where it can be generalized for a particular varian<strong>to</strong>f the B-tree.The 2-3 tree insert <strong>and</strong> delete routines do not add new nodes at the bot<strong>to</strong>m ofthe tree. Instead they cause leaf nodes <strong>to</strong> split or merge, possibly causing a rippleeffect moving up the tree <strong>to</strong> the root. If necessary the root will split, causing a newroot node <strong>to</strong> be created <strong>and</strong> making the tree one level deeper. On deletion, if thelast two children of the root merge, then the root node is removed <strong>and</strong> the tree willlose a level. In either case, all leaf nodes are always at the same level. When allleaf nodes are at the same level, we say that a tree is height balanced. Because the2-3 tree is height balanced, <strong>and</strong> every internal node has at least two children, weknow that the maximum depth of the tree is log n. Thus, all 2-3 tree insert, find,<strong>and</strong> delete operations require Θ(log n) time.

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

Saved successfully!

Ooh no, something went wrong!