{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

two4 - Advanced Tree Structures 2 4 Trees(10 Introduction...

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

Introduction In the previous set of notes we introduced the multi-way tree and specifically the variant known as an m-way search tree. In this set of notes we will examine several of the special variants of m-way search trees that have important applications in data structures. 2-4 Trees If there is a maximum value m placed on the number of children that a given node may have the tree is referred to as an m-way tree . In this section we will focus on a common variant of the m-way tree known as a 2-3-4 tree or more commonly as a 2-4 tree. In the above definition, rule 1 defines a size property for the 2-4 tree; rules 2, 3, and 4 define the ordering property (which identifies the tree as a search tree), and rule 5 defines a depth property which determines the balance of a 2-4 tree. This depth property ensures that the height of a 2-4 tree containing n key values is θ (log 2 n). Figure 1 shows a 2-4 tree containing 13 key values (items) with a height of three (not counting the external nodes). 2-4 Trees - 1 Advanced Tree Structures – 2 - 4 Trees (10) 2-4 Tree A 2-4 tree is an m-way search tree T in which an ordering is imposed on the set of keys which reside in each node such that: 1. Each node has a maximum of 4 children and between 1 and 3 keys. 2. The keys in each node appear in ascending order. 3. The keys in the first i children are smaller than the i th key. 4. The keys in the last m-1 children are larger than the i th key. 5. All external nodes have the same depth.

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

View Full Document
Figure 1. 2-4 tree containing 13 key values. Insertion into a 2-4 Tree As with the other types of search trees that we have dealt with this semester, insertion of a new item ( k, x) , where k is the key value of item x, into a 2-4 tree begins with a search for the key value k . Assuming that the item does not already exist, the search will terminate unsuccessfully at an external node, let’s call it z . If v is the parent of this external node z , then the new item is inserted into node v and a new child is added to v . Let’s call this new child w , and we know that w is an external node. While this insertion technique clearly preserves the depth property of the 2-4 tree it may well violate the size property. The problem is that node v may already have four children and thus be a 4- node . Insertion of a new node in this manner would cause node v to become a 5-node and thus violate the size property. Any time an insertion occurs in node which is already a 4-node an overflow occurs and resolution of the overflow must occur to restore the properties of the 2-4 tree. Resolution of the overflow is done via a splitting operation. Recall that we saw this operation when we examined the general m-way search tree .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern