Presentation is loading. Please wait.

Presentation is loading. Please wait.

Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of.

Similar presentations


Presentation on theme: "Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of."— Presentation transcript:

1 Orthogonal range searching

2 The problem (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

3 1-D solution Build a balanced tree using the points’ co-ordinates as the keys. 7 71915128245 2 4 5 8 15 24578121519 617 query: O(log n+k) space: O(n)

4 The problem (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

5 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

6 Range Trees (Contd.) P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7

7 P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7

8 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

9 Analysis (2-D) Space O(nlog n) Query O(log 2 n+k) Preprocessing O(nlog n)

10 Further facts Generalizes to d-dimensions Query time can be reduced using a technique called fractional cascading (we may talk about it later on)

11 The dynamic case Suppose the set S is not fixed We want to be able to insert and delete points, and make queries intermixed with insertions and deletions.

12 Easy in 1-D, just use a red-black tree or some other balance search tree 7 71915128245 2 4 5 8 15

13 P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7 Y

14 P4P4 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7 Y P3P3 Y Y Y Y Y

15 May need to rebalance the primary tree by doing a rotation: y x B C x A y BC A  We have to rebuild the secondary data structures at x and y

16 Dynamic range trees (analysis) So we use BB(α) trees Then the amortized cost of rebalancing the primary tree is O(log n) and we get Query : O(log 2 n+k) Insert, delete : O(log 2 n) (amortized)

17 Priority search trees Suppose the query is unbouded from below, can we take advantage of this ? P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12

18 P1P1 A A P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 We put the lowest point at the root and the x-median (A) of the points other than the root P9P9 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 10 P 11 P 12

19 P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 How do we answer a query ? P 12 A P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 B

20 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 P 12

21 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 P 12 P4P4 P2P2 P6P6 You stop the search in the when you hit a point that is not in the answer

22 Priority search trees (analysis) query: O(log(n) + k) space: O(n) preprocessing: O(nlogn) How do we make them dynamic ?

23 Dynamic priority search trees P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 First put the points at the leaves of a red-black tree

24 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P2P2 P3P3 P7P7 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P4P4 P6P6 P6P6 P5P5 P 10 P 11 How does the insertion go ? Top-down: At each internal node put the smallest point in its subtree not already assigned to an internal node

25 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N

26 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N

27 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N

28 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 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P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N We may also need to rebalance the tree… Is this a problem ?

36 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M

37 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M

38 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

39 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

40 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

41 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M P

42 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 N M P P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N M M P P

43 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M P P Need a point to put here P This is incorrect P4P4 P5P5 M P5P5 P

44 Rotation, rotations… B CA BC A X X YZ Z is bubbled down into B or C Y is bubbled up from A or B

45 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M P P P4P4 P5P5 M P5P5 M P4P4


Download ppt "Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of."

Similar presentations


Ads by Google