This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 23 TREESContents zIntroduction{Test Yourself #1z23 Tree Operations{lookup{insert¡Test Yourself #2{delete¡Test Yourself #3z23 Tree SummaryzSummary of BinarySearch Trees vs 23 TreesIntroduction Recall that, for binarysearch trees, although the averagecase times for the lookup, insert, and delete methods are all O(log N), where N is the number of nodes in the tree, the worstcase time is O(N). We can guaranteeO(log N) time for all three methods by using a balancedtree  a tree that always has height O(log N) instead of a binarysearch tree. A number of different balanced trees have been defined, including AVL trees, redblack 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 23 Tree. The important idea behind all of these trees is that the insert and delete operations may restructurethe 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 binarysearch trees. The important facts about a 23 tree are: zEvery nonleaf node has either 2 or 3 children. zAll leaves are at the same depth. zInformation (keys and associated data) is stored onlyat leaves (internal nodes are for organization only). zKeys at leaves are ordered left to right. zIn addition to child pointers, each internal node stores: {the value of the max key in the leftsubtree (leftMax) {the value of the max key in the middlesubtree (middleMax) zIf 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 23 trees that all store the values 2,4,7,10,12,15,20,30:Page 1 of 623 Trees2008/3/27http://pages.cs.wisc.edu/~cs3671/topics/BalancedSearchTrees/TEST YOURSELF #1Draw two different 23 trees, both containing the letters A through G as key values. solutionOperations on a 23 Tree   4  12   /  \ /  \     2  4   7  10   15  20     /  /  \ /  \ 2 4 7 10 12 15 20 30   7  15   /  \ /  \     2  4   10  12   20  30     /  \ /  \   2 4 7 10 12 15 20 30   10  30   /   \ / \    4  10   15  30    /  /  /  /       2  4   7  10   12...
View
Full
Document
This note was uploaded on 03/27/2008 for the course CS 367 taught by Professor Marvinsolomon during the Spring '08 term at Wisconsin.
 Spring '08
 MarvinSolomon
 Data Structures

Click to edit the document details