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

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 . The definition of the split operation for a 2-4 tree is shown in Figure 2.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

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

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