2-3 Tree. Outline. Balanced Search Trees 2-3 Trees 2-3-4 Trees. Why care about advanced implementations?. Same entries, different insertion sequence:. Not good! Would like to keep tree balanced. 2-3 Trees. Features. each internal node has either 2 or 3 children
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
2-3 Tree
Same entries, different insertion sequence:
Not good! Would like to keep tree balanced.
Features
2-node
3-node
What is the time efficiency of searching for an item?
Binary Search
Tree
both trees after
inserting items
39, 38, ... 32
2-3 Tree
Insert 39
Insert 38
divide leaf
and move middle
value up to parent
result
insert in leaf
Insert 37
Insert 36
divide leaf
and move middle
value up to parent
insert in leaf
overcrowded
node
... still inserting 36
divide overcrowded node,
move middle value up to parent,
attach children to smallest and largest
result
After Insertion of 35, 34, 33
How do we insert 32?
Final Result
70
80
Delete70
Deleting70: swap 70 with inorder successor (80)
Deleting70: ... get rid of 70
Result
Delete 100
Deleting 100
Result
Delete 80
Deleting 80 ...
Deleting 80 ...
Deleting 80 ...
Final Result
comparison with
binary search tree
Deleting item I:
Redistribution
Merging
Redistribution
Merging
If n's parent ends up without item, apply process recursively
If merging process reaches the root and root is without item
delete root
all operations have time complexity of log n
4-node
Inserting 60, 30, 10, 20, 50, 40, 70, 80, 15, 90, 100
Inserting 60, 30, 10, 20 ...
...50, 40 ...
Inserting 50, 40 ...
...70, ...
Inserting 70 ...
...80, 15 ...
Inserting 80, 15 ...
...90 ...
Inserting 90 ...
...100 ...
Inserting 100 ...
Splitting 4-nodes during Insertion
Splitting a 4-node whose parent is a 2-node during insertion
Splitting a 4-node whose parent is a 3-node during insertion
30 50
20 50
30 40
25
25
40
10 20
10
Turning a 2-node into a 3-node ...
"rotation"
30 50
50
25
25
35
35
40
10 30 40
10
Turning a 2-node into a 3-node ...
merging
Delete 32, 35, 40, 38, 39, 37, 60