Title: Geometric Computing and Visualization 7
1Geometric Computing and Visualization 7
2Example Segment Tree
Query x3.5
112
612
16
I1 3,8 I2 2,5 I3 1,9 I4 7,11 I5
6,10 I6 4,12
I6
I3
13
36
69
912
I3
I5
I1
67
79
1012
12
23
34
46
910
I6
I1
I2
I2
I4
I4
I5
45
56
78
89
1011
1112
Output I3, I1, I2
I2
I1
I4
3Interval Trees
- Given a set S of intervals, I1, I2, , In, find
the intervals that contain a query point q. - Interval_Tree T for S
- Let P denote the set of endpoints of the n
intervals - root(T) median P
- Let Sl, Sr, and Sm denote the sets of intervals
to the left of, to the right of, and containing
medianP respectively. - left subtree(root) Interval_Tree Tl for Sl
- mid subtree(root) two sorted arrays for the left
endpoints and the right endpoints of intervals in
Sm. - right subtree(root) Interval_Tree Tr for Sr
- height of Interval_Tree T is ?log n?
4Priority Queue
- Priority Queue Heap(Min)
- root(S) min S
- Root contains min of those nodes in the
tree. - root (left subtree) min nodes in the left
subtrees - root (right subtree) min nodes in the right
subtrees - Standard priority queue (S1, S2, , Sn)
- S1 min Si
- left child of Si is S2i
- right child of Si is S2i1
- height of (min) heap ?log n?
5Priority Search Tree 3
- Priority search tree (McCreight) combination of
priority queue binary search tree. - Priority search tree of a point set S in the
plane is a segment tree whose auxiliary structure
v.aux associated with the range s, t, is a
pointer to the point with minimum py of all
points p?S, s?px?t.
6Priority Search Tree 2
- Priority search tree PST(S).
- if P ?, then PST is empty (leaf)
- else
- Let pmin be the point with min y-value
- Let xmedian be the median of x values in
S\pmin - Sleft p? S\pmin p.x ? xmedian
- Sright p? S\pmin p.x gt xmedian
7Priority Search Tree 1
8Priority search tree 0
Query Given a query interval l, r find the
point p?S s.t. l?p.x?r and p.y is
minimum
9Searching
- Given a set S of n points p1, p2, , pn and an
interval Ql, r, find the point with min
y-coordinate and whose x-coordinate lies within Q - Solution Build a PST for S
- Q(n) O(log n)
- S(n) O(n)
- Using binary search to find the root-to-leaf
paths for l and for r in PST. - ? Nodes on these paths are possible candidates
and - ? Nodes that belong to the canonical covering of
l, r
10Searching
- Split node v The first node v on the
root-to-leaf path of l (or r) whose key value,
key(v) ? query interval l, r
11Searching 1
Split node
121.5D Range Search 2
- 1.5 D range search ? 2 D range search
- or grounded range search
- Range queries of form (l1, r1)?(??, r2)
- Priority Search Tree
- Q(n) O(log n) k, k output size
- S(n) O(n)
- Optimal time and space
131.5D Range Search 1
- Solution
- Build a PST for S.
- Find the root-to-leaf paths for l1 and for r1 in
PST. - Nodes on these paths are possible candidates
- Visit subtrees whose roots belong to the
canonical covering of (l1, r1) and do retrieval - Q(n) O(log n) O(k), k output size
- S(n) O(n) Optimal time and space
14Range_Search_Minimum Query Problem
- The priority search tree can also be used to
support query of the form find the point p with
minimum py such that px?l, r.
15Filtering Search for Grounded Range Search 2
- Query time Search time report time
- Partition S into p blocks B1, B2, , Bp each
block containing at most log n points. - p ? n/log n
- Each block Bi is sorted list in y-coord
- Build a PST for the set (?i, ?i) i1, 2, , p
where (?i, ?i) is the point with min y-coordinate
in Bi.
16Filtering Searchfor Grounded Range Search 1
- Query
- 1. Find Blocks Bl and Br containing l1 and r1
respectively. O(log p) - 2. If (l1)ltr (i.e. Bl and Br are separated by at
least one block) - then answer segment query (Bl, Br, r2) using
PST - for each point (?i, ?i) found, report
Bj. - O(log p) k
- 3. Sequential search in Bl Br . We can afford a
sloppy search, since its size is at most O(log n) - Total time O(log n) O(k), where k is output
size
17Point Enclosure Problem 2
- Given n intervals, I1, I2,, In, and a query
point x, find all the interval Ij such that x?Ij - Segment tree
- (S(n), Q(n)) (O(nlogn), O(logn)F)
- Interval tree
- (S(n), Q(n)) (O(n), O(logn)F)
18Point Enclosure Problem 1
- Solution Reporting mode
- Using 2n end points to build a segment tree
- Find the canonical covering for each interval
- For each node v v.aux contains a list of
intervals Ii s.t B(v),E(v)? canonical covering
of Ii - canonical covering of each interval 2??logn?
- (S(n), Q(n)) (O(nlogn), O(logn)F)
- Solution Counting mode
- only want to know how many intervals Ii such that
x?Ij - v.aux for each node contains only a number
- (S(n), Q(n)) (O(n), O(logn))
19Question
- Given m sorted lists L1, L2, , Lm and a query q,
find for each list the successor of q. - p ? list Li is a successor of q, if p is
the - smallest element in Li no less than q.
- Q(n) O(log n m) optimal time
- S(n) O(n)
- How do we solve this iterative search problem
in optimal time?
20Window List filtering search
- Interval overlap problem
- S ai, bi i1, 2, , n
- Report all intervals in S intersecting a query
interval q. - Special case when qx, x is known as point
enclosure problem, inverse of range searching
problem.
21Window list
- Def S(x) ai, bi?S ai?x?bi
- 1. Create a window list w1, , wp, each
containing a number of intervals from S - 2. Each window wj has an interval Ij. Let
?1??2???2n denote the 2n endpoints of the
intervals in S. I1, I2,, Ip is a partition of
?1, ?2n - 3. Density condition
- ?x?Ij, S(x)?Wj , 0ltWj??max(1, S(x)).
- i.e. Wj is always a superset of the solution
Wj??S(x)
22Overlapping Interval Searching
- Search method
- Given an x do binary search to locate a window
Wi whose interval Ii contains x - Then report intervals in Wj by filtering out
non-solutions - O(log p ? ?output size)
23Window List Construction
- Procedure Make_Window
- j1 Wj? low1 cur0 T0
- / Scan endpoint from left to right/
- for i 1 to 2n do
- if ?i is a left endpoint of interval I
- then cur
- T
- if (T gt ??low)
- then New(i, j)
- Wj Wj?I
- low T cur
- else Wj Wj?I
- else ?i is a right endpoint of interval I
- cur--
- low min(low, cur)
- if (T gt ??low)
- then New(i, j)
- T cur low max(1,T)
-
- Procedure New(i, j)
- j
- Wj intervals x, y of Wj-1s.t.
ygt?i -
- / low is the min size of S(x) in window Wj /
- / cur current density of intervals in Wj /
- / T number of intervals inserted in Wj /
-
24Example ? 2
d
W1 a, b
a
W2 a, b, c, d, e, f
c
h
b
g
W3 c, d, e, f, g,h
f
W4 f, h
e
W1
W3
W4
W2
25Theorem
- ? (S(n), Q(n))(n, log n) algorithm for point
enclosure problem - Proof
- Each interval ai, bi can be decomposed into 2
types of window points full part (Aj) partial
part (Bj) - I(j) ? ai, bi then ai, bi has a full part of
Wj - I(j) ?ai, bi ? ? then ai, bi has a partial
part of Wj - When left endpoint is scanned
- ??min(S(x))ltWj1
- When right endpoint is scanned
- ??min(S(x)-1)ltWj
- Wj Aj Bj
- ? Aj ? min ??S(x) lt Aj Bj ? ?
26The first should have been -.
27Review 2
- Priority Search Tree
- For 1.5D Range search (Grounded Range Search), in
which queries are of the form (l1,r1)?(-?,r2) - S(n) O(n)
- Q(n) O(lognk)
- Filtering Search
- Window list for point enclosure problem (for
overlapping interval search) - S(n) O(n)
- Q(n) O(log nk)
- w(x) ? ?S(x), w(x) ? S(x) (solution set)
28Review 1
- Segment tree for point enclosure problem
- S(n) O(n log n)
- Q(n) O(log n) k
- Question
- 2D Range search (counting) problem does there
exist an O(nlogn logn) algorithm???? - Dominance problem Given a set S of n pts in Rd
and q, find the total of pts in S dominated by
q. p is dominated by q iff p.xi?q.xi, i1,2,,d.
29- 2D Range tree
- S(n)O(n log n)?O(n loglog n)
- Q(n)O(log n)k
- 1.5D Range tree (grounded range tree)
30?-ary Range Tree 3
Aux(v)
31?-ary Range Tree 2
- Height is log? nlog n/log ?
- Each node u has an auxiliary structure A(u).
Bk1
Bk?
32?-ary Range Tree 1
- Overall window list for all pts corresponding to
u, Bk?-? segments intervals - Two PSTs
- Space O(n)?height
- Query O(log n ? k) O(log nk)
- Range query ? two 1.5D windowlist
- 2 ? (1.5D) ?(log n) y-sorted list
- 2 ? (1.5D) ? log n windowlist
33k-d Multidimensional Search Tree
- Root Box (0,?)?(0,?)
- Box(l) (0,x1)?(0,?)
- Box(r) (0,x2)?(0,?)
- v is visited only if (Box(v)?Query Rec??)
- Q(n)O(n1/2)k
- S(n)O(n)
- Quad tree