Orthogonal range searching - PowerPoint PPT Presentation

About This Presentation
Title:

Orthogonal range searching

Description:

Given a set of points S on the line, preprocess them to build structure that ... tree using the points' co-ordinates as the keys. 7. 7. 19. 15. 12. 8. 2 ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 46
Provided by: hai2
Category:

less

Transcript and Presenter's Notes

Title: Orthogonal range searching


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 Ix1,x2
find all points in S that are in the interval.
2
4
5
7
8
12
15
19
3
1-D solution
  • Build a balanced tree using the points
    co-ordinates as the keys.

2
4
5
7
8
12
15
19
7
query O(log nk)
space O(n)
4
12
2
5
8
15
7
19
15
12
8
2
4
5
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
Rx1,x2y1,y2 find all points in S that are
in the rectangle.
P3
P8
P5
P2
P6
P4
P7
P1
5
Range Trees (2-D)
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
P3
P3
P2
P2
P4
P4
P1
P1
P4
P3
P2
P1
6
Range Trees (Contd.)
P3
P8
P5
P2
P6
P4
P7
P1
P3
P2
P4
P1
P4
P3
P2
P1
P8
P7
P6
P5
7
Range Trees (Contd.)
P3
P8
P5
P2
P6
P4
P7
P1
P3
P2
P4
P1
P4
P3
P2
P1
P8
P7
P6
P5
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(log2 nk)
  • 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
4
12
2
5
8
15
7
19
15
12
8
2
4
5
13
P3
P8
P5
P2
P6
P4
P7
P1
P3
P2
P4
P1
P4
P3
P2
P1
P8
P7
P6
P5
14
P3
P8
P5
P2
P6
P4
P7
P1
P3
P2
P4
P1
P4
P2
P1
P8
P7
P6
P5
15
  • May need to rebalance the primary tree by doing a
    rotation

y
x
ltgt
A
x
C
y
B
B
C
A
? We have to rebuild the secondary data
structures at x and y
16
Dynamic range trees (analysis)
  • So we use BB(a) trees
  • Then the amortized cost of rebalancing the
    primary tree is O(log n)
  • and we get

Query O(log2 nk)
Insert, delete O(log2 n) (amortized)
17
Priority search trees
  • Suppose the query is unbouded from below, can we
    take advantage of this ?

P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
18
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
A
P1
A
P3
P12
We put the lowest point at the root and the
x-median (A) of the points other than the root
P4
P6
P7
P2
P5
P8
P9
P10
P11
19
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
P1
A
B
A
P4
P7
B
How do we answer a query ?
P8
P6
P5
P2
P11
P10
P9
P3
P12
20
P10
P11
P12
P3
P9
P8
P5
P2
P6
P4
P7
P1
P1
A
P4
P7
B
P8
P6
P5
P2
P11
P10
P9
P3
P12
21
P10
You stop the search in the when you hit a point
that is not in the answer
P11
P12
P3
P9
P8
P5
P2
P6
P4
P7
P1
P1
A
P4
P4
P7
B
P8
P6
P6
P5
P2
P2
P11
P10
P9
P3
P12
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
P10
P11
P3
P12
First put the points at the leaves of a red-black
tree
P9
P8
P5
P2
P6
P4
P7
P1
P2
P3
P12
P1
P4
P10
P11
P5
P8
P6
P7
P9
24
Top-down At each internal node put the smallest
point in its subtree not already assigned to an
internal node
P1
P7
P2
How does the insertion go ?
P3
P2
P3
P12
P1
P4
P10
P11
P5
P6
P7
P8
P9
25
P10
P11
P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4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
P4
P10
P11
P5
P6
P7
P8
P9
P3
N
35
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
We may also need to rebalance the tree Is this a
problem ?
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
P4
P10
P11
P5
P6
P7
P8
P9
P3
N
36
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
P4
P10
P11
P5
P6
P7
P8
P9
P3
N
37
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
P4
P10
P11
P6
P7
P8
P9
P3
N
M
P5
38
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
M
P4
P10
P11
P6
P7
P8
P9
P3
N
M
P5
39
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
M
P4
P10
P11
P6
P7
P8
P9
P3
N
M
P5
40
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
M
P4
P10
P11
P6
P7
P8
P9
P3
N
M
P5
41
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
N
P1
N
P7
P1
P4
P6
P2
P3
P11
P6
P5
P10
P12
P1
P2
M
P4
P10
P11
P6
P7
P8
P9
P3
N
M
P5
42
P
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
P1
N
43
P
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
N
P1
N
P7
P1
P4
P2
P6
P3
P11
P6
P5
P10
P12
P2
P1
P
P10
P11
P8
P6
P7
P9
P3
N
M
P
P4
P5
44
Rotation, rotations
X
X
ltgt
Y
Z
C
A
B
C
B
A
Z is bubbled down into B or C Y is bubbled up
from A or B
45
P
M
P10
P11
P3
P12
P9
P8
P5
P2
P6
P4
P7
N
P1
N
P7
P1
P4
P2
P6
P3
P11
P6
P5
P10
P12
P2
P1
P4
M
P10
P11
P8
P6
P7
P9
P3
N
M
P
P4
P5
Write a Comment
User Comments (0)
About PowerShow.com