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.

354 Chap. 10 Indexing18332320233020301921 24 31 19 21 24 31(a)(b)2318331220304810 15 19 21 24(c)3145 47 50 52Figure 10.14 Example of inserting a record th<strong>at</strong> causes the 2-3 tree root to split.(a) The value 19 is added to the 2-3 tree of Figure 10.9. This causes the nodecontaining 20 <strong>and</strong> 21 to split, promoting 20. (b) This in turn causes the internalnode containing 23 <strong>and</strong> 30 to split, promoting 23. (c) Finally, the root node splits,promoting 23 to become the left record in the new root. The result is th<strong>at</strong> the treebecomes one level higher.merged together. The delete oper<strong>at</strong>ion for the 2-3 tree is excessively complex <strong>and</strong>will not be described further. Instead, a complete discussion of deletion will bepostponed until the next section, where it can be generalized for a particular variantof the B-tree.The 2-3 tree insert <strong>and</strong> delete routines do not add new nodes <strong>at</strong> the bottom ofthe tree. Instead they cause leaf nodes to split or merge, possibly causing a rippleeffect moving up the tree to the root. If necessary the root will split, causing a newroot node to be cre<strong>at</strong>ed <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 <strong>at</strong> the same level. When allleaf nodes are <strong>at</strong> the same level, we say th<strong>at</strong> a tree is height balanced. Because the2-3 tree is height balanced, <strong>and</strong> every internal node has <strong>at</strong> least two children, weknow th<strong>at</strong> the maximum depth of the tree is log n. Thus, all 2-3 tree insert, find,<strong>and</strong> delete oper<strong>at</strong>ions require Θ(log n) time.

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

Saved successfully!

Ooh no, something went wrong!