m-Way Search Trees
A m-way Search tree of degree ‘m’ can have
at most m child nodes.
• If a node has k child nodes, then the node can
have only (k-1) keys contained in the node.
• For a node A0, (K1, A1), (K2, A2)…………….
..(Km-1, Am-1), all key value in the sub-tree
pointed to by Ai are less than the key Ki+1, and
all key values in the sub-tree pointed to by Am-1
Example 2 :
22
5 10 25
3 4 6 8 14 23 24 27
11 13 17 18 19 20 21
m-Way searching :
• Similar to Binary searching
• If search item s<k1 search the leftmost child.
• If search item s>k(d-1), search the rightmost child
• What about if d>2 ?
• Find two keys k(i-1) and k(i) between which s falls
and search the item in that node.
m-Way searching :
Search for 8 22
Search for 12
5 10 25
3 4 6 8 14 23 24 27
11 13 17 18 19 20 21
What would an in-order traversal look like :
22
5 10 25
3 4 6 8 14 23 24 27
11 13 17 18 19 20 21
3, 4, 5, 6, 8, 10, 11,13,14,17,18,19,20,21,22,23,24,25, 27
(2, 4) Tree
It is a kind of m-way search tree.
Properties 12
• At most 4 children
5
•All leaf are at same level 10 15
3 11
6 8
4
13 14 17
Insertion in m-way search tree :
STEPS :
• Search the node where the key is to be inserted.
• If the searched node is not full then insert the
key into that node.
• If the searched node is full then open a new
child node and insert the key.
Insertion in m-way search tree :
Since 6<18 TO INSERT 6
18 44 76 198
X X
Since 6<7 & node
is not full 6 will
be inserted
at this
node. 7 12 80 92 141 262
X X X X X
8 12 77 148 151 172 186 272 286 350
X X X X X X X X X X X X X X
Insertion in m-way search tree :
To insert 6 18 44 76 198
X X
7 12 80 92 141 262
X X X X X
8 12 77 148 151 172 186 272 286 350
X X X X X X X X X X X X X X
Insertion in m-way search tree :
18 44 76 198 TO INSERT 6
X X
7 12 80 92 141 262
X X X X X
8 12 77 148 151 172 186 272 286 350
X X X X X X X X X X X X X X