2-3 Trees

2-3 Trees - 2-3 TREESContents zIntroduction{Test Yourself...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2-3 TREESContents zIntroduction{Test Yourself #1z2-3 Tree Operations{lookup{insert¡Test Yourself #2{delete¡Test Yourself #3z2-3 Tree SummaryzSummary of Binary-Search Trees vs 2-3 TreesIntroduction 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 guaranteeO(log N) time for all three methods by using a balancedtree -- 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 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 binary-search trees. The important facts about a 2-3 tree are: zEvery non-leaf 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 2-3 trees that all store the values 2,4,7,10,12,15,20,30:Page 1 of 62-3 Trees2008/3/27http://pages.cs.wisc.edu/~cs367-1/topics/Balanced-Search-Trees/TEST YOURSELF #1Draw two different 2-3 trees, both containing the letters A through G as key values. solutionOperations on a 2-3 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.

Page1 / 6

2-3 Trees - 2-3 TREESContents zIntroduction{Test Yourself...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online