Download presentation
Presentation is loading. Please wait.
1
2-4 tree k=2 Each node has 2,3,or 4 children
2
Delete 15 30 14 30 40 50 16 17 9 delete(14,T). 1 23 4 5 6 7 8 7 9 5 14 3
3
Delete 30 40 50 16 17 9 delete(14,T). 1 23 4 5 6 7 8 7 9 5 14 30 3
4
Delete 30 40 50 16 17 9 delete(17,T). 1 23 4 5 6 7 8 7 9 5 14 30 3
5
Delete 30 40 50 9 delete(17,T). 1 23 4 5 6 7 8 7 9 5 14 30 16 3
6
Delete 30 40 50 9 delete(16,T). 1 23 4 5 6 7 8 7 9 5 14 30 16 3
7
Delete 30 40 50 9 delete(16,T). 1 23 4 5 6 7 8 7 9 5 14 30 3
8
Borrow 30 40 50 9 delete(16,T). 1 23 4 5 6 7 8 7 9 5 14 30 3
9
Borrow 30 40 50 9 delete(16,T). 1 23 4 5 6 7 8 5 9 30 3 7
10
30 40 50 9 delete(9,T). 1 23 4 5 6 7 8 5 9 30 3 7
11
30 40 50 delete(9,T). 1 23 4 5 6 7 8 5 9 30 3 7
12
30 40 50 delete(9,T). 1 23 4 5 6 7 8 5 9 3 Fusion 7 30
13
30 40 50 delete(9,T). 1 23 4 5 6 7 8 3 Fusion 7 30 5
14
Delete -- definition Remove 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.
15
2) Orthogonal range searching Range trees
16
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=[x 1,x 2 ] find all points in S that are in the interval. 24578121519 617
17
Reporting (1-D) Build a balanced tree over the points Concatenate them in a list 7 71915128245 2 4 5 8 15 24578121519 617 query: O(log n+k) space: O(n)
18
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=[x 1,x 2 ][y 1,y 2 ] find all points in S that are in the rectangle. P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7
19
Range Trees (2-D) P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 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
20
Range Trees (Contd.) P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7
21
P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7
22
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
23
Analysis (2-D) Space O(nlog n) Query O(log 2 n+k)
24
הוספת מפתח 95 שוב צריך לפצל, הפעם את העלה ( 75, 80, 85, 90). במקומו יהיו שני עלים בעץ, בשמאלי יהיו המפתחות ( 75, 80 ) ובימני המפתחות ( 85, 90, 95). אבל עכשיו צריך להוסיף מפתח ( ומצביע ) להורה. אמורים להיות בו המפתחות : ( 25, 50, 60, 75, 85 ). אך יש מקום לארבעה מפתחות בלבד. מה עושים ? מפצלים ( אך לא בדיוק כמו מקודם )
25
הוספת מפתח 95 (המשך) אחרי שכבר פיצלנו את העלה, נפצל גם את הרמה הבאה ונארגן את המצביעים. את המפתח האמצעי ( 60 ) נשלח עוד רמה כלפי מעלה 60
26
הוספת מפתח 95 (סיום) לא הייתה רמה נוספת, לכן נוצר שורש חדש ( מותר שלא יהיה ½ מלא לפחות )
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.