1 / 26

Priority Search Trees

Priority Search Trees. Keys are distinct ordered pairs (x i , y i ) . Basic operations. get(x,y) … return element whose key is (x , y) . delete(x,y) … delete and return element whose key is (x,y) . insert(x,y,e) … insert element e , whose key is (x , y) . Rectangle operations. y T.

altas
Download Presentation

Priority Search Trees

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Priority Search Trees • Keys are distinct ordered pairs (xi, yi). • Basic operations. • get(x,y) … return element whose key is (x,y). • delete(x,y) … delete and return element whose key is (x,y). • insert(x,y,e) … insert element e, whose key is (x,y). • Rectangle operations.

  2. yT xL xR minXinRectangle(xL,xR,yT) • Return element with min x-coordinate in the rectangle defined by the lines, x= xL, x= xR, y =0, y = yT, xL <= xR, 0 <= yT. • I.e., return element with min x such that xL <= x <= xR and 0 <= y <= yT.

  3. yT xL xR maxXinRectangle(xL,xR,yT) • Return element with max x-coordinate in the rectangle defined by the lines, x= xL, x= xR, y =0, y = yT, xL <= xR, 0 <= yT. • I.e., return element with max x such that xL <= x <= xR and 0 <= y <= yT.

  4. xL xR minYinXrange(xL,xR) • Return element with min y-coordinate in the rectangle defined by the lines, x= xL, x= xR, y =0, y = infinity, xL <= xR. • I.e., return element with min y such that xL <= x <= xR.

  5. yT xL xR enumerateRectangle(xL,xR,yT) • Return all elements in the rectangle defined by the lines, x= xL, x= xR, y =0, y = yT, xL <= xR, 0 <= yT. • I.e., return all elements such that xL <= x <= xR and 0 <= y <= yT.

  6. Complexity • O(log n) for each operation except for enumerateRectangle, where n is the number of elements in the tree. • Complexity of enumerateRectangle is O(logn + s), where s is the number of elements in the rectangle.

  7. (5,6) (3,4) (6,3) (4,2) (2,1) Applications – Visibility • Dynamic set of semi-infinite vertical line segments. • Vertical lines with end points (xi,infinity) and (xi,yi). Opaque/translucent lines.

  8. (5,6) y (3,4) (6,3) (4,2) (2,1) 0 x infinity Translucent Lines • Eye is at (x,y). • Priority search tree of line end points. • enumerateRectangle(x, infinity, y).

  9. (5,6) y (3,4) (6,3) (4,2) (2,1) 0 x infinity Opaque Lines • Eye is at (x,y). • Priority search tree of line end points. • minXinRectangle(x, infinity, y).

  10. Bin Packing • First fit. • Best fit. • Combination. • Some items packed using first fit. • Others packed using best fit. • Memory allocation.

  11. Combined First And Best Fit • Bins are numbered 0, 1, …, n – 1. • Capacity of each is c. • Initialize priority search tree with the pairs (c, j), 0 <= j < n.

  12. neededSize bin index available capacity First Fit • minYinXrange(neededSize, infinity)

  13. neededSize bin index available capacity Best Fit • minXinRectangle(neededSize, infinity, infinity)

  14. Online Intersection Of Line Intervals • Intervals are of the form [i,j],i < j. • [i,j] may, for example represent the fact that a machine is busy from time i to time j. • Answer queries of the form: which intervals intersect/overlap with a given interval [u,v], u < v. • List all machines that are busy at any time between u and v.

  15. e 1 2 3 f 6 d c 2 5 4 7 a b 1 3 4 6 Example • Machine a is busy from time 1 to time 3. • Interval is [1,3]. • Machines a, b, c, e, and f are busy at some time in the interval [2,4].

  16. d b e 1 2 3 f 6 f c d 2 5 7 4 c e a a b 1 3 4 6 Example • Interval [i,j] corresponds to the pair (x,y), where x = j and y = i. • enumerateRectangle(u, infinity, v). • enumerateRectangle(2, infinity, 4).

  17. e 1 2 3 f 6 d c 2 5 7 4 a b 1 3 4 6 Interval Containment • List all intervals [i,j] that contain the interval [u,v]. • [i,j] contains [u,v] iff i <= u <= v <= j. [u,v] = [5,6]

  18. d b e 1 2 3 f 6 f c d 2 5 7 4 c e a a b 1 3 4 6 Interval Containment • Interval [i,j] corresponds to the pair (x,y), where x = j and y = i. • enumerateRectangle(v, infinity, u). • enumerateRectangle(6, infinity, 5).

  19. D A E G F C B Intersecting Rectangle Pairs • (A,B), (A,C), (D, G), (E,F) • Online interval intersection.

  20. D A E G F C B Algorithm • Examine horizontal edges in sorted y order. • Bottom edge => insert interval into a priority search tree. • Top edge => report intersecting segments and delete the top edge’s corresponding bottom edge.

  21. Complexity • Examine edges in sorted order. • Bottom edge => insert interval into a priority search tree. • Top edge => report intersecting segments and delete the top edge’s corresponding bottom edge. • O(n log n) to sort edges by y, where n is # of rectangles. • Insert n intervals … O(n log n). • Report intersecting segments … O(n log n + s). • Delete n intervals … O(n log n).

  22. IP Router Table • Longest-prefix matching • 10*, 101*, 1001* • Destination address d = 10100 • Longest matching-prefix is 101* • Prefix is an interval • d is 5 bits => 101* = [10100, 10111] = [20,23] • 2 prefixes may nest but may not have a proper intersection

  23. d IP Router Table • p(d) = prefixes that match d. • Use online interval intersection mapping. • p(d) = enumerateRectangle(d,infinity,d)

  24. d IP Router Table • lmp(d) = [maxStart(p(d)), minFinish(p(d))] • minXinRectangle(d,infinity,d) finds lmp(d) except when >1 prefixes have same finish point.

  25. d IP Router Table • Remap finish points so that all prefixes have different finish point. • f’ = 2wf – s + 2w – 1 , w = length of d • f’ is smaller when s is bigger

  26. d IP Router Table • Complexity is O(log n) for insert, delete, and find longest matching-prefix.

More Related