Priority Search Trees Keys are pairs x y

  • Slides: 19
Download presentation
Priority Search Trees • Keys are pairs (x, y). • Basic (search, insert, delete)

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)

Radix Priority Search Tree • All x values are different, integer, and in the

Radix Priority Search Tree • All x values are different, integer, 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.

Radix Priority Search Tree • The y value of the element in node w

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)).

Insert • • Start with empty RPST. k = 16. Root interval is [0,

Insert • • Start with empty RPST. k = 16. Root interval is [0, 16). Insert (5, 8). [0, 16) 5, 8 [0, 16) • Insert (6, 9). 5, 8 • (5, 8) remains in root, because 8 < 9. • (6, 9) inserted in left subtree, because[0, 8) 6 is in the left child interval. 6, 9

Insert [0, 16) 5, 8 • Insert (7, 1). • (7, 1) goes into

Insert [0, 16) 5, 8 • Insert (7, 1). • (7, 1) goes into the root, because 1 < 8. [0, 8) • (5, 8) inserted in left subtree, because 5 6, 9 [0, 16) is in the left child interval. 7, 1 • (5, 8) displaces (6, 9), because 8 < 9. • (6, 9) inserted in right subtree, because 6 is in the right child interval. [0, 8) 5, 8 [4, 8) 6, 9

Insert [0, 16) 7, 1 [0, 8) 5, 8 [4, 8) 6, 9 •

Insert [0, 16) 7, 1 [0, 8) 5, 8 [4, 8) 6, 9 • Insert (11, 5). [8, 16) 11, 5

Properties [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [8,

Properties [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [8, 16) 11, 5 [4, 8) 6, 9 • Height is O(log k). • Insert time is O(log k).

Search [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [4,

Search [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [4, 8) 6, 9 • Search time is O(log k). [8, 16) 11, 5

Delete [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [8,

Delete [0, 16) 7, 1 [0, 8) 5, 8 [0, 4) 2, 12 [8, 16) 11, 5 [4, 8) 6, 9 • Similar to delete min of min heap. • Delete time is O(log k).

min. Xin. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8)

min. Xin. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8) 5, 8 [8, 16) 11, 5 [12, 16) [0, 4) 2, 12 [4, 8) 6, 9 • min. Xin. Rectangle(6, 12, 7). • Time is O(log k). 14, 6

Complexity yok yok ynot. OK Profile of visited nodes. Node is visited iff its

Complexity yok yok ynot. OK Profile of visited nodes. Node is visited iff its y is checked for being ok/not. OK. This check is done only at nodes with an x-range overlap.

Complexity yok yok ynot. OK Yellow node is node closest to root with 2

Complexity yok yok ynot. OK Yellow node is node closest to root with 2 examined children.

Complexity yok yok ynot. OK No yellow node O(log k) examined nodes Yellow node

Complexity yok yok ynot. OK No yellow node O(log k) examined nodes Yellow node unique

Complexity yok yok ynot. OK Assume both children of the yellow node are yok.

Complexity yok yok ynot. OK Assume both children of the yellow node are yok. The other cases are similar.

Complexity yok yok ynot. OK No other node in the yellow node’s subtree can

Complexity yok yok ynot. OK No other node in the yellow node’s subtree can have two children marked yok.

Complexity yok yok ynot. OK # nodes visited < 4 log k. yok ynot.

Complexity yok yok ynot. OK # nodes visited < 4 log k. yok ynot. OK

max. Xin. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8)

max. Xin. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8) 5, 8 [8, 16) 11, 5 [12, 16) [0, 4) 2, 12 [4, 8) 6, 9 • max. Xin. Rectangle(6, 12, 7). • Time is O(log k). 14, 6

min. Yin. Xrange(x. L, x. R) [0, 16) 12, 1 [0, 8) 5, 8

min. Yin. Xrange(x. L, x. R) [0, 16) 12, 1 [0, 8) 5, 8 [8, 16) 11, 5 [12, 16) [0, 4) 2, 12 [4, 8) 6, 9 • min. Yin. Xrange(6, 10). • Time is O(log k). 14, 6

enumerate. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8) 5,

enumerate. Rectangle(x. L, x. R, y. T) [0, 16) 12, 1 [0, 8) 5, 8 [8, 16) 11, 5 [12, 16) [0, 4) 2, 12 [4, 8) 6, 9 14, 6 • enumerate. Rectangle(6, 12, 8). • Time is O(log k + s), where s is #points in rectangle.