This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 11/17/10 20:36:45 1 27 CS 61B: Lecture 27 Friday, October 29, 2010 234 TREES =========== A 234 tree is a perfectly balanced tree. It has a big advantage over regular binary search trees: because the tree is perfectly balanced, find, insert, and remove operations take O(log n) time, even in the worst case. 234 trees are thus named because every node has 2, 3, or 4 children, except leaves, which are all at the bottom level of the tree. Each node stores 1, 2, or 3 entries, which determine how other entries are distributed among its children’s subtrees. Each internal (nonleaf) node has one more child than keys. For example, a node with keys [20, 40, 50] has four children. Eack key k in the subtree rooted at the first child satisfies k <= 20; at the second child, 20 <= k <= 40; at the third child, 40 <= k <= 50; and at the fourth child, k >= 50. WARNING: The algorithms for insertion and deletion I’ll discuss today are different from those discussed by Goodrich and Tamassia. The text presents "bottomup" 234 trees, so named because the effects of node splits at the bottom of the tree can work their way back up toward the root. I’ll discuss "topdown" 234 trees, in which insertion and deletion finish at the leaves. Topdown 234 trees are usually faster than bottomup ones. Goodrich and Tamassia call 234 trees "(2, 4) trees". 234 trees are a type of Btree, which you may learn about someday in connection with fast disk access for database systems. [1] Object find(Object k); Finding an entry is straightforward. ========== Start at the root. At each node, +20 40 50+ check for the key k; if it’s not /==========\ present, move down to the // / \ \\ appropriate child chosen by    ======= comparing k against the keys. 14 32 43 +70 79+ Continue until k is found,    ======= or k is not found at a / \ / \ / \ /  \ leaf node. For example,        ====  find(74) visits the 10 18 25 33 42 47 57 62 66 +74+ 81 doublelined boxes at right.        ====  Incidentally, you can define an inorder traversal on 234 trees analogous to that on binary trees, and it visits the keys in sorted order....
View
Full Document
 Fall '01
 Canny
 Binary Search, Data Structures

Click to edit the document details