2-4 tree
•k=2
•Each node has 2,3,or 4 children
Delete
15 30
14 30 40 5016 179
delete(14,T).
1 2 3 4 5 6 7 8
7 9
5 14
3
Delete
30 40 5016 179
delete(14,T).
1 2 3 4 5 6 7 8
7 9
5 14
303
Delete
30 40 5016 179
delete(17,T).
1 2 3 4 5 6 7 8
7 9
5 14
303
Delete
30 40 509
delete(17,T).
1 2 3 4 5 6 7 8
7 9
5 14
30
16
3
Delete
30 40 509
delete(16,T).
1 2 3 4 5 6 7 8
7 9
5 14
30
16
3
Delete
30 40 509
delete(16,T).
1 2 3 4 5 6 7 8
7 9
5 14
303
Borrow
30 40 509
delete(16,T).
1 2 3 4 5 6 7 8
7 9
5 14
303
Borrow
30 40 509
delete(16,T).
1 2 3 4 5 6 7 8
5 9
303 7
30 40 509
delete(9,T).
1 2 3 4 5 6 7 8
5 9
303 7
30 40 50
delete(9,T).
1 2 3 4 5 6 7 8
5 9
303 7
30 40 50
delete(9,T).
1 2 3 4 5 6 7 8
5 9
3
Fusion
7 30
30 40 50
delete(9,T).
1 2 3 4 5 6 7 8
3
Fusion
7 30
5
Delete -- definitionRemove the key.
If it is the only key in the node remove the node, and let v be the parent that looses a child, otherwise return
(*) If v has one child, and v is the root discard v.
Otherwise (v is not a root), if v has a sibling w of degree 3 or 4, borrow a child from w to v and terminate.
Otherwise, fuse v with its sibling to a degree 3 node and repeat (*) with the parent of v.
2 )Orthogonal range searching
Range trees
Reporting )1-D)
Given a set of points S on the line, preprocess them to build structure that allows efficient queries of the from:
Given an interval I=[x1,x2] find all points in S that are in the interval.
2 4 5 7 8 12 15 19
6 17
Reporting )1-D)
Build a balanced tree over the pointsConcatenate them in a list
7
7 19151282 4 5
2
4
5 8
12
15
2 4 5 7 8 12 15 19
6 17
query: O(log n+k)space: O(n)
Reporting )2-D)
Given a set of points S on the plane, preprocess them to build structure that allows efficient queries of the from:Given an rectangle R=[x1,x2][y1,y2] find all points in S that are in the rectangle.
P1
P2
P3
P4
P5 P8
P6
P7
Range Trees )2-D)
P4P3P2P1
P3
P2
P4
P1
P1
P2
P3
P4
Maintain the points in a balanced search tree ordered by x-coor. In each internal node maintain the points in its subtree in a balanced search tree ordered by y
Range Trees )Contd.)
P4P3P2P1
P3
P2
P4
P1
P1
P2
P3
P4
P8P7P6P5
P5 P8
P6
P7
Range Trees )Contd.)
P4P3P2P1
P3
P2
P4
P1
P1
P2
P3
P4
P8P7P6P5
P5 P8
P6
P7
Query processing
•Search by the first dimension gives us O)logn) trees which together contain the
output.
•We search each of these trees to get the answer
Analysis )2-D)
•Space O)nlog n)
•Query O)log2 n+k)
95הוספת מפתח
. (90, 85, 80, 75(שוב צריך לפצל, הפעם את העלה במקומו יהיו שני עלים בעץ, בשמאלי יהיו המפתחות
.(95, 90, 85(ובימני המפתחות ( 80, 75(
אבל עכשיו צריך להוסיף מפתח (ומצביע( להורה. . (85, 75, 60, 50, 25(אמורים להיות בו המפתחות:
אך יש מקום לארבעה מפתחות בלבד. מה עושים? מפצלים (אך לא בדיוק כמו מקודם(
(המשך(95הוספת מפתח אחרי שכבר פיצלנו את העלה, נפצל גם את הרמה הבאה ונארגן
( נשלח עוד רמה כלפי 60את המצביעים. את המפתח האמצעי(מעלה
60
(סיום(95הוספת מפתח
לא הייתה רמה נוספת, לכן נוצר שורש חדש (מותר שלא יהיה ½ מלא לפחות(