{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2-3 Trees

# 2-3 Trees - 2-3 Trees Page 1 of 6 2-3 TREES Contents...

This preview shows pages 1–4. Sign up to view the full content.

2-3 T REES Contents z Introduction { Test Yourself #1 z 2 - 3 Tree Operations { lookup { insert Test Yourself #2 { delete Test Yourself #3 z 2 - 3 Tree Summary z Summary of Binary - Search Trees vs 2 - 3 Trees Introduction Recall that, for binary-search trees, although the average-case times for the lookup, insert, and delete methods are all O(log N), where N is the number of nodes in the tree, the worst-case time is O(N). We can guarantee O(log N) time for all three methods by using a balanced tree -- a tree that always has height O(log N)-- instead of a binary-search tree. A number of different balanced trees have been defined, including AVL trees , red-black trees , and B trees . You might learn about the first two in an algorithms class, and the third in a database class. Here we will look at yet another kind of balanced tree called a 2-3 Tree . The important idea behind all of these trees is that the insert and delete operations may restructure the tree to keep it balanced. So lookup, insert, and delete will always be logarithmic in the number of nodes, but insert and delete may be more complicated than for binary-search trees. The important facts about a 2-3 tree are: z Every non-leaf node has either 2 or 3 children. z All leaves are at the same depth. z Information (keys and associated data) is stored only at leaves (internal nodes are for organization only). z Keys at leaves are ordered left to right. z In addition to child pointers, each internal node stores: { the value of the max key in the left subtree (leftMax) { the value of the max key in the middle subtree (middleMax) z If a node only has 2 children, they are left and middle (not left and right) children. As for binary search trees, the same values can usually be represented by more than one tree. Here are three different 2-3 trees that all store the values 2,4,7,10,12,15,20,30: Page 1 of 6 2-3 Trees 2008/3/27 http://pages.cs.wisc.edu/~cs367-1/topics/Balanced-Search-Trees/

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document