Download presentation
Presentation is loading. Please wait.
1
Priority Search Trees Keys are pairs (x,y).
Basic (search, insert, delete) and rectangle operations. Two varieties. Based on a balanced binary search tree such as a red-black tree. Red-black Priority Search Tree (RBPST) Based on a radix search tree. Radix Priority Search Tree (RPST)
2
Radix Priority Search Tree
All x values are different, integral, and in the range [0, k – 1]. Each node of the priority search tree has exactly one element. Min tree on y. Radix tree on x. When x values are not different we may transform (x,y) to (xM+y,y), when y values are integral and in the range [0,M-1]. For rectangle ops, left boundary becomes x_L * M and right becomes x_R * M + M-1. This preserves the integrity of rectangle operations.
3
Radix Priority Search Tree
The y value of the element in node w is <= the y value of all elements in the subtree rooted at w (y values define a min tree). Root interval is [0,k). Interval for node w is [a,b). Left child interval is [a, floor((a+b)/2)). Right child interval is [floor((a+b)/2, b)). Similar to point segment tree (each leaf is a point rather than a unit interval).
4
Insert Start with empty RPST. k = 16. Root interval is [0,16).
5,8 [0,16) Insert (6,9). (5,8) remains in root, because 8 < 9. (6,9) inserted in left subtree, because 6 is in the left child interval. 5,8 6,9 [0,16) [0,8) Note that despite the fact that 6 > 5, 6 is in the left subtree. Radix search tree; not binary search tree.
5
Insert Insert (7,1). (7,1) goes into the root, because 1 < 8.
5,8 6,9 [0,16) [0,8) Insert (7,1). (7,1) goes into the root, because 1 < 8. (5,8) inserted in left subtree, because 5 is in the left child interval. (5,8) displaces (6,9), because 8 < 9. 7,1 [0,16) 5,8 [0,8) (6,9) inserted in right subtree, because 6 is in the right child interval. 6,9 [4,8)
6
Insert Insert (11,5). 7,1 [0,16) 5,8 [0,8) 6,9 [4,8) 7,1 [0,16) 5,8
[8,16) 11,5 Insert (11,5).
7
Properties Height is O(log k). Insert time is O(log k). 7,1 [0,16) 5,8
[0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) Height is O(log k). Insert time is O(log k).
8
Search Search time is O(log k). 7,1 [0,16) 5,8 [0,8) 6,9 [4,8) [8,16)
11,5 2,12 [0,4) If root y > y of search key, quit. Search time is O(log k).
9
Delete Similar to delete min of min heap. Delete time is O(log k). 7,1
[0,16) 5,8 [0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) Similar to delete min of min heap. Delete time is O(log k).
10
minXinRectangle(xL,xR,yT)
12,1 [0,16) 5,8 [0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) [12,16) 14,6 If root y-value is > yT quit. Check if root is a candidate (I.e., is it in the rectangle). Search for a better candidate in the left subtree if x-range of left subtree overlaps with x-range of rectangle. Search right subtree only if left subtree does not have a point in the rectangle (provided, of course, there is an x-range overlap). Discontinue descent if you reach a node with a point above the rectangle. minXinRectangle(6,12,7). Time is O(log k).
11
Complexity yok ynotOK Profile of visited nodes.
We shall say that a node is visited/examined iff a comparison is made to determine whether its y value is > yT. Only nodes that have an x-range overlap with query rectangle may be examined. Label all examined nodes as yok or ynotOK depending on whether the y-value of the element in that node is <= yT. Only nodes labeled yok may have examined children. Profile of visited nodes.
12
Complexity yok ynotOK Yellow node is node closest to root with 2 examined children.
13
Complexity yok ynotOK No yellow node O(log k) examined nodes
If there is no such node, then only O(log k) nodes are examined. If there is a yellow node its y must be OK as it has examined children. The yellow node is unique, because if two nodes on the same level satisfy the property then their nearest common ancestor also satisfies the property and is closer to the root. Note that only nodes whose y-value is within the y-range may have an examined child. That is, the parent (if any) of an examined node must be labeled yok. Equivalently, every ancestor of an OK node is also OK. No yellow node O(log k) examined nodes Yellow node unique
14
Complexity yok ynotOK Assume both children of the yellow node are yok. The other cases are similar.
15
Complexity yok ynotOK If blue circled node has an OK y-value, it represents a point in the rectangle, because its left sibling has an x-range overlap with the rectangle as does the right child of the yellow node (so the x-range of the blue circled node is contained in the rectangle). So, the right subtree of the yellow circled node cannot be entered and the right child of the yellow node is not examined. Therefore, this blue circled node cannot have an OK y-value and so the subtree of which it is root is not entered. Similarly, if the red circled node has an OK y-value, its element is in the given rectangle and its right sibling is not examined. So, there can be at most one node that has two children labeled yok. No other node in the yellow node’s subtree can have two children marked yok.
16
Complexity yok ynotOK # nodes visited < 4log k.
No node in the yellow node’s subtree can have two children marked yok. If blue circled node has an OK y-value, it represents a point in the rectangle. So, the right subtree of the yellow circled node cannot be entered and the right child of the yellow node is not examined. Therefore, this blue circled node cannot have an OK y-value and so the subtree of which it is root is not entered. Similarly, if the red circled node has an OK y-value, its element is in the given rectangle and its right sibling is not examined. So, there can be at most one node that has two children labeled yok. # nodes visited < 4log k.
17
maxXinRectangle(xL,xR,yT)
12,1 [0,16) 5,8 [0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) [12,16) 14,6 If root y-value is > yT quit. Check if root is a candidate (I.e., is it in the rectangle). Search for a better candidate in the right subtree. Search left subtree only if right subtree does not have a point in the rectangle. Discontinue descent if you reach a node with a point above the rectangle. As before, a subtree is entered only if there is an x-range overlap. maxXinRectangle(6,12,7). Time is O(log k).
18
minYinXrange(xL,xR) minYinXrange(6,10). Time is O(log k). 12,1 [0,16)
5,8 [0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) [12,16) 14,6 Check if root is a candidate (I.e., is it in the x-range). If so, discontinue search. Otherwise, search left subtree if x-range has overlap. Also search right subtree if x-range has overlap. Take better of the up to 2 points found. minYinXrange(6,10). Time is O(log k).
19
enumerateRectangle(xL,xR,yT)
12,1 [0,16) 5,8 [0,8) 6,9 [4,8) [8,16) 11,5 2,12 [0,4) [12,16) 14,6 If root y-value is > yT quit. Check if root is in the rectangle. Search left and right subtrees (provided there is an x-range overlap) for additional points. enumerateRectangle(6,12,8). Time is O(log k + s), where s is #points in rectangle.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.