10_MultiwayTrees
-
Upload
dilip-matolkar -
Category
Documents
-
view
215 -
download
0
Transcript of 10_MultiwayTrees
-
8/13/2019 10_MultiwayTrees
1/22
Ceng-112 Data Structures I 2007 1
Chapter 10
MultiwayTrees
-
8/13/2019 10_MultiwayTrees
2/22
Ceng-112 Data Structures I 2007 2
M-Way Trees
M-way tree is a search tree.
Each node of tree can have from zero to m
subtrees,
m is defined as the order of the tree.
-
8/13/2019 10_MultiwayTrees
3/22
Ceng-112 Data Structures I 2007 3
Figure 10-1
Given the nonempty multiway tree, the following properties are defined:
1. Each node has 0 to m subtrees.
2. Given a node contains k subtree pointers, some of which may be null,and k-1 data entries.
3. The key values in the first subtree are all less than the key in the first entry,
the key values in the other subtrees are all greater than or equal to the key in
their parent entry.
4. The keys of the data entries are ordered.
M-Way Trees
It is not balanced!
m = 4
-
8/13/2019 10_MultiwayTrees
4/22
-
8/13/2019 10_MultiwayTrees
5/22
Ceng-112 Data Structures I 2007 5
M-Way Trees
-
8/13/2019 10_MultiwayTrees
6/22
-
8/13/2019 10_MultiwayTrees
7/22Ceng-112 Data Structures I 2007 7
Figure 10-4
B-Trees
A B-tree of order; m=5.Min entry : Ceiling|5/2| - 1 = 2 entries.
Max entry: 5 1 = 4 entries.
Min subtrees : Ceiling|5/2|=3
Max subtrees: 5
-
8/13/2019 10_MultiwayTrees
8/22
-
8/13/2019 10_MultiwayTrees
9/22Ceng-112 Data Structures I 2007 9
Figure 10-5
B-Tree Insertion
B-tree grows from the bottom
up.
When the node is full, this
condition is called asoverflow.
Overflow requires that the
node be split into two nodesand median entry is pushed
up, the tree grows one level.
m=5
-
8/13/2019 10_MultiwayTrees
10/22
Ceng-112 Data Structures I 2007 10
Figure 10-9 (a, b, and c)
B-Tree Insertion
-
8/13/2019 10_MultiwayTrees
11/22
Ceng-112 Data Structures I 2007 11
Figure 10-9 (d, e, and f)
B T B l
-
8/13/2019 10_MultiwayTrees
12/22
Ceng-112 Data Structures I 2007 12
Figure 10-12
B-Tree Balance
Order m=5.
Min entry = 2 entries.
Max entry= 4 entries.
B T C bi
-
8/13/2019 10_MultiwayTrees
13/22
Ceng-112 Data Structures I 2007 13
Figure 10-13
B-Tree Combine
Order m=5
-
8/13/2019 10_MultiwayTrees
14/22
-
8/13/2019 10_MultiwayTrees
15/22
Ceng-112 Data Structures I 2007 15
Figure 10-14 (d and e)
B T T l
-
8/13/2019 10_MultiwayTrees
16/22
Ceng-112 Data Structures I 2007 16
Figure 10-15
B-Tree Traversal
-
8/13/2019 10_MultiwayTrees
17/22
Ceng-112 Data Structures I 2007 17
Simplified B-Trees
There are two types;
1. 2-3 trees; is a B-tree order 3. Each non-root
node has eighter 2 or 3 subtrees. The root
may have zero, two or three subtrees.
2. 2-3-4 trees; is a B-tree order 4. Each node
can have 2, 3 or 4 children.
-
8/13/2019 10_MultiwayTrees
18/22
Ceng-112 Data Structures I 2007 18
Figure 10-16
B-Tree of order 3. (2-3 trees).
Simplified B-Trees
-
8/13/2019 10_MultiwayTrees
19/22
Ceng-112 Data Structures I 2007 19
Figure 10-17
B-Tree of order 4. (2-3-4 trees).It is a B-tree order 4. Each node can have 2, 3 or 4 children.
Simplified B-Trees
-
8/13/2019 10_MultiwayTrees
20/22
Ceng-112 Data Structures I 2007 20
Exercise
Calculate the maximum number of data
entries in a:
1. 3-way tree of heigh 3:
2. 4-way tree of heigh 5:
3. m-way tree of heigh h:
331 = 26
451 = 1023
mh1
-
8/13/2019 10_MultiwayTrees
21/22
Ceng-112 Data Structures I 2007 21
Exercise
Draw the B-tree of order 3 created by inserting the following
data arriving sequence:92 24 6 7 11 8 22 4 5 16 19 20 78
-
8/13/2019 10_MultiwayTrees
22/22