Go to Bottom of Page
|
Up one Level
LECTURE 10
Chee Yap
Computational Geometry II: Window Queries
Computational Geometry II: Window Queries
Go to Bottom of Page
|
Up one Level
OVERVIEW
[Previous]
[This]
[Next]
[Top]
[Bot]
Introduction
[Previous]
[This]
[Next]
[Top]
[Bot]
Preprocessing Problems
- The window query problem in the introduction
will be solved through a series of development.
Along the way, we will
introduce several techniques and data structures
that are important in their own right.
-
The class of problems we are concerned with are
called preprocessing problems and they have the
following form. We are given a set S of objects
to which queries from some family Q will be applied.
-
For instance, S is a set points in \mathbb R2.
and Q is the family of rectangles in \mathbb R2.
Each q Î Q corresponds to the query ``list all
points in S ÇQ.
-
What makes this a preprocessing problem is that we want
to precompute a data structure D(S) so that all queries
q are answered efficiently by using D(S).
In other words, D(S) is computed before we know what
the sequence of queries might be.
-
The underlying set S does not change during queries.
This does not mean that the structure D(S) has to
be static - indeed, for adaptive or amortized
data structures, D(S) will evolve with each queries in Q.
-
But we can also consider the setting
where S can be changed by an insertion
or deletion. If a data structure D(S) does not
support insertion or deletion, we say it is static.
If it supports insertion but not deletion, we say
it is semi-dynamic. If it supports insertion as well
as deletion, it is dynamic.
-
Suppose S has size n.
The complexity of a solution to this problem is typically
described by three complexity functions:
- Construction Time T(n)
is the time to build D(S) from scratch.
-
Storage Space S(n)
is the amount of space used for D(S).
-
Query Time Q(n)
is the time to answering any query q Î Q.
This Q(n) could be defined in the worst case,
amortized or expected senses.
-
Query Time Q(n,k)
when the output size is k.
This is explained below.
-
Insertion Time I(n)
is the time to insert a new object into S.
-
Deletion Time D(n)
is the time to delete an object from S.
-
a query q typically outputs
a list of items, and the size k = k(q) of this list can range
from 0 to n. Since k is a lower bound on any
specific query, the worst case query complexity is therefore
Q(n)=Q(n) in this case.
To avoid this trivial answer,
we use a query time function Q(n,k) that depends on
this output parameter k as well. For instance,
in many problems Q(n,k) = O(k + logn) is generally
regarded as optimal.
-
The use of the parameter k is an important innovation
in complexity analysis. The original view of complexity is
based on the input size parameters (i.e., n in our
case). But k is an output size parameter.
Algorithms that can take advantage output size parameters
are said to be output sensitive.
-
The above formulation of preprocessing problem can be
generalized as follows: the set S does not change under
the queries in Q. Such problems are said to be static.
We can also imagine queries that insert or delete members from
S. Then the problems are dynamic (or semi-dynamic in
case there are no deletes).
[Previous]
[This]
[Next]
[Top]
[Bot]
Window Query Problems
[Previous]
[This]
[Next]
[Top]
[Bot]
Orthogonal Range Searching, I
- We address Problem (I), the orthogonal range query problem.
It should be noted that this problem is actually a basic
problem in the study of databases. For instance, consider
a relational database of employees where we store with
each employee their date of birth and salary.
Thus each employee can be represented by a point
in a 2-dimensional space. Suppose we want to
support database queries of the
form ``list all employees who are born between 1960 and 1969,
and whose salary are between $70,000 and $90,000''.
To support such queries, the database would need
some data structure for range queries.
[FIGURE]
-
Before we solve the 2-dimensional problem, let us
consider the 1-dimensional version.
Here, S is just a set of numbers in \mathbb R,
and a query q is just an interval [xmin,xmax] Í \mathbb R.
Since S is static, we can simply order the numbers
in an array A[1..n]. To answer the query q,
we perform binary search for the index of the
successor of xmin in the array, i.e., the smallest
index i such that A[i] ³ xmin.
Starting from A[i], we can check successive values
of the array to see if each is £ xmin. If so,
we output the value. We terminate the first time
we encounter a value that is > xmax.
-
The above solution has T(n)=O(nlogn),
S(n)=O(n) and Q(n,k)=O(k+logn). These
complexity bounds are generally considered optimal.
-
Another possible solution to the 1-D problem is
to build a balanced binary tree on the set S.
To answer a query q=[xmin, xmax], we
perform a ``binary search'' for the interval q.
Initially, it will be unambiguous as to which
branch of a search node should be taken.
Suppose v0 is the first node where there
is ambiguity. What this means is that
the search key at v0 lies in the interval q.
At this point, we need to go down the left and
right branch of v0. We call v0 the split node.
-
By symmetry, consider
the search in the left child of v0.
Henceforth, at each search node u, we
know that the search key u.Key is less than xmax.
So we only need to compare u.Key: xmin.
-
There are two cases:
(a) if u.Key > xmin then we only need to go
down the right branch. This is the ``easy case''.
(b) if u.Key £ xmin then we only need to go
down both branches. But there is a important new
fact we can exploit: the right branch leads to
a subtree whose nodes contains keys that is guaranteed
to be in the interval q. Suppose T(u) denotes
subtree rooted at u and S(u) denotes the set
{x Î S: x Î Tu}. So, conceptually,
we can ``return'' the right child u.Right to represent
this set T(u.Right). This ability will be important later.
But for our present 1-D problem, we can simply
do a traversal of u.Right and output every
element in this subtree.
-
This second solution also has the same
complexity as the first solution: T(n)=O(nlogn),
S(n)=O(n) and Q(n,k)=O(k+logn). What
have we gained? Nothing in some sense, and perhaps
we have lost something because it is more complicated
than the first solution.
What the second solution gain is some additional
flexibility that can be exploited when we go to 2-D.
-
Let us recap some properties of the second solution:
after the split node v0, the left and right searches
below v0 will visit at most O(logn) nodes
of the easy type (case a), and at most O(logn) nodes
of the hard type. There are thus at most
O(logn) nodes of the hard type overall.
The output qÇS is obtained as the union of all S(u) where
u range over the hard nodes, as well as the individual
keys stored at the easy nodes (which has to be checked
individually to see if they belong to qÇS).
[Previous]
[This]
[Next]
[Top]
[Bot]
Orthogonal Range Searching, II
- Now consider the 2-dimensional version.
We can build on the second version of the
1-dimensional solution, where we again
set up a balanced binary search tree Tx, using
only the x-coordinate of points in S for
this construction. To do the query
q = [xmin, ymin, xmax, ymax] |
|
we can perform a search in Tx using
the query qx=[xmin, xmax].
At the ``easy nodes'' we again do an individual
check to see if the point stored at such nodes
lies in q, and to output them if so.
The difference is then when we get to the
``hard nodes'', we no longer can assume to
output everything in the subtree.
-
What we want to output at a hard node u Î Tx
is to output all those points in S(u) whose
y-coordinates lies in the interval qy=[ymin, ymax].
[Why is this correct?]
-
To support this operation at hard nodes,
we construct an auxilliary search
structure A(u) at every node u Î Tx.
This search structure is simply a 1-D search
structure on the y-coordinates of the points
in S(u). Here, we can assume A(u) is our
simpler solution to the 1-D problem, i.e., an array.
-
What is the complexity of this solution?
We claim S(n) = O(nlogn).
Let nu be the number of points in S(u).
Then S(n)=åu O(nu).
But each point in S is the key of some node v
and it can contribute to only those S(u) where u
lies on the path from v to the root. There are
O(logn) sets.
Next we claim T(n)=O(nlogn) as follows:
Constructing A(u) takes time O(nulognu).
It follows that T(n) = åu O(nulognu) = O(nlog2 n).
To improve this to the claimed bound, we
construct the auxialliary structures A(u)
in a bottom up fashion. Assuming that the children
of u are uL and uR, suppose A(uL) and A(uR)
have been constructed. Then we can construct A(u) in
time O(nu), not O(nulognu).
Finally, we claim that Q(n)=O(k+log2 n).
That is because we have to handle O(logn) hard
nodes, and each costs O(logn) time.
-
The above data structure is also called a range tree.
-
We can improve Q(n) to O(k+logn) as follows:
For each element A(u)[i] in the array A(u), we assume that
we store two pointers, into its successors in the
list A(uL) and A(uR), respectively. Recall
that A(u)[i] is really a point of S but we use
its y-coordinate as the key. The successor here
refers to these y-coordinates. Note that
A(u)[i] is actually an element in A(uL)
of A(uR). These pointers can be constructed
as we do the bottom-up merge of the lists A(uL)
and A(uR).
[FIGURE: A(u), A(uL), A(uR)]
-
To exploit these successor pointers, we assume that
as we visit each search node u in Tx, we always
maintain a pointer to the successor of ymin
in the array A(u). In particular, at the root,
we need to perform an O(logn) search to find
this pointer. But subsequently, we can update
this pointer at O(1) cost. This leads to the
claimed complexity of Q(n)=O(k+logn).
-
N.B. This improvement is sometimes called a trick
of fractional cascading. The full blown concept
of fractional cascading is slightly more involved
in general - but the goal is the same as that of ensuring
O(1) work to move from the solution to a query in A(u)
to solution of the same query in A(uL).
[Previous]
[This]
[Next]
[Top]
[Bot]
Interval Tree
- Let S be the set of geometric objects to be processed
for queries.
In orthogonal range queries S is a set of points.
We now consider the case where the objects in S
have non-trivial extensions: the simplest is where
S is a set of line segments.
-
Again, we begin with 1-dimension. So each I Î S
is an interval, assumed to be a closed interval.
Let us preprocess S for point queries: given q Î \mathbb R2,
retrieve qÙS.
[Previous]
[This]
[Next]
[Top]
[Bot]
Window Querying of Aligned Segments
- We now consider Problem (II). Here, S is a set
of aligned segments, i.e., horizontal or vertical.
Our first task is
to reduce it to a simpler problem.
- Given a query window q, the set of segments in S
that intersects q either has an endpoint in q
or it ``crosses q''.
- Those segments with one endpoint in q can be solved
using an orthogonal range query structure, which we
already solved.
- One detail that may be important
in applications is that a segment with 2 endpoints
in q might be reported twice. If this is not
acceptable, one solution is simply to mark each
segment for output first. Only when all the segments
have been marked, do we output. Marking a segment
twice does no harm in this marking scheme.
- Those segments that crosses q are of two types:
the horizontal and the vertical ones. The horizontal
segments must intersect both the left and right edges
of q. The vertices segments must intersect both
the top and bottom edges of q.
- Consider the new query problem: given a set S of
horizontal segments, solve the preprocessing problem
where queries are vertical line segments.
Thus, instead on window queries, we consider
segment queries (queries by segments).
- Using two calls to this segment query structure
(once for vertical segment queries, and once
for the horizontal segment queries), we have now
completely solved Problem (II).
[Previous]
[This]
[Next]
[Top]
[Bot]
Spatial Queries and Databases
We now take a slightly different point of view:
suppose we are dealing with very large
data sets involves geometric objects such as points, lines,
segments, polytopes and paths.
In databases, these are called spatial databases.
The difference from what we have discussed above
is that we no longer can assume that the full data set
can fit into main memory. This has two immediate
consequences:
- We need new kinds of data structures
that are sensitive to the I/O bottleneck between
main memory and secondary storage (or disk).
-
We are now more sensitive to the storage requirements
of our data. Thus, W(nlogn) storage is
no longer acceptable. Even for linear space O(n)
data structures, we worry about the implicit constants
in the big-Oh notation.
In practice, the most important
spatial data applications arise in 2-dimensions.
Most modern databases systems support efficient
for such structures objects. In particular, Postgrel
supports a very rich set of such operators (see Lecture 9).
The standard data structure used here are
R-Trees and its many variants. R-trees
are a generalization of B-trees, one of the most
important data structures in databases (the other is hashing).
Traditional data structure design criteria seeks to
optimize query time alone, as the data is
seen as static. New applications and demands
require more dynamic operations.
Moreover, sublinear size data structures
are expected to grow in importance.
R-trees were introduced by A. Guttmann [4].
Since its introduction, many variants of R-trees
have been investigated.
Until recently, there were no general
worst case complexity bounds for such
data structures. This has begun to change recently
[3,1].
The trick lies in exploiting additional complexity parameters
of the input, including stabbing numbers and aspect ratios
of rectangles.
So the basic problem is this: given a set S
of d-boxes in \mathbb Rd, to preprocess S so that given any query
box q, we can efficiently retrieve all b Î S that intersects q.
Call this the box-box query problem.
A special case of this is when q is a single point,
and then it becomes the point-box query problem.
When we desire to perform this query for a set of geometric
objects in \mathbb Rd that are not boxes, it is still possible to
use this data structure if we first replace each objeve
by its minimum bounding box (MBB). In this case,
the box-box query problem can be regarded as a preliminary
``filtering step'' to produce a superset of what we really needed.
The subsequent ``refinement step'' can be regarded as a straightforward
sequential search through the output from the filtering step.
This will be efficient if the filtering step do not produce too
many false hits. See Zhou and Suri [xx] for such examples.
BB Hierarchy.
The concept of a bounding-box hierarchy (or BB Hierarchy)
for S is quite generic. Most of the search structures
we are interested are special forms of such a hierarchy.
Let |S|=n.
A BB hierarchy for S is a search tree T with n leaves,
and for each leaf v of T, there is an associated
box Bv Î S. Morever every box in S is associated
with some leaf v. For a node u Î T, let Cu denote
the set of boxes at the leaves of the tree Tu rooted at u.
The smallest enclosing box for the cluster Cu is denoted Bu.
Call Bu and Cu the bounding box and cluster at u,
respectively. Thus the space used by T is linear.
Note that T is not restricted to binary trees.
However, we assume in the following that each node u
has at most b children, where b is a constant.
We can use a BB Hierarchy to answer any box query q on S
in the obvious way: let q be a box. Starting at the root
of T, suppose we are at a general node u. If q ÇBu=Æ,
we are done. If Bu Í q then we report every box in Cu.
Otherwise, we recursively visit all the children of u.
Let us analyze the query time for this algorithm: we introduce the
notion of crossing: say q crosses a node u of T
if BuÇq is non-empty and Bu is not contained q.
We define the crossing number of T to be the maximum
number of nodes in T that crosses any query box q.
It follows that the time to answer any query (using
conventions established at the beginning) is
where c(T) be the crossing number of T and k is the
output size. Note that the O(c(T)+ k)
here depends on b, which we suppress. To make
this dependence on b explicit, we can write
R-Trees.
An R-Tree is one form of a BB Hierarchy.
R-trees were introduced by A. Guttmann [4].
Since its introduction, many variants of R-trees
have been investigated.
To understand R-Trees, we must first understand the concept
of a B-Tree. These are search trees parametrized by
a number b. All nodes u has at most b children.
They also have at least b/2 children except that the
root is allowed to have as few as 2 children.
The unique feature is that all the leaves of
a B-Tree lie in the same level. Given these constraints,
there are relatively simple and natural algorithms for
insertion and deletion into B-Trees. We will not elaborate
on them here. The constraints also means that a B-Tree
has height at most (lgn)/(lg(b/2))+O(1).
What distinguish one BB Hierarchy from another is the way
they form the clusters (viewed from a bottom up perspective)
or the way clusters are split (viewed from top down).
Various heuristics are discussed in the literature.
See for example [2].
[Previous]
[This]
[Next]
[Top]
[Bot]
R-Trees with Low Stabbing Number
Until recently, there were no general
worst case complexity bounds for such
data structures. This has begun to change recently
[3,1].
The trick lies in exploiting additional complexity parameters
of the input, including stabbing numbers and aspect ratios
of rectangles.
[FIGURE with strips]
[Previous Section]
[Next Section]
Go to Top of Page
References
- [1]
-
P. K. Agarwal, M. de Berg, J. Gudmundsson, M. Hammar, and H. J. Haverkort.
Box-trees and r-trees with near-optimal query time.
In Symposium on Computational Geometry, pages 124-133, 2001.
- [2]
-
S. Brakatsoulas, D. Pfoser, and Y. Theodoridis.
Revisiting r-tree construction principles.
In Proc. 6th East-European Conf. on Advances in Databases and
Information Systems. Springer-Verlag, 2002.
Lecture Notes in CS, LNCS No.2435. ADBIS'02, Bratislava, Slovakia,
September 2002.
- [3]
-
M. de Berg, J. Gudmundsson, M. Hammar, and M. H. Overmars.
On r-trees with low stabbing number.
In European Symposium on Algorithms, pages 167-178, 2000.
- [4]
-
A. Guttmann.
R-trees: a dynamic indexing structure for spatial searching.
In Proc. ACM-SIGMOD Intl. Conf. on Management of Data, pages
47-57, 1984.
File translated from
TEX
by
TTH,
version 3.01.
On 30 Apr 2003, 17:47.