Академический Документы
Профессиональный Документы
Культура Документы
Timothy M. Chan
Abstra
t
We des
ribe the rst optimal randomized in-pla
e algorithm for the basi
3-d
onvex hull problem (and, in parti
ular, for 2-d Voronoi diagrams). The algorithm runs in O(n log n) expe
ted time
using only O(1) extra spa
e; this improves the previous O(n log3 n) bound by Bronnimann, Chan,
and Chen [SoCG'04. The same approa
h leads to an optimal randomized in-pla
e algorithm for
the 2-d line segment interse
tion problem, with O(n log n + K ) expe
ted running time for output
size K , improving the previous O(n log2 n + K ) bound by Vahrenhold [WADS'05. As a bonus,
we also point out a simpli
ation of a known optimal
a
he-oblivious (non-in-pla
e) algorithm
by Kumar and Ramos (2002) for 3-d
onvex hulls, and observe its appli
ability to 2-d segment
interse
tion, extending a re
ent result for red/blue segment interse
tion by Arge, Mlhave, and
Zeh [ESA'08. Our results are all obtained by standard random sampling te
hniques, with some
interesting twists.
Keywords : In-pla
e algorithms, Convex hulls, Voronoi diagrams, Segment interse
tion, Ca
heoblivious algorithms
Introdu tion
In this paper, we address the basi
theoreti
al question of how mu
h spa
e is needed to solve fundamental problems in
omputational geometry. In the usual setting, we assume the input is given in an
array, where elements in the input array may be permuted; the measure of interest is the amount of
working spa
e ex
luding the input array (and the output stream, if the problem requires one). For
example, standard O(n log n)-time algorithms for the 3-d
onvex hull problem [38, 20 require O(n)
spa
e; Chazelle and Edelsbrunner's O(n log n + K )-time algorithm for 2-d segment interse
tion [16
requires O(n + K ) spa
e (K denotes the output size), whereas Balaban's O(n log n + K )-time algorithm [4 requires only O(n) spa
e. Generally, throughout the literature, an underlying goal has
always been to lower the spa
e
omplexity of algorithms whenever possible, if the running time does
not have to be sa
ri
ed.
For two very basi
geometri
problems, this paper provides the ultimate in spa
e redu
tion|we
prove that there is essentially no inherent limit in how far we
an redu
e spa
e. More pre
isely,
we show that, in the standard algebrai
de
ision tree model, there are asymptoti
ally time-optimal
algorithms for 3-d
onvex hulls and 2-d segment interse
tion using only O(1) spa
e. The algorithms
Cheriton S
hool of Computer S
ien
e, University of Waterloo, Waterloo, Ontario N2L 3G1, Canada (ftm
han,
y28
henguwaterloo.
a). Work supported by NSERC.
are randomized. For the former problem, given n points in an array, the algorithm
an, in O(n log n)
expe
ted time, permute the array so that the verti
es of the
onvex hull appear in a prex of the
array; if the fa
ets or edges of the
onvex hull are desired, they
an be printed to an output stream.
The running time
an be further redu
ed to O(n log h) if the output has h verti
es. For the latter
problem, given n line segments in an array, the algorithm
an, in O(n log n + K ) expe
ted time, print
the K interse
ting pairs to the output stream.
Sin
e 2-d Voronoi diagrams redu
e to 3-d
onvex hulls, we
an also print the verti
es of the
Voronoi diagram of n given points in O(n log n) expe
ted time with O(1) spa
e. A few appli
ations
follow; for example, we
an
ompute the
losest red/blue pair between n red points and n blue
points, or
ompute the largest
ir
le en
losing n points whose
enter lies within a given triangle 0,
in O(n log n) expe
ted time with O(1) spa
e.1 The te
hniques we use are general enough that they
an likely be applied to the
onstru
tion of other linear-size geometri
stru
tures.
Previous work. Algorithms using O(1) extra spa
e in a model where elements may be permuted
in the input array are
ommonly
alled in-pla
e algorithms; heapsort is a
lassi
al example. There
has been renewed interest in in-pla
e algorithms in the last few years. For example, the problem of
in-pla
e sorting in O(n log n) time with O(n) swaps was resolved only in 2003 by Fran
es
hini and
Geert [25. See [29, 28 for other re
ent examples of in-pla
e algorithms, and [27, 26 for examples
of in-pla
e, also
alled impli
it, data stru
tures where the stru
ture is represented entirely within a
permutation of the elements in the input array.
The more sophisti
ated in-pla
e algorithms and impli
it data stru
tures typi
ally build on the
following tri
k (e.g., see [36): we
an en
ode a bit impli
itly without extra spa
e by simply permuting
a
onse
utive pair (p; q) of elements in the input array, for example, by letting the en
oded bit be
0 (resp. 1) if p is lexi
ographi
ally smaller (resp. larger) than q. Using this tri
k, a pointer
an be
en
oded by permuting O(log n) pairs.
In
omputational geometry, a series of papers has re
ently appeared on in-pla
e algorithms. Some
simple results were des
ribed by Bronnimann et al. [11 (on 2-d
onvex hulls) and Bose et al. [7.
Chen and Chan [18 obtained a segment interse
tion algorithm running in O((n + K ) log2 n) time and
O(log2 n) spa
e, by reworking Bentley and Ottmann's sweep-line algorithm using known impli
it data
stru
tures (for the sear
h tree and priority queue). Bronnimann and Chan [9 obtained an O(n)-time
in-pla
e algorithm for
omputing the
onvex hull of a 2-d polygonal
hain, by reworking Melkman's
algorithm using impli
it data stru
tures (for the deque). The most substantial previous paper on the
topi
was by Bronnimann, Chan, and Chen [10, who gave a
olle
tion of nontrivial results on both
in-pla
e geometri
algorithms and impli
it geometri
data stru
tures. Of parti
ular relevan
e is the
main result on 3-d
onvex hulls: the paper presented the rst e
ient in-pla
e algorithm, running
in O(n log3 n) time, whi
h is obtained by rst designing a new sweep-line O(n log2 n)-time algorithm
and then making it in-pla
e using the impli
it pointer en
oding tri
k mentioned above.
Vahrenhold [42 later improved Chan and Chen's result on segment interse
tion and obtained an
O(n log2 n + K )-time in-pla
e algorithm, this time, by a
areful reworking of Balaban's algorithm [4.
Turning to other problems, Blun
k and Vahrenhold [5 gave an optimal O(n log n)-time in-pla
e
For the former problem, observe that the optimal pair must form a Delaunay edge; we
an examine the Delaunay
edges in O(1) spa
e as they are generated one at a time. For the se
ond problem, observe that the optimal
enter must
be a vertex v in the
lipped Voronoi diagram, i.e., the interse
tion of the Voronoi diagram with 0 ; the radius of the
largest empty
ir
le
entered at v
an be determined from the features dening the vertex (e.g., 3 points, or 2 points
and an edge of 0 ). It is known that the 2-d
lipped Voronoi diagram
an be transformed into a 3-d
onvex hull [15.
1
algorithm for 2-d layers of maxima and 3-d maxima. Chan and Chen [13 presented a new impli
it
data stru
ture for 2-d nearest neighbor sear
h with O(log1:71 n) query time.
Despite all these previous eorts, optimal in-pla
e algorithms for the basi
3-d
onvex hull and
2-d segment interse
tion problems have remained elusive. Our results provide the last word on these
open questions.
Our te
hniques. Any su
iently involved pointer-based stru
ture we want to maintain would
require the above-mentioned bit en
oding tri
k. However, the time to en
ode/de
ode a single pointer
is already logarithmi
; this is one of the reasons why a
hieving optimal running time is often di
ult
in the in-pla
e setting.
Our overall idea is to use a divide-and-
onquer strategy where the subproblem sizes drop dramati
ally. This way, pointer sizes (log n) would also de
rease su
iently, so that the extra logarithmi
ost would dissipate at the end. We will aim roughly for a re
urren
e of the form
T (n) (
n= log n) T (log n) + O(n log n), whi
h would indeed yield T (n) = O(n log n). (In fa
t,
on
e we get su
h a re
urren
e, the subproblems are small enough that they
an be solved dire
tly
without re
ursion.) To a
omplish the divide-and-
onquer, we apply standard random sampling
te
hniques. The division into subproblems requires point lo
ation queries, and the key lies in a
method (Lemma 2.4) to answer a bat
h of n point lo
ation queries, in a subdivision of sublinear size,
in O(n log n) time without the extra logarithmi
penalty.
Of
ourse,
ountless papers in
omputational geometry sin
e Clarkson and Shor [20 have used
randomized in
remental
onstru
tion and the random sampling paradigm [35 before. In parti
ular,
several works have used sampling to link the
omplexity of problems like 3-d
onvex hulls to that of
oine point lo
ation in dierent (e.g., transdi
hotomous or
a
he-oblivious) models [14, 33. However,
our work is not just another routine appli
ation of random sampling. Several sampling steps with
dierent sample sizes are needed to put together the nal result, though the algorithm
an still
be des
ribed
on
isely. In some ways, our algorithm is perhaps more related to (or generalizes)
Fran
es
hini and Geert's usage of deterministi
samples in their in-pla
e 1-d sorting algorithm [25.
In any
ase, we
an now add one more reason to study randomized te
hniques in
omputational
geometry|that they
an not only lead to time-optimal algorithms, but to spa
e-optimal ones as
well.
Their algorithm is des ribed for 2-d Voronoi diagrams, but should also work for 3-d onvex hulls.
We observe that Kumar and Ramos'
onvex hull algorithm
an be simplied (spe
i
ally, the
extra \pruning steps" turn out to be unne
essary after all). Se
ondly, we observe that their algorithm
an be adapted to yield an optimal
a
he-oblivious algorithm for general segment interse
tion.
The overall approa
h is again a sampling-based divide-and-
onquer strategy. The new idea is
quite simple: this time, we will aim for a re
urren
e of the form T (n)
n1 "T (n" ) + O(n log n) for
an absolute
onstant
and a su
iently small
onstant " > 0. If " is small enough (as
ompared to
1=
), the re
urren
e would indeed have solution T (n) = O(n log n). Somehow, this simple approa
h
was overlooked by previous resear
hers. This type of re
urren
e adapts well to the
a
he-oblivious
settings. The approa
h suggests that a variant of the standard randomized in
remental
onstru
tion
or random sampling method may be advantageous, where we stop the pro
ess on
e we have rea
hed
a sample size of n1 " , reorganize the array, and then re
urse. (See [2, 1, 21 for other previous work
on pra
ti
al and I/O-e
ient variants of random sampling methods.)
2
2.1
Preliminaries
lation
Lemma 2.1
(i)
hP
n
(ii) Pr max2T (R) jHj > (n=r) log t = O(r=t) for any t r.
In parti
ular, the following holds with probability at least 1=2 for some absolute
onstant
:
X
jHj
n and max
jH j
(n=r) log r:
2T (R)
2T (R)
(1)
as [25. As usual, the input array stores a permutation of the input elements at any time, and we
have O(1) registers that
an store indi
es and input elements. Standard operations on array elements
and registers
ost unit time as usual. In the new model, we are also allowed to work with an extra
array of bits whi
h we
all the \buer area". The number of bits may be large (possibly larger than
linear), but there is a pri
e to pay: the
ontent of this extra spa
e
an only be a
essed through bit
probes, with ea
h bit a
ess
osting unit time.
The buer area
an store pointers to input elements (with O(log n) bits) but
annot store input
elements themselves (whi
h we
an think of as having innite pre
ision). For example, if the buer
area stores an array of pointers to the input elements, a binary sear
h that normally takes O(log n)
time would now
osts O(log2 n) in our model be
ause reading a single pointer stored in the buer
area already
osts O(log n).
The algorithm should identify (i) the verti
es of the lower envelope (i.e.,
the hull fa
ets in primal spa
e), and (ii) the planes that parti
ipate in the lower envelope (i.e., the
hull verti
es in primal spa
e). For (i), the verti
es of the envelope are to be printed to an output
stream, where ea
h vertex is represented by its three dening planes. Note that if the edges of the
envelope (i.e., hull edges in primal spa
e) are desired, they
an be printed as well, where ea
h edge
is represented by its two dening planes: For ea
h vertex v printed, we just print the (at most two)
edges formed by the three dening planes that are oriented rightward towards v. This way, ea
h
edge is printed on
e. The edges that interse
t x = 1
an be generated by a 2-d lower envelope
algorithm [11.
For (ii), we assume that the buer area stores an array of n \output bits", one
orresponding to
ea
h input plane. At the end, we require that the algorithm turns the output bits to 1 for those input
planes that parti
ipate in the envelope. Output bits that were set to 1 before we
all the algorithm
will remain set to 1. At the very beginning, we
an initialize the output bits to 0.
In the model, we are allowed to permute elements in the input array during the exe
ution of
the algorithm. Though not expli
itly stated in our algorithm des
riptions below, whenever we swap
elements in the input array, we will swap the
orresponding output bits; this will not in
rease the
asymptoti
ost.
Output requirement.
Redu
tion to the permutation+bits model. We now show that any e
ient algorithm A in the
permutation+bits model, using O(n polylog n) bits of spa
e,
an be
onverted to an e
ient in-pla
e
algorithm for our problem. We apply the basi
bit en
oding tri
k mentioned in the introdu
tion.
The redu
tion is a
omplished by two lemmas, both using random sampling with small sample sizes:
Lemma 2.2 In the permutation+bits model, given a 3-d
onvex hull algorithm A requiring T (n)
expe
ted time and S (n) bits of spa
e, we
an obtain a 3-d
onvex hull algorithm A0 requiring O(T (n)+
n log n) expe
ted time and O(S (n loglog n= log n) + n) bits of extra spa
e, assuming that T (n)=n is
in reasing.
Draw a random sample R of size r = log n and put it in a sux of the input array. We
ompute E (R) and T (R) naively, in rO(1) time, and store it in the buer area.
Take a
ell 2 T (R). In O(n) time, we
an determine whi
h planes are in H, and move the
planes of H to the front of the input array using a standard in-pla
e partitioning subroutine. We
run algorithm A on H to
ompute the part of the lower envelope
ontained in . We then pro
eed
to the next
ell . (The planes in H n R have been permuted, but this is allowed.)
Proof:
Assuming (1), the running time is P2T (R) T (jHj) + O(nr) O(T (n) + n log n) and the spa
e
for the bits is max S (jHj) + O(n) = S ((n= log n) log log n) + O(n). If (1) fails, we
an retry with
a new sample; the expe
ted number of trials is O(1).
2
Lemma 2.3 Given a 3-d
onvex hull algorithm A requiring T (n) expe
ted time and O(n) bits of
extra spa
e in the permutation+bits model, we
an obtain an in-pla
e 3-d
onvex hull algorithm A0
requiring O(T (n)) expe
ted time.
Proof: Draw a random sample R of size r where, this time, r is a
onstant made su
iently large.
We
ompute E (R) and T (R) naively, in O(1) time and spa
e. Before ea
h iteration, we maintain the
invariant that the input array is divided into two parts 1 and 0, where 1 holds the list of planes
whose
urrent output bit is 1 (i.e., planes that have been found to parti
ipate in the lower envelope)
and 0 holds the list of remaining planes. Initially, 1 is empty.
Take a
ell 2 T (R). In O(n) time, we
an determine whi
h planes are in H, and move the
planes of H \ 1 and H \ 0 to the front of the input array, by in-pla
e partitioning. We simulate
algorithm A on H for the
ell . By (1), we
an ensure that jHj "n and A uses "n bits of
spa
e for a some suitable
onstant " > 0 (if (1) fails, we restart). Using the bit-en
oding tri
k, we
an simulate the buer area by permuting 2"n pairs at the ba
k of the input array (the only one
ex
eption is the pair that
rosses between 1 and 0). Noti
e that by
hoosing " small enough, we
an
ensure that there is no overlap between the part of the array storing H and the buer area. Before
the simulation, we re
ord the
urrent output bits of H in the buer area. After the simulation, we
unsplit H into H \ 1 and H \ 0 based on the updated output bits from the buer area, and
then move blo
ks around, in O(n) time (in-pla
e), to restore the invariant that the input array is
divided into the updated 1 and 0. We then pro
eed to the next
ell .
Sin
e r is a
onstant, the total expe
ted running time is O(T (n)).
2
It is not di
ult to obtain a 3-d
onvex hull algorithm that runs in O(n polylog n) time using O(n polylog n) bits of spa
e in the permutation+bits model: We
an just simulate any known
optimal O(n log n)-time, O(n)-spa
e algorithm, su
h as Preparata and Hong's divide-and-
onquer
algorithm [38. (We may assume that this algorithm does not modify the input array, as we
an
work with pointers to the input points.) Ea
h pointer operation now
osts O(log n), so the running
time be
omes O(n log2 n), and the number of bits of extra spa
e is O(n log n).
Applying Lemma 2.2 to this algorithm with T (n) = O(n log2 n) and S (n) = O(n log n) gives a new
algorithm in the permutation+bits model with O(n log2 n) running time and O(n log log n) bits of extra spa
e. Applying Lemma 2.2 on
e more gives O(n log2 n) running time and O(n log2 log n= log n +
n) = O(n) bits of extra spa
e. Applying Lemma 2.3 nally yields an in-pla
e 3-d
onvex hull algorithm with O(n log2 n) expe
ted time|this is already an improvement over Bronnimann, Chan, and
Chen's O(n log3 n) algorithm!
To obtain an O(n log n)-time in-pla
e algorithm, we
an fo
us all our attention on designing
an algorithm in the permutation+bits model that requires O(n log n) expe
ted time and O(n log n)
bits of extra spa
e. Unfortunately, tasks that normally take O(n) time, like merging two verti
ally
separated
onvex hulls [38, no longer seem doable in O(n) time in the permutation+bits model.
Ironi
ally, the di
ulty in designing an optimal in-pla
e algorithm lies in time
omplexity, not spa
e.
6
An
Lemma 2.4 Suppose we are given a set P of n points in 2-d, stored
onse
utively in the input array,
another set R of r points, stored
onse
utively in the input array, and a planar subdivision over the
verti
es in R of size O(r), en
oded in the buer area.
We
an lo
ate the
ell
p in the subdivision
ontaining ea
h point p 2 P , in O(n log r + r log r log n)
time in total and using O(r log r log n) bits of extra spa
e in the permutation+bits model. The algorithm is allowed to permute P in the input array, and the
p's are to be stored as an array of
O(n log r) bits in the buer area (in the order
orresponding to the permutation of P at the end).
The pre
eding algorithm
an be viewed as a variant of qui
ksort, be
ause of the re
ursive use
of the partitioning subroutine. We remark that not all standard point lo
ation methods
an be
7
simulated as ni
ely as above; known optimal sear
h stru
tures with linear spa
e (su
h as [24, 31, 40)
are DAGs, not binary trees (see [41 for an explanation). For the above, we only need optimal
O(log r) query time, not optimal spa
e, so the trapezoid method is ideal. (Another alternative is an
r" -ary segment tree, whi
h has O(log r) query time and O(r1+") prepro
essing time; be
ause of the
higher prepro
essing time, this option would require more eort later in the re
ursion.)
With the above lemma on point lo
ation, we
an now des
ribe our optimal algorithm:
Theorem 2.5 There is a 3-d
onvex hull algorithm that runs in O(n log n) expe
ted time and uses
O(n log n) bits of extra spa
e in the permutation+bits model.
Proof: Draw a random sample R of size r = n= log n and put it in a sux of the input array. We
ompute E (R) and T (R), stored in the buer area, in T (r) time by some algorithm A to be spe
ied
later.
For ea
h input plane h 2 H n R, we rst
ompute a vertex of E (R) above h. It su
es to nd the
extreme vertex vh in E (R) along the dire
tion orthogonal to h. In the dual, E (R)
orresponds to an
upper hull of r points; planes tangent to E (R)
orresponds to points on the upper hull; and planes
parallel to h
orresponds to points on a verti
al line. Thus, nding vh is equivalent to interse
ting
the upper hull with a query verti
al line. This redu
es to a point lo
ation query in the verti
al
proje
tion of the upper hull, a planar triangulation with O(r) verti
es. By Lemma 2.4, the
ost of
the n oine point lo
ation queries is O(n log r + r log2 n). The input array for H n R has now been
permuted (whi
h is ne sin
e so far we have not kept any pointer stru
ture to the elements of H n R);
we will keep this permutation as the \home" permutation.
For ea
h input plane h,
ompute the list Vh of all verti
es of E (R) above h. This
an be done by
a depth-rst sear
h in E (R), starting at vh ; in the traditional model, this takes O(jVhj) time, sin
e
the graph asso
iated with E (R) has maximum degree 3. From this list, we obtain the list of
ells of
T (R) interse
ted by h. From these lists, we obtain the
on
i
t lists H for all 2 E (R), stored in
pointer stru
tures in the buer area. In the traditional model, the total time is proportional to the
total size of the H's, whi
h is O(n) by (1) (if (1) fails, we restart). In the permutation+bits model,
the
ost be
omes O(n log n) (all these operations are done in the buer area, without permuting the
input array).
Now, take a
ell 2 T (R). We move the planes of H to the front of the array; this requires O(jHj) swaps in the input array and O(jHj) pointer operations on the
on
i
t lists, taking
O(jH j log n) time. We then solve the subproblem for H in T (jH j) time, by running algorithm
A. We assume that algorithm A does not
hange the input array. Afterwards, we move the planes
of H ba
k to their original position; for example, if we re
ord a trans
ript of the pre
eding O(jHj)
swaps, using O(jHj log n) bits, we
an perform these swaps ba
kwards in O(jHj log n) time. (It is
important that we go ba
k to the home permutation, so as not to disturb the pointer stru
tures for
the
on
i
t lists.) We
an then pro
eed to the next
ell .
For r = n= log n, the total expe
ted running time is
X
T (ni ) + T (n= log n) + O(n log n)
i
for some ni's with Pi ni = O(n) and maxi ni = O(log2 n). We do not need re
ursion. For algorithm
A, we
an just simulate a known O(n log n) algorithm; this requires T (n) = O(n log2 n) time in the
permutation+bits model. (With O(n log2 n) time, algorithm A indeed does not need to
hange the
8
input array, by working with pointers.) This yields a nal time bound of O(n log2 log n + n log n) =
O(n log n).
2
By applying Lemma 2.2 twi
e and then Lemma 2.3, we rea
h our nal
on
lusion:
Corollary 2.6 There is an in-pla
e 3-d
onvex hull algorithm that runs in O(n log n) expe
ted time.
2.3
Derandomization?
Derandomization of our in-pla
e O(n log n)-time algorithm appears di
ult be
ause of the large
hoi
e of sample size r, so we leave open the question of nding an optimal deterministi
in-pla
e
algorithm for 3-d
onvex hulls. We remark, however, that the in-pla
e O(n log2 n)-time algorithm
mentioned after Lemmas 2.2{2.3
an be derandomized using "-approximations [34.
Formally, a subset A H is a (1=r)-approximation of H i jHj=jH j and jAj=jAj diers by at
most 1=r for every simplex . Assuming that a (1=r)-approximation A of size rO(1) is given, we
an
ompute a sample R satisfying the properties in Lemma 2.1 in rO(1) time and spa
e, as shown by
Chazelle and Matousek [17, proof of Corollary 4. In the proof of Lemma 2.2, the extra time and
spa
e in bits are polylogarithmi
, whi
h are allowed. In the proof of Lemma 2.3, the extra time and
spa
e in words of words of spa
e are O(1), whi
h are again a
eptable. It remains to des
ribe how
to
onstru
t an (1=r)-approximation A.
There is a known algorithm A for
omputing (1=r)-approximations in O(n log r) time when
r n for a su
iently small
onstant > 0 [34. In the permutation+bits model, A would take
O(n log r log n) time and O(n log r log n) bits of extra spa
e. To obtain an in-pla
e algorithm, we
divide the array into k subsets H1; : : :; Hk , ea
h of size n=k, with k =
0 log r log n for some
onstant
0. For ea
h i, we
ompute a (1=(2r))-approximation Ai of Hi of size rO(1) by simulating A on Hi.
By
hoosing
0 large enough, this requires O(n log r log n) total time and at most "n bits of spa
e for
an arbitrarily small
onstant " > 0. Using the bit-en
oding tri
k, we
an simulate
the buer area
S
by permuting 2"n pairs anywhere in the input array outside of HSi. We move i Ai to a prex of
the array
and nish by
omputing a (1=(2r))-approximation A of i Ai by simulating A on
e again.
Sin
e Si Ai has size rO(1) log r log n, the time needed for this last step is negligible and the spa
e
needed in bits is less than "n, and so the bit-en
oding tri
k
an again be used. The result A is a
(1=r)-approximation of H , by known properties about "-approximations (
losure under unions and
ompositions) [34. We have thus des
ribed an in-pla
e algorithm to
ompute (1=r)-approximations
with running time at most O(n log r log n) = O(n log2 n) for r n .
2
Corollary 2.7 There is a deterministi
in-pla
e 3-d
onvex hull algorithm that runs in O(n log n)
time.
2.4
An Output-Sensitive Version
We observe that with additional known te
hniques, the O(n log n) running time
an be redu
ed to
O(n log h) if h is the output size. This improves the previous output-sensitive in-pla
e algorithm by
Bronnimann, Chan, and Chen [10, whi
h runs in O(n log3 h) time. The result extends the previous
2-d O(n log h)-time algorithm by Bronnimann et al. [11.
Corollary 2.8 There is an in-pla
e 3-d
onvex hull algorithm that runs in O(n log h) expe
ted time
where h denotes the number of hull verti
es.
Note that for h n", our O(n log n)-time algorithm already runs in O(n log h) expe
ted
time. We may thus assume h < n" . By Lemma 2.3, it su
es to give an O(n log h)-time algorithm
that uses O(n) bits of extra spa
e in the permutation+bits model for this
ase. (The proof of
Lemma 2.3 is still valid in the output-sensitive setting.)
We adapt Chan's (deterministi
) output-sensitive
onvex hull algorithm [12. We divide the given
array P of points into n=m subarrays Pi, ea
h
ontaining m points for some parameter m. For ea
h
subarray Pi, we build an impli
it data stru
ture to support gift-wrapping queries by permuting Pi.
(In a gift-wrapping query, we want to nd the rst point hit when we rotate a given plane around
a given line outside the interior of the
onvex hull; in the dual, this is equivalent to nding the
rst plane hit by a given ray originating from inside a halfspa
e interse
tion.) Bronnimann, Chan,
and Chen [10 provided su
h data stru
tures; the simplest option is an impli
it partition tree, whi
h
a
hieves query time O(m1 ) for some
onstant > 0. The prepro
essing time for ea
h subarray is
O(m log m), for a total of O(n log m). (The prepro
essing algorithm is in-pla
e.)
Chan's algorithm
omputes the
onvex hull using O(h) gift-wrapping queries on P , whi
h redu
e
to O(h(n=m)) queries on the Pi's. The algorithm maintains a queue storing at most O(h) fa
ets (to
implement a breadth-rst sear
h), and a di
tionary storing O(h) fa
ets (to ensure that ea
h fa
et
is pro
essed on
e). In the permutation+bits model, the algorithm requires O(h log n) bits of extra
spa
e; this number is sublinear sin
e h < n" . The total time for the queries is O(h(n=m)m1 ).
Ex
luding the prepro
essing phase, the total time for the di
tionary/queue operations is O(h log h)
in the traditional model, and O(h log h log n) in the permutation+bits model, be
ause of pointer
operations; this
ost is sublinear sin
e h < n" . If h is known, we
an set m = h1= and get an overall
running time of O(n log h) and an overall spa
e bound of O(n + h log n) = O(n) in bits. A standard
guessing tri
k [12
an remove the assumption that h is given in advan
e.
2
Proof:
The same approa
h as in Se
tion 2 works for the segment interse
tion problem. To avoid repetition,
we only point out the dieren
es. Here, H is a set of line segments, and T (R) is the trapezoidal
de
omposition of the arrangement of the segments in R. A new
ompli
ation is that the analysis
depends on the output parameter K , the number of interse
tions in H . For a random sample R of H
of size r, the expe
ted size of T (R) is now O(r + Kr2=n2), and
onsequently Lemma 2.1(i)
hanges
to
2
3
X
E4
jHjb5 = O((r + Kr2=n2) (n=r)b):
2T (R)
In Lemma 2.2, suppose that algorithm A spe
i
ally takes O(n log n + K ) time. Then algorithm
takes expe
ted time O((r + Kr2=n2) (n=r) log n + K ) = O(n log n + K ).
In Lemma 2.3, the algorithm
an be slightly simplied sin
e there are no output bits.
In Theorem 2.5, we again use oine 2-d point lo
ation (Lemma 2.4), this time, to lo
ate a
ell
in T (R)
ontaining ea
h left endpoint of H . For ea
h segment h, we
an
ompute the list of all
ells in T (R) interse
ting h by a a depth-rst sear
h, starting at the left endpoint; in the traditional
model, this takes time proportional to the sum of deg() over 2 T (R) interse
ting h, where
deg() denotes the number of
ells adja
ent to . From these lists, we obtain all the
on
i
t lists
H , stored in pointer stru
tures in the buer area. In the traditional model, the total time is
P
2T (R) jH j deg(). An analysis by Clarkson and Shor [20, proof of Theorem 4.6, 3rd paragraph
A0
10
bounds the expe
tation of this expression by O((r + Kr2=n2) (n=r)). Setting r = n= log n as before
would lead to an optimal expe
ted time bound, but the number of bits of extra spa
e used may not
be O(n log n). Instead, we pro
eed iteratively with dierent
hoi
esPof r as follows:
2 j , where Kj = 2j n log n in the j -th trial. If 2T (R) jH j deg()
0 n and
P We setjHr =j2 n =K
0Kj for a su
iently large
onstant
0, we de
lare the j -th trial su
essful and
2T (R)
solve the subproblems dire
tly by brute for
e in expe
ted time O(Kj ). The brute-for
e algorithm
simply
he
ks all pairs and needs
hP no extra spa
e. i
If
Kj K , then E 2T (R) jH j deg() = O((r + Kr2=n2 ) (n=r)) = O(n) and
i
hP
E 2T (R) jH j2 = O((r + Kr2=n2 ) (n=r)2) = O(Kj ). So, if Kj K , the probability that
iteration j is not su
essful
an be bounded by an arbitrarily small
onstant p. Letting f denote the
nal iteration, we have PrfKf > 2i maxfn log n; K gg pi, and so E [Kf = O(maxfn log n; K g).
Thus, the expe
ted total
ost is O(n log n + K ).
Note that we
an suppress printing during all iterations and rerun the nal iteration to print the
interse
tions. We
on
lude:
Theorem 3.1 There is an in-pla
e 2-d segment interse
tion algorithm that runs in O(n log n + K )
expe
ted time, where K denotes the number of interse
tions.
In this se
tion, we swit
h to the
a
he-oblivious model and give a simpler re-derivation of an optimal
3-d
onvex hull algorithm in this model, rst obtained by Kumar and Ramos [33. As in Se
tion 2.2,
the approa
h is based on random sampling. Again we need an e
ient oine point lo
ation method
as a subroutine. The lemma below serves this purpose.
Lemma 4.1 Suppose we are given a set P of N points and an arrangement R of r hyperplanes in
a
onstant dimension d. We
an lo
ate the
ell
p in the arrangement
ontaining ea
h point p 2 P ,
in O((N=B ) logM r + rO(1)) memory transfers.
The proof of this lemma was given by Kumar and Ramos [33 and will not be reprodu
ed here.
Roughly, we
an adopt, for example, the naive slab method [23 for point lo
ation, whi
h normally
has O(log r) query time and rO(1) prepro
essing time. The key subproblem is lo
ating a set of points
against a set of noninterse
ting hyperplanes inside a verti
al slab. This subproblem
an be solved
by a variant of an optimal
a
he-oblivious sorting algorithm. (One
annot dire
tly apply a sorting
algorithm, however, sin
e points are not
omparable against ea
h other, but one
an still adopt a
variant of the
a
he-oblivious distribution sort [30. Our situation is a
tually a little simpler, sin
e we
do not need to sort all N elements but just distribute N elements into r \bu
kets", while tolerating
an extra rO(1) term.)
Be
ause of the larger overhead rO(1) term, our
a
he-oblivious
onvex hull algorithm will need
re
ursion with a dierent sample size. The algorithm is still
on
eptually simple and is des
ribed in
the following theorem.
Below, it is more
onvenient to swit
h to another
ommon denition of random samples: a
p-sample R of H refers to a subset obtained by in
luding ea
h element in H independently with
probability p.
11
Theorem 4.2 There is a 3-d
onvex hull algorithm that takes O((N=B ) logM N ) expe
ted number
of memory transfers in the
a
he-oblivious model.
12
For the overall algorithm, we draw an (r=N )-sample R with r = N 1 ", run the above pro
edure, and then re
ursively
ompute the lower envelope for H inside for ea
h 2 T (R). (Restart
if (1) fails for R.)
The nal re
urren
e for the expe
ted
ost is
(P
T (N ) + O((N=B ) logM N ) if N > M
T (N ) = O(iN=B )i
else
P
where i Ni
N and maxi Ni = O(N " log N ). By
hoosing a
onstant " < 1=
, we
an verify by
indu
tion that the re
urren
e has solution O((N=M ) logM N ), sin
e
!
X 0
"(Ni=B ) logM N + (N=B ) logM N
!
X 0
(Ni=B ) logM Ni + (N=B ) logM N
i
0(N=B) logM N;
The same approa
h as in Se
tion 4 works for the segment interse
tion problem in the
a
he-oblivious
model. This time, we obtain a new result. We now point out the main dieren
es.
The
omputation of
on
i
t lists here
an still be redu
ed to point lo
ation for hyperplanes (so
Lemma 4.1 is still appli
able), but we need to lift to a higher dimension: Spe
i
ally, map ea
h input
line segment h to a point f (h) = (; ; 0; 0; ; ) 2 IR6, where (; ) and (0; 0) are the
oordinates
of the left and right endpoints, and x + y = 1 is the equation of the line through h. For ea
h vertex
of T (R) with
oordinates (a; b), form the hyperplane a + b = 1. For ea
h edge of T (R) with line
equation ax + by = 1, form the hyperplanes a + b = 1 and a0 + b0 = 1. If f (h1) and f (h2) lie
in the same
ell of the arrangement of these O(r) hyperplanes in IR6, then the segments h1 and h2
have the same set of interse
ting trapezoids in T (R), as required.
The rst re
urren
e is
hanged to
(P
T (N ; rN =N; K ) + O((N=B ) logM N ) if N > M and r > N "
T (N; r ; K ) = O((i N=Bi ) log i N ) i
else
M
2=N 2) N=r) =
where the Ni's and Ki's are random variables satisfying E [Pi Ni j N; K = O((r + Kr
P
1
"
1
"
"
O(N + K=N ), maxi Ni = O(N log t) with probability 1 O(N =t), and i Ki = K . For
r N 1 , the re
ursion depth is
onstant, and by indu
tion, one
an verify that T (N; r; K ) =
=N log N ).
O( N +Kr
M
B
The se
ond re
urren
e be
omes
(P
N +K=N log N ) if N > M
i T (Ni; Ki) + O( B
M
T (N; K ) =
O(N=B )
else
13
A knowledgements
We thank the anonymous referees for their detailed and useful
omments.
Referen
es
[1 P. K. Agarwal, L. Arge, and K. Yi. I/O-e
ient
onstru
tion of
onstrained Delaunay triangulations.
In Pro
. 13 European Sympos. Algorithms, Le
t. Notes Comput. S
i., vol. 3669, Springer-Verlag, pages
355{366, 2005.
[2 N. Amenta, S. Choi, and G. Rote. In
remental
onstru
tions
on BRIO. In
Comput. Geom., pages 211{219, 2003.
[3 L. Arge, T. Mlhave, and N. Zeh. Ca
he-oblivious red-blue line segment interse
tion. In Pro
. 16th
European Sympos. Algorithms, Le
t. Notes Comput. S
i., vol. 5193, Springer-Verlag, pages 88{99, 2008.
14
[5 H. Blun
k and J. Vahrenhold. In-pla
e algorithms for
omputing (layers of) maxima. In Pro
. 10th
S
and. Workshop Algorithm Theory, Le
t. Notes Comput. S
i., vol. 4059, Springer-Verlag, pages 363{374,
2006.
[6 P. Bose, E. Y. Chen, M. He, A. Maheshwari, and P. Morin. Su
in
t geometri
indexes supporting point
lo
ation queries. In Pro
. 20th ACM-SIAM Sympos. Dis
rete Algorithms, pages 635{644, 2009.
[7 P. Bose, A. Maheshwari, P. Morin, J. Morrison, M. Smid, and J. Vahrenhold. Spa
e-e
ient geometri
divide-and-
onquer algorithms. Comput. Geom. Theory Appl., 37:209{227, 2007.
[8 G. S. Brodal. Ca
he-oblivious algorithms and data stru
tures. In Pro
. 9th S
and.
Theory, Le
t. Notes Comput. S
i., vol. 3111, Springer-Verlag, pages 3{13, 2004.
Workshop Algorithm
[9 H. Bronnimann and T. M. Chan. Spa
e-e
ient algorithms for
omputing the
onvex hull of a simple
polygonal line in linear time. Comput. Geom. Theory Appl., 34:75{82, 2006.
[10 H. Bronnimann, T. M. Chan, and E. Y. Chen. Towards in-pla
e geometri
algorithms and data stru
tures.
In Pro
. 20th ACM Sympos. Comput. Geom., pages 239{246, 2004. Full version at http://www.
s.
uwaterloo.
a/~tm
han/inpla
e_jsub.pdf
[11 H. Bronnimann, J. Ia
ono, J. Katajainen, P. Morin, J. Morrison, and G. T. Toussaint. Spa
e-e
ient
planar
onvex hull algorithms. Theoret. Comput. S
i., 321:25{40, 2004.
[12 T. M. Chan. Optimal output-sensitive
onvex hull algorithms in two and three dimensions.
Comput. Geom., 16:361{368, 1996.
[13 T. M. Chan and E. Y. Chen. In-pla
e 2-d nearest neighbor sear
h. In Pro
. 19th
Dis
rete Algorithms, pages 904{911, 2008.
Dis rete
ACM-SIAM Sympos.
[14 T. M. Chan and M. Patras
u. Transdi
hotomous results in
omputational geometry, I: Point lo
ation in
sublogarithmi
time. SIAM J. Comput., to appear. Preliminary versions in Pro
. 47th IEEE Sympos.
Found. Comput. S
i., pages 325{332 and 333{342, 2006.
[15 T. M. Chan, J. Snoeyink, and C.-K. Yap. Primal dividing and dual pruning: output-sensitive
onstru
tion
of four-dimensional polytopes and three-dimensional Voronoi diagrams. Dis
rete Comput. Geom., 18:433{
454, 1997.
[16 B. Chazelle and H. Edelsbrunner. An optimal algorithm for interse
ting line segments in the plane.
ACM, 39:1{54, 1992.
J.
[17 B. Chazelle and J. Matousek. Derandomizing an output-sensitive
onvex hull algorithm in three dimensions. Comput. Geom. Theory Appl., 5:27{32, 1995.
[18 E. Y. Chen and T. M. Chan. A spa
e-e
ient algorithm for segment interse
tion. In Pro
. 15th
Conf. Comput. Geom., pages 68{71, 2003.
[19 K. L. Clarkson. New appli
ations of random sampling in
omputational geometry.
Geom., 2:195{222, 1987.
Canad.
[20 K. L. Clarkson and P. W. Shor. Appli
ations of random sampling in
omputational geometry, II. Dis
rete
Comput. Geom., 4:387{421, 1989.
[21 A. Crauser, P. Ferragina, K. Mehlhorn, U. Meyer, and E. Ramos. Randomized external-memory algorithms for line segment interse
tion and other geometri
problems. Int. J. Comput. Geom. Appl.,
11:305{337, 2001.
[22 E. D. Demaine.
erikdemaine.org/papers/BRICS2002/
15
http://
SIAM J. Comput.
, 5:181{186, 1976.
[24 H. Edelsbrunner, L. Guibas, and J. Stol. Optimal point lo
ation in a monotone subdivision.
Comput., 15:317{340, 1986.
[25 G. Fran
es
hini and V. Geert. An in-pla
e sorting with O(n log n)
omparisons and
ACM, 52:515{537, 2005.
SIAM J.
O(n) moves.
[26 G. Fran
es
hini and R. Grossi. Optimal impli
it di
tionaries over unbounded universes.
Comput. Sys., 39:321{345, 2006.
J.
Theory of
[27 G. Fran
es
hini, R. Grossi, J. I. Munro, and L. Pagli. Impli
it B-trees: a new data stru
ture for the
di
tionary problem. J. Comput. Sys. S
i., 68:788{807, 2004.
[28 G. Fran
es
hini and S. Muthukrishnan. In-pla
e sux sorting. In Pro
. 34th Int. Colloq. Automata,
Languages, and Programming, Le
t. Notes Comput. S
i., vol. 4596, Springer-Verlag, pages 533{545, 2007.
[29 G. Fran
es
hini, S. Muthukrishnan, and M. Patras
u. Radix sorting with no extra spa
e. In Pro
.
15th European Sympos. Algorithms, Le
t. Notes Comput. S
i., vol. 4698, Springer-Verlag, pages 194{205,
2007.
[30 M. Frigo, C. E. Leiserson, H. Prokop, and S. Rama
handran. Ca
he-oblivious algorithms. In Pro
. 40th
IEEE Sympos. Found. Comput. S
i., pages 285{297, 1999.
[31 D. Kirkpatri
k. Optimal sear
h in planar subdivisions.
[32 P. Kumar. Ca
he oblivious algorithms. Algorithms for
vol. 2625, Springer-Verlag, pages 193{212, 2003.
SIAM J. Comput.
, 12:28{35, 1983.
, Le
t. Notes Comput. S
i.,
[33 P. Kumar and E. Ramos. I/O e
ient
onstru
tion of Voronoi diagrams. Manus
ript, 2002. http://
iteseerx.ist.psu.edu/viewdo
/summary?doi=10.1.1.59.6760
of Computational Geometry
. Prenti e-
[36 J. I. Munro. An impli
it data stru
ture supporting insertion, deletion, and sear
h in O(log2 n) time.
Comput. Sys. S
i., 33:66{74, 1986.
[37 F. P. Preparata. A new approa
h to planar point lo
ation.
[38 F. P. Preparata and S. J. Hong.
Commun. ACM, 20:87{93, 1977.
[39 F. P. Preparata and M. I. Shamos.
York, 1985.
J.
, 10:473{482, 1981.
SIAM J. Comput.
[40 N. Sarnak and R. E. Tarjan. Planar point lo
ation using persistent sear
h trees.
679, 1986.
Commun. ACM
[41 R. Seidel and U. Adamy. On the exa
t worst
ase
omplexity of planar point lo
ation.
37:189{217, 2000.
[42 J. Vahrenhold. Line-segment interse
tion made in-pla
e.
2007.
16
, 29:669{
,
J. Algorithms
, 38:213{230,