DATA STRUCTURE
17/01/2015
OHIDA ISLAM
2-4 TREE
Tree
• A tree is a data structure made up of nodes
or vertices and edges without having any
cycle.
• It also can be defined recursively Tree is
collection of nodes.
• When this tree will have no nodes that is
called NULL or empty tree.
2-4 TREE
• A 2–4 tree is a self-balancing data structure.
• The numbers mean a tree where
every node with children has either two,
three, or four child nodes.
• All leaf nodes are at the same level And All
external nodes have the same depth.
• High of 2-4 tree is at least log4 and at most
log2
• Each node can store 1,2 or 3 entries
2 Node
A 2-node has
one data
element, and
internal has
two child
nodes.
a
3 Node
A 3-node has
two data
elements,
and internal
has three
child nodes.
a b
4 Node
A 4-node has
three data
elements,
and if
internal has
four child
nodes.
ab c
p
Q R
S
2-4 TREE
22
5 10 25
3 4 6 8 14 23 24 27
11 13 17
2–4 trees are B-trees of order
4. Like B-trees in general, they
can search, insert and delete.
So now I am going to show
how can search from 2-4 tree.
SEARCHING
50
30 70
20 35 40 60 80
15 25 32 37 45 55 65 75 85
INSERTION
:
21,23,40,41,7
No problem if the node
has
empty tree
INSERT 21:
Insert 23:
Insert 40:
Insert 41:
Nodes get split if there is insufficient
space:
NEXT:
If parents node does not have sufficient space then
it is split . In this manner splits can cascade.
NEXT:
DELETION:
DELETE 21:
IF KEY TO BE DELETED IS AN INTERNAL NODE THEN WE
SWAP IT WITH ITS PREDECESSOR AND THEN DELETE IT.
NEXT:
If after deleting a key a node becomes empty then we
borrow a key from its sibling:
EMPTY NODE:
Next:
After delete:
If siblings has only one key then we merge with it. The key in
the parent node separating these two siblings moves down
into the merged node.
Next:
NEXT:
Conclusion:
 The height of a (2,4) tree is 0(log n)
 Split, transfer and merge each take
0(1).
 Search, insertion and deletion each
take 0 (log n).
2-4 tree

2-4 tree