cmsc754 Spring2020 Lects
cmsc754 Spring2020 Lects
Computational Geometry1
David M. Mount
Department of Computer Science
University of Maryland
Spring 2020
1
Copyright, David M. Mount, 2020, Dept. of Computer Science, University of Maryland, College Park, MD,
20742. These lecture notes were prepared by David Mount for the course CMSC 754, Computational Geometry, at
the University of Maryland. Permission to use, copy, modify, and distribute these notes for educational purposes and
without fee is hereby granted, provided that this copyright notice appear in all copies.
than one running in O(n log n) time which is better than one running in O(n2 ) time. (This
particular problem can be solved in O(n2 log n) time by a fairly simple algorithm, in O(n log n)
by a relatively complex algorithm, and it can be approximated quite well by an algorithm
whose running time is O(n log n).) In some cases average case running time is considered
instead. However, for many types of geometric inputs (this one for example) it is difficult to
define input distributions that are both easy to analyze and representative of typical inputs.
Overview of the Semester: Here are some of the topics that we will discuss this semester.
Convex Hulls: Convexity is a very important geometric property. A geometric set is convex
if for every two points in the set, the line segment joining them is also in the set. One of
the first problems identified in the field of computational geometry is that of computing
the smallest convex shape, called the convex hull, that encloses a set of points (see Fig. 2).
Intersections: One of the most basic geometric problems is that of determining when two
sets of objects intersect one another. Determining whether complex objects intersect
often reduces to determining which individual pairs of primitive entities (e.g., line seg-
ments) intersect (see Fig. 2). We will discuss efficient algorithms for computing the
intersections of a set of line segments.
Triangulation and Partitioning: Triangulation is a catchword for the more general prob-
lem of subdividing a complex domain into a disjoint collection of “simple” objects (see
Fig. 2). The simplest region into which one can decompose a planar object is a trian-
gle (a tetrahedron in 3-d and simplex in general). We will discuss how to subdivide a
polygon into triangles and later in the semester discuss more general subdivisions into
trapezoids.
Optimization and Linear Programming: Many optimization problems in computational
geometry can be stated in the form of linear programming, namely, finding the extreme
points (e.g. highest or lowest) that satisfies a collection of linear inequalities. Linear
programming is an important problem in the combinatorial optimization, and people
often need to solve such problems in hundred to perhaps thousand dimensional spaces.
Line Arrangements and Duality: Perhaps one of the most important mathematical struc-
tures in computational geometry is that of an arrangement of lines (or generally the
arrangement of curves and surfaces). Given n lines in the plane, an arrangement is just
the graph formed by considering the intersection points as vertices and line segments
joining them as edges (see Fig. 4). We will show that such a structure can be constructed
in O(n2 ) time.
The reason that this structure is so important is that many problems involving points
can be transformed into problems involving lines by a method of point-line duality. In
the plane, this is a transformation that maps lines to points and points to lines (or
generally, (d − 1)-dimensional hyperplanes in dimension d to points, and vice versa).
For example, suppose that you want to determine whether any three points of a planar
point set are collinear. This could be determined in O(n3 ) time by brute-force checking
of each triple. However, if the points are dualized into lines, then (as we will see later
q
q
p
Fig. 5: Geometric search problems. The point-location query determines the triangle containing q.
The nearest-neighbor query determines the point p that is closest to q.
P conv(P )
The (planar) convex hull problem is, given a discrete set of n points P in the plane, output a
representation of P ’s convex hull. The convex hull is a closed convex polygon, the simplest
representation is a counterclockwise enumeration of the vertices of the convex hull. In higher
dimensions, the convex hull will be a convex polytope. We will discuss the representation of
Convexity: Before getting to discussion of the algorithms, let’s begin with a few standard defini-
tions regarding convexity and convex sets. For any d ≥ 1, let Rd denote real d-dimensional
space, that is, the set of d-dimensional vectors over the real numbers.
Affine and convex combinations: Given two points p = (px , py ) and q = (qx , qy ) in Rd ,
we can generate any point on the line ←
→ as a linear combination of their coordinates,
pq
where the coefficient sum to 1:
By adding the additional constraint that 0 ≤ α ≤ 1, the set of points generated lie on
the line segment pq (see Fig. 7(b)). This is called a convex combination. Notice that this
can be viewed as taking a weighted average of p and q. As α approaches 1, the point
lies closer to p and when α approaches zero, the point lies closer to q.
It is easy to extend both types of combinations to more than two points. For example,
given k points {p1 , . . . , pk } an affine combination of these points is the linear combination
k
X
αi p i , such that α1 + · · · + αk = 1.
i=1
Boundedness: A convex set is bounded if it can be enclosed within a sphere of a fixed radius.
Otherwise, it is unbounded (see Fig. 8(c)). For example, line segments, regular n-gons,
and circular disks are all bounded. In contrast, lines, rays, halfspaces, and infinite cones
are unbounded.
Convex body: A closed, bounded convex set is called a convex body.
Support line/hyperplane: An important property of any convex set K in the plane is that
at every point p on the boundary of K, there exists at least one line ` (or generally a
(d − 1)-dimensional hyperplane in higher dimensions) that passes through p such that
K lies entirely in one of the closed halfplanes (halfspaces) defined by ` (see Fig. 8(d)).
Such a line is called a support line for K. Observe that there may generally be multiple
support lines passing through a given boundary point of K (e.g., when the point is a
vertex of the convex hull).
Equivalent definitions: We can define the convex hull of a set of points P either in an
additive manner as the closure of all convex combinations of the points or in a subtractive
manner as the intersection of the set of all halfspaces that contain the point set.
When computing convex hulls, we will usually take P to be a finite set of points. In such a
case, conv(P ) will be a convex polygon. Generally P could be an infinite set of points. For
example, we could talk about the convex hull of a collection of circles. The boundary of such
a shape would consist of a combination of circular arcs and straight line segments.
General Position: As in many of our algorithms, it will simplify the presentation to avoid lots
of special cases by assuming that the points are in general position. This effectively means
that degenerate configurations (e.g., two points sharing the same x or y coordinate, three
points being collinear, etc.) do not arise in the input. More specifically, a point set fails to
lower hull
(a) (b)
Fig. 9: (a) Upper and lower hulls and (b) the left-hand turn property of points on the upper hull.
It suffices to show how to compute the upper hull, since the lower hull is symmetrical. (Just flip
the picture upside down.) Once the two hulls have been computed, we can simply concatenate
them with the reversal of the other to form the final hull.
Observe that a point p ∈ P lies on the upper hull if and only if there is a support line passing
through p such that all the points of P lie on or below this line. Our algorithm will be based
on the following lemma, which characterizes the upper hull of P . This is a simple consequence
of the convexity. The first part says that the line passing through each edge of the hull is a
support line, and the second part says that as we walk from right to left along the upper hull,
we make successive left-hand turns (see Fig. 9(b)).
Lemma 1: Let hpi1 , . . . , pim i denote the vertices of the upper hull of P , sorted from left to
Let hp1 , . . . , pn i denote the sequence of points sorted by increasing order of x-coordinates.
For i ranging from 1 to n, let Pi = hp1 , . . . , pi i. We will store the vertices of the upper hull of
Pi on a stack S, where the top-to-bottom order of the stack corresponds to the right-to-left
order of the vertices on the upper hull. Let S[t] denote the stack’s top. Observe that as we
read the stack elements from top to bottom (that is, from right to left) consecutive triples of
points of the upper hull form a (strict) left-hand turn (see Fig. 9(b)). As we push new points
on the stack, we will enforce this property by popping points off of the stack that violate it.
Turning and orientations: Before proceeding with the presentation of the algorithm, we should
first make a short digression to discuss the question of how to determine whether three points
form a “left-hand turn.” This can be done by a powerful primitive operation, called an
orientation test, which is fundamental to many algorithms in computational geometry.
Given an ordered triple of points hp, q, ri in the plane, we say that they have positive orienta-
tion if they define a counterclockwise oriented triangle (see Fig. 10(a)), negative orientation
if they define a clockwise oriented triangle (see Fig. 10(b)), and zero orientation if they are
collinear, which includes as well the case where two or more of the points are identical (see
Fig. 10(c)). Note that orientation depends on the order in which the points are given.
Orientation is formally defined as the sign of the determinant of the points given in homoge-
neous coordinates, that is, by prepending a 1 to each coordinate. For example, in the plane,
we define
1 px py
Orient(p, q, r) = det 1 qx qy .
1 rx ry
Observe that in the 1-dimensional case, Orient(p, q) is just q − p. Hence it is positive if p < q,
zero if p = q, and negative if p > q. Thus orientation generalizes the familiar 1-dimensional
binary relations <, =, >.
Also, observe that the sign of the orientation of an ordered triple is unchanged if the points
are translated, rotated, or scaled (by a positive scale factor). A reflection transformation
(e.g., f (x, y) = (−x, y)) reverses the sign of the orientation. In general, applying any affine
transformation to the point alters the sign of the orientation according to the sign of the
determinant of the matrix used in the transformation. (By the way, the notion of orientation
can be generalized to d + 1 points in d-dimensional space, and is related to the notion of
pop pop
Graham’s Scan
(1) Sort the points according to increasing order of their x-coordinates, denoted hp1 , p2 , . . . , pn i.
(2) push p1 and then p2 onto S.
(3) for i ← 3, . . . , n do:
(a) while (|S| ≥ 2 and Orient(pi , S[t], S[t − 1]) ≤ 0) pop S.
(b) push pi onto S.
Correctness: The correctness of the algorithm was essentially established by Lemma 1 and the
above explanation. (Where we showed that it is safe to pop all right-turning triples off the
stack, and safe to push pi .) The only remaining issue is whether we might stop too early.
In particular, might we encounter a left-turning triple before reaching pj ? We claim that
this cannot happen. Suppose to the contrary that before reaching pj , we encounter triple
hpi , S[t], S[t − 1]i that forms a left-hand turn, but S[t] 6= pj (see Fig. 12). We know that S[t]
lies to the right of pj . By Lemma 1, all the points of Pi−1 (including pj ) lie on or below the
line S[t]S[t − 1]. But if pj lies below this line, it follows that the triple hpi , S[t], pj i forms a
left-hand turn, and this implies that S[t] lies above the line pj pi . This contradicts Lemma 1,
because by our hypothesis, pj pi is an edge of the upper hull of Pi , and no point of Pi can lie
above an edge of the upper hull.
How much detail? A question that often arises at this point of the semester is, “how much detail
is needed in giving a geometrical proof of correctness?” You might find the above proof to be
a bit too vague. There is a bit of art between the extremes of producing proofs that are not
convincing from those that contain excessive details. Whenever feasible, you should reduce
base-level assertions to configurations involving just a constant number of points (e.g., the
points involved in an orientation test). It may be helpful to add additional constructions
(e.g., support lines) to help illustrate points. Don’t be fooled by your drawings. Finally, note
that more detail is not always better. Your proof is intended to be read by a human, not
a compiler or automated proof verifier. You should rely your (intelligent) reader to fill in
low-level geometric reasoning.
Running-time analysis: We will show that Graham’s algorithm runs in O(n log n) time. Clearly,
it takes this much time for the initial sorting of the points. After this, we will show that O(n)
time suffices for the rest of the computation.
Let di denote the number of points that are popped (deleted) on processing pi . Because each
orientation test takes O(1) time, the amount of time spent processing pi is O(di + 1). (The
extra +1 is for the last point tested, which is not deleted.) Thus, the total running time is
proportional to
Xn Xn
(di + 1) = n + di .
i=1 i=1
P
To bound i di , observe that each of the n points is pushed onto the stack once. Once a
point P
is deleted it can never be deleted again. Since each of n points can be deleted at most
once, i di ≤ n. Thus after sorting, the total running time is O(n). Since this is true for the
lower hull as well, the total time is O(2n) = O(n).
Convex Hull by Divide-and-Conquer: As with sorting, there are many different approaches
to solving the convex hull problem for a planar point set P . Next, we will consider another
O(n log n) algorithm, which is based on divide-and-conquer. It can be viewed as a generaliza-
tion of the well-known MergeSort sorting algorithm (see any standard algorithms text). Here
is an outline of the algorithm. As with Graham’s scan, we will focus just on computing the
upper hull, and the lower hull will be computed symmetrically.
The algorithm begins by sorting the points by their x-coordinate, in O(n log n) time. In splits
the point set in half at its median x-coordinate, computes the upper hulls of the left and right
sets recursively, and then merges the two upper hulls into a single upper hull. This latter
process involves computing a line, called the upper tangent, that is a line of support for both
hulls. The remainder of the algorithm is shown in the code section below.
Computing the upper tangent: The only nontrival step is that of computing the common tan-
gent line between the two upper hulls. Our algorithm will exploit the fact that the two
hulls are separated by a vertical line. The algorithm operates by a simple “walking proce-
dure.” We initialize p0 to be the rightmost point of H 0 and p00 to be the leftmost point of
p00
upper tangent
H 00 p0 H 00
H0 H0
H 00 (see Fig. 14(a)). We will walk p0 backwards along H 0 and walk p00 forwards along H 00
until we hit the vertices that define the tangent line. As in Graham’s scan, it is possible
to determine just how far to walk simply by applying orientation tests. In particular, let q 0
be the point immediately preceding p0 on H 0 , and let q 00 be the point immediately following
p00 on H 00 . Observe that if Orient(p0 , p00 , q 00 ) ≥ 0, then we can advance p00 to the next point
along H 00 (see Fig. 14(a)). Symmetrically, if Orient(p00 , p0 , q 0 ) ≤ 0, then we can advance p0
to its predecessor along H 0 (see Fig. 14(b)). When neither of these conditions applies, that
is, Orient(p0 , p00 , q 00 ) < 0 and Orient(p00 , p0 , q 0 ) > 0, we have arrived at the desired points of
mutual tangency (see Fig. 14(c)).
q 00 p00 00
q
q0 p0
q0
p0 p00 p00
p0
There is one rather messy detail in implementing this algorithm. This arises if either q 0 or q 00
does not exist because we have arrived at the leftmost vertex of H 0 or the rightmost vertex
of H 00 . We can avoid having to check for these conditions by creating two sentinel points.
We create a new leftmost vertex for H 0 that lies infinitely below its original leftmost vertex,
and we create a new rightmost vertex for H 00 that lies infinitely below its original rightmost
vertex. The tangency computation will never arrive at these points, and so we do not need
A formal proof of correctness of this procedure is similar to that of Graham’s scan (but
observe that there are now two tangency conditions to be satisfied, not just one). We will
leave it as an exercise. Observe that the running time is O(n), because with each step we
spend O(1) time and eliminate a point either from H 0 or from H 00 as a candidate for the
tangency points, and there are at most n points that can be so eliminated.
Running-time analysis: The asymptotic running time of the algorithm can be expressed by a
recurrence. Given an input of size n, consider the time needed to perform all the parts of
the procedure, ignoring the recursive calls. This includes the time to partition the point set,
compute the upper tangent line, and return the final result. Clearly, each of these can be
performed in O(n) time, assuming any standard list representation of the hull vertices. Thus,
ignoring constant factors, we can describe the running time by the following recurrence:
1 if n ≤ 3
T (n) =
n + 2T (n/2) otherwise.
This is the same recurrence that arises in Mergesort. It is easy to show that it solves to
T (n) ∈ O(n log n) (see any standard algorithms text).
x2 x4 x3 x5 x1 x2 x4 x3 x5 x1
Theorem: Assuming computations based on comparisons (e.g., orientation tests) any algo-
rithm for the convex hull problem requires Ω(n log n) time in the worst case.
• What if we don’t require that the points be enumerated in cyclic order? For example,
suppose we just want to count number of points on the convex hull. Can we do better?
• Suppose that we are not interested in worst-case behavior. For example, in many in-
stances of convex hull, relatively few points lie on the boundary of the hull.
• We will present a convex hull algorithm that runs O(nh) time, where h is the number of
vertices on the hull. (This is beats the worst-case bound is h is asymptotically smaller
than O(log n).)
• We will present Chan’s algorithm, which computes convex hulls in O(n log h) time.
• We will present a lower bound argument that shows that, assuming a comparison-based
algorithm, even answering the question “does the convex hull have h distinct vertices?”
requires Ω(n log h) time.
The last result implies that Chan’s algorithm is essentially the best possible as a function of
h and n.
Gift-Wrapping and Jarvis’s March: Our next convex hull algorithm, called Jarvis’s march,
computes the convex hull in O(nh) time by a process called “gift-wrapping.” In the worst
case, h = n, so this is inferior to Graham’s algorithm for large h, it is superior if h is
target
pk
source
p3
pi
pi−1 p2
p1 p0 = (−∞, 0) p1
(a) (b) (c)
Clearly, each iteration can be performed in O(n) time, and after h iterations, we return to
the starting vertex. Thus, the total time is O(nh). As a technical note, the algorithm can
be simplified by adding a sentinel point p0 at the (conceptual) coordinates (−∞, 0). The
algorithm starts with the horizontal ray −
p−→
0 p1 (see Fig. 16(c)).
Chan’s Algorithm: Depending on the value of h, Graham’s scan may be faster or slower than
Jarvis’ march. This raises the intriguing question of whether there is an algorithm that always
does as well or better than these algorithms. Next, we present a planar convex hull algorithm
by Timothy Chan whose running time is O(n log h).
While this algorithm is too small an improvement over Graham’s algorithm to be of significant
practical value, it is quite interesting nonetheless from the perspective of the techniques that
it uses:
• It combines two slower algorithms, Graham’s and Jarvis’s, to form a faster algorithm.
• It employs an interesting guessing strategy to determine the value of a key unknown
parameter, the number h of vertices on the hull.
Chan’s algorithm: The principal shortcoming of Graham’s scan is that it sorts all the points,
and hence is doomed to having an Ω(n log n) running time, irrespective of the size of the hull.
While Jarvis’s algorithm is not limited in this way, it is way too slow if there are many points
on the hull.
The first observation needed for a better approach is that, if we hope to achieve a running
time of O(n log h), we can only afford a log factor depending on h. So, if we run Graham’s
algorithm, we are limited to sorting sets of size at most h.
P1 H1
Step 1: Mini-hulls We start by partitioning the point set P into groups of size h∗ (the
last group may have fewer than h∗ elements). Call these P1 , . . . , Pm where r = dn/h∗ e
(see Fig. 17(b)). This can be done arbitrarily, without any regard for their geometric
structure. By Graham’s algorithm, we can compute the convex hull of each subset in
time O(h∗ log h∗ ). Let H1 , . . . , Hm denote the resulting mini-hulls. The total time to
compute all the mini-hulls is
O(r(h∗ log h∗ )) = O((n/h∗ )h∗ log h∗ ) = O(n log h∗ ) = O(n log h).
Good so far. We are within our overall time budget
Step 2: Merging the minis: The high-level idea is to run Jarvis’s algorithm, but we treat
each mini-hull as if it is a “fat point” (see Fig. 18(a)). Recall that in Jarvis’s algorithm,
we computed the angle between a source ray and a target ray, where the source ray
−−−→
pi−1 pi was the previous edge of the hull and the target ray − p− →
i pk went to the next vertex
of the hull. We modify this so that the target ray will now be a “tangent ray” or more
properly a line of support for a mini-hull Hk that passes through pi and has Hk lying to
the left of the ray, from the perspective of someone facing the direction of the ray (see
Fig. 18(b)). Among all the mini-hulls, Hk is the one that minimizes the angles in these
rays (see Fig. 18(c)).
Note that the current edge − −−→
pi−1 pi is on the global convex hull, so it cannot lie in the
interior of any of the mini-hulls. Among all these tangents, we take the one that yields
the smallest external angle (see Fig. 18(c)). Since each of the mini-hulls is represented as
a convex polygon having at most h∗ vertices, we claim that we can compute this tangent
in O(log h∗ ) = O(log h) time through a variant of binary search. This is formalized in
the following lemma, whose proof we will leave as an exercise.
Lemma: Consider a convex polygon K in the plane stored as an array of vertices in
cyclic order, and let p be any point external to K. The two supporting lines of K
passing through p can each be computed in time O(log m), where m is the number
of vertices of K.
H4 H4
H3 H2 H3 H2
Hk qk
H1 pi H1 pi
pi−1 pi−1
Each step of Jarvis’s algorithm on the mini-hulls takes O(r log h∗ ) = O(r log h) time to
compute the support lines and select the one forming the smallest angle.
The Conditional Algorithm: We can now present a conditional algorithm for computing the
convex hull. The algorithm is given a point set P and an estimate h∗ of the number of
vertices on P ’s convex hull. Letting h denote the actual number of vertices, if h ≤ h∗ ,
then this algorithm computes the final hull. Otherwise, the algorithm “fails”, reporting that
h > h∗ , and terminates. This is presented in the code block below.
Chan’s Algorithm for the Conditional Hull Problem
∗
ConditionalHull(P, h ) :
(1) Let r ← dn/h∗ e
(2) Partition P into disjoint subsets P1 , . . . , Pr , each of size at most h∗
(3) For i ← 1 to r:
i Compute Hi = conv(Pi ) using Graham’s scan and store the vertices in an ordered array
(4) Let p0 ← (−∞, 0) and let p1 be the bottommost point of P
(5) For i ← 1 to h∗ :
(a) For j ← 1 to r:
i Compute the support line of Hj that passes through pi , and let qj be the associated vertex
of Hj
(b) Set pi+1 be the point of {q1 , . . . , qr } that minimizes the angle between the rays −
p−−−→
i−1 pi and
−−→
pi qj
(c) If pi+1 = p1 then return success (hp1 , . . . , pk i is the final hull)
(6) Return failure (conv(P ) has more than h∗ vertices)
Observe the following: (1) the Jarvis phase never performs for more than h∗ stages, and (2)
if h ≤ h∗ , the algorithm succeeds in computing the entire hull. To analyze its running time,
recall that the computation of the mini-hulls takes O(n log h) time (under the assumption that
h∗ ≤ h2 ). Each iteration of the Jarvis phase takes O(r log h) time, where r ≈ n/h∗ . Since there
cannot be more than h∗ iterations, this takes total time O(h∗ r log h) = O(h∗ (n/h∗ ) log h) =
O(n log h) time. So, we are within our overall time budget.
Determining the Hull’s Size: The only question remaining is how do we know what value to
give to h∗ ? Remember that, if h∗ ≥ h, the algorithm will succeed in computing the hull,
The summation is a geometric series. It is well known that a geometric series is asymptotically
dominated by its largest term. Thus, we obtain a total running time of
which is just what we want. In other words, by the “miracle” of the geometric series, the
total time to try all the previous failed guesses is asymptotically the same as the time for the
final successful guess. The final algorithm is presented in the code block below.
Chan’s Complete Convex Hull Algorithm
Hull(P ) :
(1) h∗ ← 2; status ← fail
(2) while status 6= fail:
(a) Let h∗ ← min((h∗ )2 , n)
(b) status ← ConditionalHull(P, h∗ )
(3) Return L.
2
When log n appears as a factor within asymptotic big-O notation, the base of the logarithm does not matter
provided it is a constant. This is because loga n = logb n/ logb a. Thus, changing the base only alters the constant
factor.
Convex Hull Size Verification Problem (CHSV): Given a point set P and integer h,
does the convex hull of P have h distinct vertices?
Clearly if this takes Ω(n log h) time, then computing the hull must take at least as long.
As with sorting, we will assume that the computation is described in the form of a decision
tree. The sorts of decisions that a typical convex hull algorithm will make will likely involve
orientation primitives. Let’s be even more general, by assuming that the algorithm is allowed
to compute any algebraic function of the input coordinates. (This will certainly be powerful
enough to include all the convex hull algorithms we have discussed.) The result is called an
algebraic decision tree.
The input to the CHSV problem is a sequence of 2n = N real numbers. We can think of these
numbers as forming a vector in real N -dimensional space, that is, (z1 , z2 , . . . , zN ) = ~z ∈ RN ,
which we will call a configuration. Each node branches based on the sign of some function of
the input coordinates. For example, we could implement the conditional zi < zj by checking
whether the function (zj − zi ) is positive. More relevant to convex hull computations, we can
express an orientation test as the sign of the determinant of a matrix whose entries are the
six coordinates of the three points involved. The determinant of a matrix can be expressed
as a polynomial function of the matrices entries. Such a function is called algebraic. We
assume that each node of the decision tree branch three ways, depending on the sign of a
given multivariate algebraic formula of degree at most d, where d is any fixed constant. For
example, we could express the orientation test involving points p1 = (z1 , z2 ), p2 = (z3 , z4 ),
and p3 = (z5 , z6 ) as an algebraic function of degree two as follows:
1 z1 z2
det 1 z3 z4 = (z3 z6 − z5 z4 ) − (z1 z6 − z5 z2 ) + (z1 z4 − z3 z2 ).
1 z5 z6
For each input vector ~z to the CHSV problem, the answer is either “yes” or “no”. The set
of all “yes” points is just a subset of points Y ⊂ RN , that is a region in this space. Given an
We say that two points ~u, ~v ∈ Y are in the same connected component of Y if there is a
path in RN from ~u to ~v such that all the points along the path are in the set Y . (There
are two connected components in the figure.) We will make use of the following fundamental
result on algebraic decision trees, due to Ben-Or. Intuitively, it states that if your set has M
connected components, then there must be at least M leaves in any decision tree for the set,
and the tree must have height at least the logarithm of the number of leaves.
Theorem: Let Y ∈ RN be any set and let T be any d-th order algebraic decision tree that
determines membership in W . If W has M disjoint connected components, then T must
have height at least Ω((log M ) − N ).
Multiset Size Verification Problem (MSV): Given a multiset of n real numbers and an
integer k, confirm that the multiset has exactly k distinct elements.
Lemma: The MSV problem requires Ω(n log k) steps in the worst case in the d-th order
algebraic decision tree
Proof: In terms of points in Rn , the set of points for which the answer is “yes” is
It suffices to show that there are at least k!k n−k different connected components in this
set, because by Ben-Or’s result it would follow that the time to test membership in Y
would be
Consider the all the tuples (z1 , . . . , zn ) with z1 , . . . zk set to the distinct integers from 1
to k, and zk+1 . . . zn each set to an arbitrary integer in the same range. Clearly there are
To finish the lower bound proof, we argue that any instance of MSV can be reduced to the
convex hull size verification problem (CHSV). Thus any lower bound for MSV problem applies
to CHSV as well.
The proof is rather unsatisfying, because it relies on the fact that there are many duplicate
points. You might wonder, does the lower bound still hold if there are no duplicates? Kirk-
patric and Seidel actually prove a stronger (but harder) result that the Ω(n log h) lower bound
holds even you assume that the points are distinct.
• In solid modeling complex shapes are constructed by applying various boolean operations
(intersection, union, and difference) to simple primitive shapes. The process is called
constructive solid geometry (CSG). Computing intersections of model surfaces is an
essential part of the process.
• In robotics and motion planning it is important to know when two objects intersect for
collision detection and collision avoidance.
• In geographic information systems it is often useful to overlay two subdivisions (e.g. a
road network and county boundaries to determine where road maintenance responsibili-
ties lie). Since these networks are formed from collections of line segments, this generates
a problem of determining intersections of line segments.
• In computer graphics, ray shooting is a classical method for rendering scenes. The
computationally most intensive part of ray shooting is determining the intersection of
the ray with other objects.
In this lecture, we will focus the basic primitive of computing line segment intersections in
the plane.
General-position assumptions
no duplicate coordinates
(no vertical/horizontal segments)
no endpoint lies on
another segment
no collinear segments
(a) (b)
Observe that n line segments can intersect in as few as zero and as many as n2 = O(n2 )
different intersection points. We could settle for an O(n2 ) time algorithm, claiming that it is
worst-case asymptotically optimal, but it would not be very useful in practice, since in many
instances of intersection problems intersections may be rare. Therefore, it seems reasonable
to design an output sensitive algorithm, that is, one whose running time depends not only on
the input size, but also on the output size.
Given a set S of n line segments, let m = m(S) denote the number of intersections. We will
express the running time of our algorithm in terms of both n and m. As usual, we will assume
that the line segments are in general position.
Plane Sweep Algorithm: Let us now consider a natural approach for reporting the segment
intersections. The method, called plane sweep, is a fundamental technique in planar compu-
tational geometry. We solve a 2-dimensional problem by simulating the process of sweeping
a 1-dimensional line across the plane. The intersections of the sweep line with the segments
defines a collection of points along the sweep line.
Although we might visualize the sweeping process as a continuous one, there is a discrete set
of event points where important things happen. As the line sweeps from left to right, points
are inserted, deleted, and may swap order along the sweep line. Thus, we reduce a static
2-dimensional problem to a dynamic 1-dimensional problem.
In any algorithm based on plane sweep there are three basic elements that need to be main-
tained (see Fig. 21):
(1) the partial solution that has already been constructed to the left of the sweep line (in
our case, the intersection pointsj to the left of the sweep line),
(2) the sweep-line status, that is, the set of objects intersecting the current sweep line (in
our case, the sorted segments intersecting the sweep line), and
(3) a subset of the future events to be processed (in our case, the intersection points to the
right of the sweep line).
`
Fig. 21: Plane sweep.
The key to designing an efficient plane-sweep algorithm is determining how to efficiently store
and update these three elements as each new event is process. Let’s consider each of these
elements in greater detail in the context of line-segment intersection.
Sweep line status and above-below comparisons: We will simulate the sweeping of a vertical
line ` from left to right. The sweep-line status consists of the line segments that intersect
the sweep line sorted, say, from top to bottom. In order to maintain this set dynamically, we
will store them in an appropriate data structure, an ordered dictionary to be precise (e.g.,
a red-black tree or skiplist). Such a data structure stores objects from some totally ordered
domain and supports the operations find, insert, delete, predecessor, and successor each in
O(log m) time, where m is the current number of entries in the dictionary. We will also need
to swap two adjacent elements.
But hey! How can we possibly do this efficiently? Every time we move the sweep line even
a tiny distance, all the y-coordinates of the intersection points change as well! Clearly, we
cannot store the y-coordinates explicitly, for otherwise we would be doomed to O(n) time per
event, which would lead to an overall running time that is at least quadratic.
The key is that we do not need store the actual y-coordinates in the dictionary. We simply
need to implement a function which is given the x-coordinate of the current sweep line, call
it x0 , and two segments si and sj . This function determines which segment intersects the
sweep line above the other. Let’s call this a dynamic comparator.
Observe that between consecutive event points (intersection points or segment endpoints) the
relative vertical order of segments is constant (see Fig. 22(a)). For each segment, we can
compute the associated line equation, and evaluate this function at x0 to determine which
segment lies on top. The ordered dictionary does not need actual numbers. It just needs a
way of comparing objects (see Fig. 22(b)).
Dynamic comparator: (Techincal aside) We are given the sweep line x = x0 and two
segments si and sj . Assuming each segment is nonvertical and has endpoints pi =
(pi,x , pi,y ) and qi = (qi,x , qi,y ), we can compute the associated line equations `i : y =
ai x + bi and `j : y = aj x + bj , by solving the simultaneous equations
sj sj yj (x0) = aj x0 + bj
(a) (b)
Fig. 22: The dictionary does not need to store absolute y-coordinates, just the ability to make
above-below comparisons for any location of the sweep line.
which yields
pi,y − qi,y pi,x qi,y − pi,y qi,x
ai = bi = .
pi,x − qi,x pi,x − qi,x
(Because the segment is nonvertical, the denominator is nonzero.)
Given that the sweep line is at x = x0 , we can define our dynamic comparator to be:
Events and Detecting Intersections: It suffices to process events only when there is a change
in the sweep-line status. As mentioned above, these x-coordinates are called event points.
For our application, we have three types of event points, corresponding to when the sweep
line encounters: (1) the left endpoint of a segment, (2) the right endpoint of a segment, and
(3) an intersection point between two segments.
Note that endpoint events ((1) and (2)) can be presorted before the sweep runs. In contrast,
intersection events (3) will be discovered dynamically as the sweep executes. It is important
that each event be detected before the actual event occurs. Since each pair of segments along
the sweep line might intersect, there are O(n2 ) potential intersection events to consider, which
again would doom us to at least quadratic running time. How can we limit the number of
potential intersection points to a manageable number?
Our strategy will be as follows. Whenever two line segments become adjacent along the
sweep line (one immediately above the other), we will check whether they have an intersection
occurring to the right of the sweep line. If so, we will add this new event to a priority queue
of future events. This priority queue will be sorted in left-to-right order by x-coordinates.
We call this the adjacent-segment rule.
A natural question is whether this strategy of scheduling intersections between adjacent pairs
is correct. In particular, might it be that two line segments intersect, but just prior to this
Lemma: Consider a set S of line segments in general position, and consider two segments
si , sj ∈ S that intersect in some point p. Then si and sj are adjacent along the sweep
line just after the event that immediately precedes p in the sweep.
Proof: By general position, it follows that no three lines intersect in a common point. There-
fore if we consider a placement of the sweep line that is infinitesimally to the left of the
intersection point, the line segments si and sj will be adjacent along this sweep line.
Consider the event point q with the largest x-coordinate that is strictly less than px .
Since there are no events between qx and px , there can be no segment intersections
within the vertical slab bounded by q on the left and p on the right (the shaded region
of Fig. 22), and therefore the order of lines along the sweep line after processing q will
be identical the order of the lines along the sweep line just prior p. Therefore, si and sj
are adjacent immediately after processing event q and remain so just prior to processing
p.
q
si
adjacent p
sj
`
Fig. 23: Correctness of the adjacent-segment rule.
When two formerly adjacent segments cease to be adjacent (e.g., because a new segment is
discovered between them), we will delete the event from the queue. While this is not formally
necessary, it keeps us from inserting the same event point repeatedly and it guarantees that
the total number of events can never exceed O(n).
Data Structures: As mentioned above the segments that intersect the sweep line will be main-
tained in an ordered dictionary, sorted vertically from top to bottom. The future event points
(segment endpoints and impending intersection points) will be stored in a priority queue,
which will be ordered from left to right by x-coordinates.
Here are the operations assumed to be supported by the ordered dictionary, which stores the
sweep-line status:
All of these operations can be performed in O(log n0 ) time and O(n0 ) space, where n0 is
the current number of entries in the dictionary using any balanced binary search tree (see
the algorithms book by CLRS). Note that along with each entry in the dictionary we can
associated additional auxiliary information (such as any future events associated within this
entry.) In our case, the entries to be inserted will be line segments (each associated with a
symbolic key, as described above).
Next, here are the operations assumed to be supported by the priority queue, which stores
the future events sorted by the x-coordinates:
• r ← insert(e, x): Insert event e with “priority” x and return a reference r to its location
in the data structure.
• delete(r): Delete the entry associated with reference r.
• (e, x) ← extract-min(): Extract and return the event from the queue with the smallest
priority x.
Again, all of these operations can be performed in O(log n0 ) and O(n0 ) space, where n0 is the
current number of entries in the data structure through the use of any standard binary heap
structure (see CLRS).
The Final Algorithm: All that remains is explaining how to process the events. This is presented
in the code block below, and the various cases are illustrated in Fig. 23. (Further details can
be found in the 4M’s.)
Computing Intersection Points: (Technical aside) We have assumed that the primitive of com-
puting the intersection point of two line segments can be performed exactly in O(1) time.
Let us see how we might do this. Let ab and cd be two line segments in the plane, given
by their endpoints, for example a = (ax , ay ). First observe that it is possible to determine
whether these line segments intersect, simply by applying an appropriate combination of ori-
entation tests. (We will leave this as an exercise.) However, this alone is not sufficient for the
plane-sweep algorithm.
One way to determine the point at which the segments intersect is to use a parametric
representation of the segments. Any point on the line segment ab can be written as a convex
combination involving a real parameter s:
p(s) = (1 − s)a + sb, for 0 ≤ s ≤ 1,
and similarly for cd we may introduce a parameter t:
q(t) = (1 − t)c + td, for 0 ≤ t ≤ 1
(see Fig. 25).
An intersection occurs if and only if we can find s and t in the desired ranges such that
p(s) = q(t). Thus we obtain the two equations:
(1 − s)ax + sbx = (1 − t)cx + tdx and (1 − s)ay + sby = (1 − t)cy + tdy .
The coordinates of the points are all known, so it is just a simple exercise in linear algebra to
solve for s and t as functions of the coordinates of a, b, c, and d. (A solution may generally
not exist, but this means that the segments are parallel. By our assumption that no segments
are collinear, this implies that the segments do not intersect.) Once s and t are known, it
remains to just check with 0 ≤ s, t ≤ 1, to confirm that the intersection point occurs within
the line segment (and not in the extended infinite line).
As in our earlier example of determining the order of segments along the sweep line, if all
the coordinates are integers, this yields formulas for s and t as rational numbers, and hence
the coordinates of the intersection point are themselves rational numbers. If it is needed to
perform exact computations on these coordinates, rather than converting them to floating
point, it is possible to save the numerator and denominator of each coordinate as a pair of
(multiple precision) integers.
Correctness: The correctness of the algorithm essentially follows from our extensive derivation to
the algorithm itself. Formally, the correctness proof is based on an induction proof showing
that immediately after processing each event: (a) the sweep-line status contains the line
segments intersecting the sweep line in sorted order and (b) the event queue contains exactly
all the events demanded by the adjacent-segment rule.
Analysis: Altogether, there are 2n + m events processed. Each event involves a constant amount
of work and a constant number of accesses to our data structures. As mentioned above, each
access to either of the data structures takes O(log n) time. Therefore, the total running time
is O((2n + m) log n) = O(n log n + m log n). Note that if we output each intersection point
without storing it, the total storage requirements never exceed O(n). In summary, we have:
Theorem: Given a set of n line segments S in the plane (subject to our general-position
assumptions), the above algorithm correctly reports all the m intersections between
these segments in time O((n + m) log n) time and O(n) space.
Lower Bound: Is this the best possible? No. There is a faster algorithm (which we may discuss
later in the semester) that runs in time O(n log n + m). This latter algorithm is actually
optimal. Clearly Ω(m) time is needed to output the intersections. The lower bound of
Ω(n log n) results from a reduction from a problem called element uniqueness. In this problem,
we are give a list of n numbers X = hx1 , . . . , xn i and we are asked whether there are any
duplicates (or all are distinct). Element uniqueness is known to have a lower bound of
Ω(n log n) in the algebraic decision-tree model of computation. (It can be solved in O(n)
time using hashing, but the algebraic decision-tree model does not allow integer division,
which is needed by hashing.)
The reduction involves converting each xi into a line segment si that passes through the
point (xi , 0), but otherwise there are no other intersections. (A little cleverness is needed to
guarantee that the general-position assumptions are satisfied.) Clearly, two segments si and
Applications: Triangulating simple polygons is important for many reasons. This operation use-
ful, for example, whenever it is needed to decompose a complex shapes a set of disjoint simpler
shapes. Note that in some applications it is desirable to produce “fat” (nearly equilateral)
triangles, but we will not worry about this issue in this lecture.
A triangulation provides a simple graphical representation of the polygon’s interior, which
is useful for algorithms that operate on polygons. In particular, consider a graph whose
vertices are the triangles of the triangulation and two vertices of this graph are adjacent if
the associated triangles are adjacent (see Fig. 26(c)). This is called the dual graph of the
triangulation. It is easy to show that such a graph is a free tree, that is, it is an acylic,
connected graph. (If the polygon has holes, then the dual graph will generally have cycles.)
Preliminaries: This simple problem has been the focus of a remarkably large number of papers
in computational geometry spanning a number of years. There is a simple naive polynomial-
time algorithm for the planar case (as opposed to possibly nonconvex polyhedra in higher
dimensions). The idea is based on repeatedly adding “diagonals.” We say that two points on
the boundary of the polygon are visible if the interior of the line segment joining them lies
entirely within the interior of the polygon. Define a diagonal of the polygon to be the line
segment joining any pair of visible vertices.
Observe that the addition of a diagonal splits the polygon into two polygons of smaller size.
In particular, if the original polygon has n vertices, the diagonal splits the polygon into two
polygons with n1 and n2 vertices, respectively, where n1 , n2 < n, and n1 + n2 = n + 2. Any
simple polygon with at least four vertices has at least one diagonal. (This seemingly obvious
fact is not that easy to prove. You might try it.) A simple induction argument shows that
the final number of diagonals is n − 3 and the final number of triangles is n − 2.
The naive algorithm operates by repeatedly adding diagonals. Unfortunately, this algorithm
is not very efficient (unless the polygon has special properties, for example, convexity) because
of the complexity of the visibility test.
• First, the simple polygon is decomposed into a collection of simpler polygons, called
monotone polygons. This step takes O(n log n) time.
• Second, each of the monotone polygons is triangulated separately, and the result are
combined. This step takes O(n) time.
Monotone Polygons: Let’s begin with a few definitions. A polygonal curve is a collection of
line segments, joined end-to-end (see Fig. 27(a)). If the last endpoint is equal to the first
endpoint, the polygonal curve is said to be closed. The line segments are called edges. The
endpoints of the edges are called the vertices of the polygonal curve. Each edge is incident to
two vertices (its endpoints), and each vertex is incident (to up) two edges. A polygonal curve
is said to be simple if no two nonincident elements intersect each other (see Fig. 27(c)). A
closed simple polygonal curve decomposes the plane into two parts, its interior and exterior.
Such a polygonal curve is called a simple polygon (see Fig. 27(c)). When we say “polygon”
we mean simple polygon.
A polygonal curve C is monotone with respect to ` if each line that is orthogonal to ` intersects
C in a single connected component. (It may intersect, not at all, at a single point, or along
a single line segment.) A polygonal curve C is said to be strictly monotone with respect to
a given line `, if any line that is orthogonal to ` intersects C in at most one point. A simple
polygon P is said to be monotone with respect to a line ` if its boundary, (sometimes denoted
bnd(P ) or ∂P ), can be split into two curves, each of which is monotone with respect to ` (see
Fig. 28(a)).
Henceforth, let us consider monotonicity with respect to the x-axis. We will call these poly-
gons horizontally monotone. It is easy to test whether a polygon is horizontally monotone.
How?
(a) Find the leftmost and rightmost vertices (min and max x-coordinate) in O(n) time.
(b) These vertices split the polygon’s boundary into two curves, an upper chain and a lower
chain. Walk from left to right along each chain, verifying that the x-coordinates are
nondecreasing. This takes O(n) time.
(As an exercise, consider the problem of determining whether a polygon is monotone in any
direction. This can be done in O(n) time.)
13 1 34 1 34 5
6
7 7 11 12 7 11 12
2 2 2
10 10
1 34 5 8 1 34 5 8 9 1 34 5 8 9
6 6 6 13
Fig. 29: Triangulating a monotone polygon.
To acquire some intuition, let’s consider the example shown in Fig. 29. There is obviously
nothing to do until we have at least three vertices. With vertex 3, it is possible to add the
diagonal to vertex 2, and so we do this. In adding vertex 4, we can add the diagonal to vertex
2. However, vertices 5 and 6 are not visible to any other nonadjacent vertices so no new
diagonals can be added. When we get to vertex 7, it can be connected to 4, 5, and 6. The
process continues until reaching the final vertex.
Have we seen enough to conjecture what the untriangulated region to the left of the sweep
line looks like? Ideally, this structure will be simple enough to allow us to determine in
constant time whether it is possible to add another diagonal. And in general we can add each
additional diagonal in constant time. Since any triangulation consists of n − 3 diagonals, the
process runs in O(n) total time. This structure is described in the lemma below.
Lemma: (Main Invariant) For i ≥ 2, let vi be the vertex just processed by the triangulation
algorithm. The untriangulated region lying to the left of vi consists of two x-monotone
chains, a lower chain and an upper chain each containing at least one edge. If the chain
from vi to u has two or more edges, then these edges form a reflex chain. The other
chain consists of a single edge whose left endpoint is u and whose right endpoint lies to
the right of vi (see Fig. 30(a)).
We will prove the invariant by induction, and in the process we will describe the triangulation
algorithm. As the basis case, consider the case of v2 . Here u = v1 , and one chain consists of
the single edge v2 v1 and the other chain consists of the other edge adjacent to v1 . To complete
the proof, we will give a case analysis of how to handle the next event, involving vi , assuming
that the invariant holds at vi−1 , and see that the invariant is satisfied after each event has
been processed. There are the following cases that the algorithm needs to deal with.
Case 1: vi lies on the opposite chain from vi−1 : In this case we add diagonals joining vi to all
the vertices on the reflex chain, from vi−1 back to (but not including) u (see Fig. 30(b)).
Note that all of these vertices are visible from vi . Certainly u is visible to vi . Because
the chain is reflex, x-monotone, and lies to the left of vi it follows that the chain itself
cannot block the visibility from vi to some other vertex on the chain. Finally, the fact
that the polygon is x-monotone implies that the unprocessed portion of the polygon
(lying to the right of vi ) cannot “sneak back” and block visibility to the chain.
vi
u u u u
vi−1 vi−1 vi−1 vi−1
vi
(a) (b) (c) (d)
Case 2: v is on the same chain as vi−1 . There are two subcases to be considered:
Case 2(a): The vertex vi−1 is a nonreflex vertex: We walk back along the reflex chain
adding diagonals joining vi to prior vertices until we find the last vertex vj of the
chain that is visible to vi . As can be seen in Fig. 30(c), this will involve connecting
vi to one or more vertices of the chain. Remove these vertices from vi−1 back to,
but not including vj from the reflex chain. Add vi to the end of reflex chain. (You
might observe a similarity between this step and the inner loop of Graham’s scan.)
Case 2(b): The vertex vi−1 is a reflex vertex. In this case vi cannot see any other
vertices of the chain. In this case, we simply add vi to the end of the existing reflex
chain (see Fig. 30(d)).
In either case, when we are done the remaining chain from vi to u is a reflex chain.
How is this implemented? The vertices on the reflex chain can be stored in a stack. We keep
a flag indicating whether the stack is on the upper chain or lower chain, and assume that
with each new vertex we know which chain of the polygon it is on. Note that decisions about
visibility can be based simply on orientation tests involving vi and the top two entries on the
stack. When we connect vi by a diagonal, we just pop the stack.
Analysis: We claim that this algorithm runs in O(n) time. As we mentioned earlier, the sorted
list of vertices can be constructed in O(n) time through merging. The reflex chain is stored on
a stack. In O(1) time per diagonal, we can perform an orientation test to determine whether
to add the diagonal and the diagonal can be added in constant time. Since the number of
diagonals is n − 3, the total time is O(n).
Monotone Subdivision: In order to run the above triangulation algorithm, we first need to
subdivide an arbitrary simple polygon P into monotone polygons. This is also done by a
plane-sweep approach. We will add a set of nonintersecting diagonals that partition the
polygon into monotone pieces (recall Fig. 28).
Observe that the absence of x-monotonicity occurs only at vertices in which the interior angle
is greater than 180◦ and both edges lie either to the left of the vertex or both to the right.
We call such a vertex a scan reflex vertex. Following our book’s notation, we call the first
type a merge vertex (since as the sweep passes over this vertex the edges seem to be merging)
and the latter type a split vertex.
Merge
Our approach will be to apply a left-to-right plane sweep (see Fig. 32(a)), which will add
diagonals to all the split and merge vertices. We add a diagonal to each split vertex as soon
as we reach it. We add a diagonal to each merge vertex when we encounter the next visible
vertex to its right.
The key is storing enough information in the sweep-line status to allow us to determine where
this diagonal will go. When a split vertex v is encountered in the sweep, there will be an edge
ea of the polygon lying above and an edge eb lying below. We might consider attaching the
split vertex to left endpoint of one of these two edges, but it might be that neither endpoint
is visible to the split vertex. Instead, we need to maintain a vertex that is visible to any split
vertex that may arise between ea and eb . To do this, imagine a sweeping a vertical segment
between ea and eb to the left until it hits a vertex. Called this helper(ea ) (see Fig. 32(b)).
helper(ea) helper(e1)
ea ea e1
e2
v v e3
helper(e3)
e4
eb eb e5
sweep line sweep line e6
helper(e5)
(a) (b) (c)
helper(ea ) : Let eb be the edge of the polygon lying just below ea on the sweep line. The
helper is the rightmost vertically visible vertex on or below ea on the polygonal chain
between ea and eb . This vertex may either be on ea , eb , or it may lie between them.
Another way to visualize the helper is to imagine sweeping out a trapezoid to the left from
the sweep line. The top side of the trapezoid lies on ea , the bottom side lies on eb , the right
side lies on the sweep line, and the left side is sweeps as far as it can until hitting a vertex
(see the shaded regions of Figs. 32(b) and (c)).
Observe that helper(ea ) is defined with respect to the current location of the sweep line. As
the sweep line moves, its value changes. The helper is defined only for those edges intersected
by the sweep line. Our approach will be to join each split vertex to helper(ea ), where ea is
the edge of P immediately above the split vertex. (Note that it is possible that the helper is
the left endpoint of ea .) When we hit a merge vertex, we cannot add a diagonal right away.
Events: The endpoints of the edges of the polygon. These are sorted by increasing order of
x-coordinates. Since no new events are generated, the events may be stored in a simple
sorted list (i.e., no priority queue is needed).
Sweep status: The sweep line status consists of the list of edges that intersect the sweep
line, sorted from top to bottom. (Our book notes that we actually only need to store
edges such that the interior of the polygon lies just below this edge, since these are the
only edges that we evaluate helper from.)
These edges are stored in a dictionary (e.g., a balanced binary tree), so that the opera-
tions of insert, delete, find, predecessor and successor can be evaluated in O(log n) time
each.
Event processing: There are six event types based on a case analysis of the local structure
of edges around each vertex. Let v be the current vertex encountered by the sweep (see
Fig. 33). Recall that, whenever we see a split vertex, we add a diagonal to the helper
of the edge immediately above it. We defer adding diagonals to merge vertices until the
next opportunity arises. To help with this, we define a common action called “fix-up.”
It is given a vertex v and an edge e (either above v or incident to its left). The fix-up
function adds a diagonal to helper(e), if helper(e) is a merge vertex.
fix-up(v, e): If helper(e) is a merge vertex, add a diagonal from v to this merge vertex.
Split vertex(v): Search the sweep line status to find the edge e lying immediately above
v. Add a diagonal connecting v to helper(e). Add the two edges incident to v into
the sweep line status. Let e0 be the lower of these two edges. Make v the helper of
both e and e0 .
Merge vertex(v): Find the two edges incident to this vertex in the sweep line status
(they must be adjacent). Let e0 be the lower of the two. Delete them both. Let e
be the edge lying immediately above v. fix-up(v, e) and fix-up(v, e0 ). Set the helper
of e to v.
Start vertex(v): (Both edges lie to the right of v, but the interior angle is smaller than
π.) Insert this vertex’s edges into the sweep line status. Set the helper of the upper
edge to v.
End vertex(v): (Both edges lie to the left of v, but the interior angle is larger than π.)
Let e be the upper of the two edges. fix-up(v, e). Delete both edges from the sweep
line status.
Upper-chain vertex(v): (One edge is to the left, and one to the right, and the polygon
interior is below.) Let e be the edge just to the left of v. fix-up(v, e). Replace the
edge to v’s left with the edge to its right in the sweep line status. Make v the helper
of the new edge.
Lower-chain vertex(v): (One edge is to the left, and one to the right, and the polygon
interior is above.) Let e be the edge immediately above v. fix-up(v, e). Replace the
edge to v’s left with the edge to its right in the sweep line status. Make v the helper
of the new edge.
Correctness: Given the number of cases, establishing correctness is a bit of a pain. We will refer
you to the 4M’s book for a careful proof, but here are main points that need to be established
in the proof.
Helpers are correctly updated: Immediately after processing each event, the helpers of
all relevant edges have been properly updated.
Merge vertices are correctly resolved: Whenever we encounter a merge vertex, we add
a diagonal to resolve this non-monotonicity.
Split vertices are correctly resolved: When a split vertex is visited, it becomes a helper
of the edge e immediately above. We will resolve this non-monotonicity when e’s helper
changes by the invocation of fix-up.
Added diagonals do not intersect each other: Added diagonals lie within a single “helper
trapezoid” which has no vertices except on its left and right vertical sides. If both of
these vertices are scan reflex vertices (merger on the left and split on the right) we will
add a single diagonal to resolve both (see the Split case of Fig. 33).
Analysis: Given a simple polygon with n vertices, there are n events, one for each vertex. Each
event involves a constant amount of processing and a constant number of accesses to the
sweep-line dictionary. Thus, the time per event is O(log n), and hence the overall time is
O(n log n). We have the following:
Theorem: Given an n-vertex simple polygon, in O(n log n) time, the above sweep-line algo-
rithm correctly add diagonals to decompose it into monotone pieces.
By combining this with the O(n) time algorithm for triangulating a monotone polygon, we
obtain the following result.
Theorem: Given a simple polygon with n vertices, it is possible to triangulate it in O(n log n)
time.
Clearly, the number of sides of the resulting polygon is at most n, but may be smaller since
some halfspaces may not contribute to the final shape.
Representing Lines and Hyperplanes: (Digression) While we will usually treat geometric ob-
jects rather abstractly, it may be useful to explore a bit regarding how lines, halfspaces, and
their higher dimensional counterparts are represented. These topics would be covered in a
more complete course on projective geometry or convexity.
If we let I(n) denote the time needed to intersect two convex polygons, each with at most n
vertices, we obtain the following recurrence for the overall running time:
1 if n = 1,
T (n) =
2T (n/2) + I(n) if n > 1,
We will show below that I(n) ≤ cn, for some constant c. It follows by standard results
(consult the Master Theorem in CLRS) that T (n) is O(n log n).
Intersecting Two Convex Polygons: The only remaining task is the process of intersecting two
convex polygons, K1 and K2 (see Fig. 35(a)). Note that these are somewhat special convex
polygons because they may be empty or unbounded.
We can compute the intersection by a left-to-right plane sweep in O(n) time (see Fig. 35(b)).
We begin by breaking the boundaries of the convex polygons into their upper and lower chains.
(This can be done in O(n) time.) By convexity, the sweep line intersects the boundary of
each convex polygon Ki in at most two points, one for the upper chain and one for the lower
chain. Hence, the sweep-line status contains at most four points. This implies that updates to
the sweep-line status can be performed in O(1) time. Also, we need keep track of a constant
number of events at any time, namely the right endpoints of the current segments in the
sweep-line status, and the intersections between consecutive pairs of segments. Thus, each
step of the plane-sweep process can be performed in O(1) time.
K2 K2
K = K1 ∩ K2
K = K1 ∩ K2
K1 K1
(a) (b)
The total number of events is equal to the total number vertices, which is n, and the total
number of intersection points. It is an easy exercise (which we leave to you) to prove that two
convex polygons with a total of n sides can intersect at most O(n) times. Thus, the overall
running time is O(n).
Lower Envelopes and Duality: Let’s next consider a variant of the halfplane intersection prob-
lem. Given any set of nonvertical lines L = {`1 , `2 , . . . , `n } in the plane. Each line defines two
natural halfplanes, and upper and lower halfplane. The intersection of all the lower halfplanes
is called the lower envelope of L and the upper envelope is defined analogously (see Fig. 36).
Let’s assume that each line `i is given explicitly as y = ai x − bi .
upper envelope
lower envelope
The lower envelope problem is a restriction of the halfplane intersection problem, but it an
interesting restriction. Notice that any halfplane intersection problem that does not involve
any vertical lines can be rephrased as the intersection of two envelopes, a lower envelope
defined by the lower halfplanes and an upper envelope defined by the upward halfplanes.
We will see that solving the lower envelope problem is very similar (in fact, essentially the
same as) solving the upper convex hull problem. Indeed, they are so similar that exactly the
same algorithm will solve both problems, without changing even a single character of code!
All that changes is the way in which you interpret the inputs and the outputs.
Lines, Points, and Incidences: In order to motivate duality, let us discuss the representation
of lines in the plane. Each line can be represented in a number of ways, but for now, let us
assume the representation y = ax − b, for some scalar values a and b. (Why −b rather than
We’ll show that these relationships are preserved by duality. For example, consider the two
lines `1 : y = 2x + 1 and the line `2 : y = − x2 + 6 (see Fig. 37(a)). These two lines intersect
at the point p = (2, 5). The duals of these two lines are `∗1 = (2, −1) and `∗2 = − 12 , −6 . The
line in the (a, b) dual plane passing through these two points is easily verified to be b = 2a − 5.
Observe that this is exactly the dual of the point p (see Fig. 37(b)). (As an exercise, prove
this for two general lines.)
Primal Dual
`1 : y = 2x + 1 p∗ : b = 2a − 5
y b
p = (2, 5)
a
`2 : y = − x2 + 6 `∗1 = (2, −1)
x
`∗2 = − 12 , −6
(a) (b)
Point-Line Duality: Let us explore this dual transformation more formally. Duality (or more
specifically point-line duality) is a transformation that maps points in the plane to lines and
lines to point. (More generally, it maps points in d-space to hyperplanes dimension d.) We
denote this transformation using a asterisk (∗) as a superscript. Thus, given point p and line
` in the primal plane we define `∗ and p∗ to be a point and line, respectively, in the dual plane
defined as follows.3
` : y = `a x − `b ⇒ `∗ = (`a , `b )
p = (px , py ) ⇒ p∗ : b = px a − py .
3
Duality can be generalized to higher dimensions as well. In Rd , let us identify the y axis with the d-th coordinate
vector, so that an arbitrary point can be written as p = (x1 , . . . , xd−1 , y) and a (d − 1)-dimensional hyperplane can be
Order reversing
`1 : y = 2x + 1 p∗ is below `∗1 and above `∗2
y
b p∗ : b = a − 4
p is above `1 and below `2
p = (1, 4) a
`∗1 = (2, −1)
`2 : y = − x2 + 6
x
`∗2 = − 12 , −6
(a) (b)
The self inverse property was already established (essentially by definition). To verify the
order reversing property, consider any point p and any line `.
p is on or above ` ⇐⇒ py ≥ `a px − `b ⇐⇒ `b ≥ px `a − py ⇐⇒ p∗ is on or below `∗
(From this it should be apparent why we chose to negate the y-intercept when dualizing points
to lines.) The other two properties (intersection preservation and collinearity/coincidence are
direct consequences of the order reversing property.)
Convex Hulls and Envelopes: Let us return now to the question of the relationship between
convex hulls and the lower/upper envelopes of a collection of lines in the plane. The following
lemma demonstrates the, under the duality transformation, the convex hull problem is dually
equivalent to the problem of computing lower and upper envelopes.
Lemma: Let P be a set of points in the plane. The counterclockwise order of the points along
the upper (lower) convex hull of P (see Fig. 39(a)), is equal to the left-to-right order of
the sequence of lines on the lower (upper) envelope of the dual P ∗ (see Fig. 39(b)).
written as h : y = d−1 ∗
P
i=1 ai xi − b. The dual of this hyperplane is h = (a1 , . . . , ad−1 , b) and the dual of the point p is
∗ P d−1
p : b = i=1 xi ai − y. All the properties defined for point-line relationships generalize naturally to point-hyperplane
relationships, where notions of above and below are based on the assumption that the y (or b) axis is “vertical.”
(a) (b)
Proof: We will prove the result just for the upper hull and lower envelope, since the other
case is symmetrical. For simplicity, let us assume that no three points are collinear.
Consider a pair of points pi and pj that are consecutive vertices on the upper convex
hull. This is equivalent to saying that all the other points of P lie beneath the line `ij
that passes through both of these points.
Consider the dual lines p∗i and p∗j . By the incidence preserving property, the dual point
`∗ij is the intersection point of these two lines. (By general position, we may assume that
the two points have different x-coordinates, and hence the lines have different slopes.
Therefore, they are not parallel, and the intersection point exists.)
By the order reversing property, all the dual lines of P ∗ pass above point `∗ij . This is
equivalent to saying the `∗ij lies on the lower envelope of P ∗ .
To see how the order of points along the hulls are represented along the lower envelope,
observe that as we move counterclockwise along the upper hull (from right to left), the
slopes of the edges increase monotonically. Since the slope of a line in the primal plane
is the a-coordinate of the dual point, it follows that as we move counterclockwise along
the upper hull, we visit the lower envelope from left to right.
One rather cryptic feature of this proof is that, although the upper and lower hulls appear
to be connected, the upper and lower envelopes of a set of lines appears to consist of two
disconnected sets. To make sense of this, we should interpret the primal and dual planes from
the perspective of projective geometry, and think of the rightmost line of the lower envelope
as “wrapping around” to the leftmost line of the upper envelope, and vice versa. The places
where the two envelopes wraps around correspond to the vertical lines (having infinite slope)
passing through the left and right endpoints of the hull. (As an exercise, can you see which
is which?)
Primal/Dual Equivalencies: There are a number of computational problems that are defined
in terms of affine properties of point and line sets. These can be expressed either in primal
or in dual form. In many instances, it is easier to visualize the solution in the dual form. We
will discuss many of these later in the semester. For each of the following, can you determine
what the dual equivalent is?
• Given a set of points P , find the narrowest slab (that is, a pair of parallel lines) that
• Given a convex polygon K, find the longest vertical line segment with one endpoint on
K’s upper hull and one on its lower hull (see Fig. 40(b)).
• Given a set of points P , find the triangle of smallest area determined by any three points
of P (see Fig. 40(c)). (If three points are collinear, then they define a degenerate triangle
of area 0.)
feasible feasible
polytope polytope
(a) (b)
assume that the objective is to maximize the objective function. If we think of (c1 , . . . , cd ) as
a vector in Rd , the value of the objective function is just the projected length of the vector
(x1 , . . . , xd ) onto the direction defined by the vector c. It is not hard to see that (assuming
general position), if a solution exists, it will be achieved by a vertex of the feasible polytope,
called the optimal vertex (see Fig. 41(b)).
In general, a d-dimensional linear programming problem can be expressed as:
Maximize: c1 x1 + c2 x2 + · · · + cd xd
Subject to: a1,1 x1 + · · · + a1,d xd ≤ b1
a2,1 x1 + · · · + a2,d xd ≤ b2
..
.
an,1 x1 + · · · + an,d xd ≤ bn ,
where ai,j , ci , and bi are given real numbers. This can be also be expressed in matrix notation:
Maximize: cT x,
Subject to: Ax ≤ b.
where c and x are d-vectors, b is an n-vector and A is an n × d matrix. Note that c should be
a nonzero vector, and n should be at least as large as d and may generally be much larger.
There are three possible outcomes of a given LP problem:
Feasible: The optimal point exists (and assuming general position) is a unique vertex of the
feasible polytope (see Fig. 42(a)).
Infeasible: The feasible polytope is empty, and there is no solution (see Fig. 42(b)).
Unbounded: The feasible polytope is unbounded in the direction of the objective function,
and so no finite optimal solution exists (see Fig. 42(c)).
In our figures (in case we don’t provide arrows), we will assume the feasible polytope is the
intersection of upper halfspaces. Also, we will usually take the objective vector c to be a
vertical vector pointing downwards. (There is no loss of generality here, because we can
always rotate space so that c is parallel any direction we like.) In this setting, the problem is
just that of finding the lowest vertex (minimum y-coordinate) of the feasible polytope.
optimum
optimal
vertex
(a) (b) (c)
hi
hi
h2 h1
vi?
`i
c vi = vi−1 c c
v2 vi−1
Fig. 43: (a) Starting the incremental construction and (b) the proof that the new optimum lies on
`i .
We will then add halfspaces one by one, hd+1 , hd+2 , . . ., and with each addition we update
the current optimum vertex, if necessary. Let vi denote the optimal feasible vertex after
the addition of {h1 , h2 , . . . , hi }. Notice that with each new constraint, the feasible polytope
generally becomes smaller, and hence the value of the objective function at optimum vertex
can only decrease. (In terms of our illustrations, the y-coordinate of the feasible vertex
increases.)
There are two cases that can arise when hi is added. In the first case, vi−1 lies within the
halfspace hi , and so it already satisfies this constraint (see Fig. 43(b)). If so, then it is easy
to see that the optimum vertex does not change, that is vi = vi−1 .
In the second case vi−1 violates constraint hi . In this case we need to find a new optimum
vertex (see Fig. 44(c)). Let us consider this case in greater detail. The key observation
is presented in the following claim, which states that whenever the old optimum vertex is
infeasible, the new optimum vertex lies on the bounding hyperplane of the new constraint.
Lemma: If after the addition of constraint hi the LP is still feasible but the optimum vertex
changes, then the new optimum vertex lies on the hyperplane bounding hi .
Proof: Let `i denote the bounding hyperplane for hi . Let vi−1 denote the old optimum
vertex. Suppose towards contradiction that the new optimum vertex vi does not lie on
`i (see Fig. 43(c)). Consider the directed line segment vi−1 vi . Observe first that as you
travel along this segment the value of the objective function decreases monotonically.
(This follows from the linearity of the objective function and the fact that vi−1 is no
longer feasible.) Also observe that, because it connects a point that is infeasible (lying
below `i ) to one that is feasible (lying strictly above `i ), this segment must cross `i .
Thus, the objective function is maximized at the crossing point itself, which lies on `i , a
contradiction.
5
Our textbook explains how to overcome these assumptions in O(n) additional time.
`i c `i
hi intersect with `i c0
vi
vi
vi−1
project onto Rd−1
c0
(a) (b)
The recursion ends when we drop down to an LP in 1-dimensional space (see Fig. 44(b)). The
projected objective vector c0 is a vector pointing one way or the other on the real line. The
intersection of each halfspace with `i is a ray, which can be thought of as an interval on the
line that is bounded on one side and unbounded on the other. Computing the intersection of
a collection of intervals on a line can be done easily in linear time, that is, O(i − 1) time in
this case. (This interval is the heavy solid line in Fig. 44(b).) The new optimum is whichever
endpoint of this interval is extreme in the direction of c0 . If the interval is empty, then the
feasible polytope is also empty, and we may terminate the algorithm immediately and report
that there is no solution. Because, by assumption, the original LP is bounded, it follows that
the (d − 1)-dimensional LP is also bounded.
Worst-Case Analysis: What is the running time of this algorithm? Ignoring the initial d halfs-
paces, there are n − d halfspace insertions performed. In step i, we may find that the current
optimum vertex is feasible. This takes O(d) time. The alternative is that we need to solve a
(d − 1)-dimensional LP with i − 1 constraints. It takes O(d(i − 1)) to intersect each of the
constraints with `i and O(d) time to project c onto `i . If we let Td (n) denote the time to run
this algorithm in dimension d with n constraints. In this case the time is O(di + Td−1 (i − 1)).
Since there are two alternatives, the running time is the maximum of the two. Ignoring
constant factors, the running time can be expressed by the following recurrence formula:
n
X
Td (n) = max d, di + Td−1 (i − 1) .
i=d+1
The basis case of the recurrence occurs when d = 1, and we just solve the interval intersection
problem described above in O(n) time by brute force. Thus, we have T1 (n) = n. It is easy to
verify by induction 6 that this recurrence solves to Td (n) = O(nd ), which is not very efficient.
Notice that this worst-case analysis is based on the rather pessimistic assumption that the
current vertex is always infeasible. Although there may exist insertion orders for which this
might happen, we might wonder whether we can arrange the insertion order so this worst
case does not occur. We’ll consider this alternative next.
Randomized Algorithm: Suppose that we apply the above algorithm, but we insert the halfs-
paces in random order (except for the first d, which need to be chosen to provide an initial
feasible vertex.) This is an example of a general class of algorithms called randomized incre-
mental algorithms. A description is given in the code block below.
Randomized Incremental d-Dimensional Linear Programming
Input: A set H = {h1 , . . . , hn } of (d − 1)-dimensional halfspaces, such that the first d define an initial
feasible vertex vd , and the objective vector c.
Output: The optimum vertex v or an error status indicating that the LP is infeasible.
(1) If the dimension is 1, solve the LP by brute force in O(n) time.
(2) Let vd be the intersection point of the hyperplanes bounding h1 , . . . , hd , which we assume define an
initial feasible vertex. Randomly permute the remaining halfspaces, and let hhd+1 , . . . , hn i denote the
resulting sequence.
(3) For i = d + 1 to n do:
(a) If (vi−1 ∈ hi ) then vi ← vi−1 .
(b) Otherwise, intersect {h1 , . . . , hi−1 } with the (d − 1)-dimensional hyperplane `i that bounds hi and
project onto Rd−1 . Let c0 be the projection of c onto `i and then onto Rd−1 . Solve the resulting
(d − 1)-dimensional LP recursively.
(i) If the (d − 1)-dimensional LP is infeasible, terminate and report that the LP is infeasible.
(ii) Otherwise, let vi be the solution to the (d − 1)-dimensional LP.
(4) Return vn as the final solution.
What is the expected case running time of this randomized incremental algorithm? Note
that the expectation is over the random permutation of the insertion order. We make no
assumptions about the distribution of the input. (Thus, the analysis is in the worst-case with
respect to the input, but in the expected case with respect to random choices.)
The number of random permutations is (n − d)!, but it will simplify things to pretend that
we permute all the halfspaces, and so there are n! permutations. Each permutation has an
equal probability of 1/n! of occurring, and an associated running time. However, presenting
6
Suppose inductively that there exists a sufficiently large constant α such that Td (n) ≤ αnd . The basis case is
trivial. Assuming the induction hypothesis holds for dimension d − 1, we have
n
X n
X n
X
i + α(i − 1)d−1 αnd−1 ≤ αnd .
Td (n) = i + Td−1 (i − 1) ≤ ≤
i=d+1 i=d+1 i=1
Computing the Minimum (Optional): To motivate how backwards analysis works, let us con-
sider a much simpler example, namely the problem of computing the minimum. Suppose that
we are given a set S of n distinct numbers. We permute the numbers and inspect them one-
by-one. We maintain a variable that holds the smallest value seen so far. If we see a value
that is smaller than the current minimum, then we update the current smallest. Of course,
this takes O(n) time, but the question we will consider is, in expectation how many times
does the current smallest value change?
Below are three sequences that illustrate that the minimum may updated once (if the numbers
are given in increasing order), n times (if given in decreasing order). Observe that in the third
sequence, which is random, the minimum does not change very often at all.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
5 9 4 11 2 6 8 14 0 3 13 12 1 7 10
Let pi denote the probability that the minimum value changes on inspecting the ith number
of the random permutation. Thus, with probability pi the minimum changes (and we add 1
to the counter for the number of changes) and with probability 1 − pi it does not (and we
add 0 to the counter for the number of changes). The total expected number of changes is
n
X n
X
C(n) = (pi · 1 + (1 − pi ) · 0) = pi .
i=1 i=1
Backwards Analysis for Randomized LP: Let us apply this same approach to the analysis of
the running time of the randomized incremental linear programming algorithm. We will do the
analysis in d-dimensional space. Let Td (n) denote the expected running time of the algorithm
on a set of n halfspaces in dimension d. We will prove by induction that Td (n) ≤ γ d! n, where
γ is some constant that does not depend on dimension. It will make the proof simpler if we
start by proving that Td (n) ≤ γd d! n, where γd does depend on dimension, and later we will
eliminate this dependence.
For d + 1 ≤ i ≤ n, let pi denote the probability that the insertion of the ith hyperplane in
the random order results in a change in the optimum vertex.
Combining the two cases, up to constant factors (which don’t depend on dimension), we have
a total expected running time of
n
X n
X
Td (n) ≤ (1 − pi )d + pi di + Td−1 (i) ≤ d + pi di + Td−1 (i) .
i=d+1 i=d+1
It remains is to determine what pi is. To do this, we will apply the same backward-analysis
technique as above. Let Si denote an arbitrary subset consisting of i of the original halfspaces.
Again, it will simplify things to assume that all the i hyperplanes are being permuted (not
just the last i − d). Among all i! permutations of Si , in how many does the optimum vertex
change with the ith step? Let vi denote the optimum vertex for these i halfspaces. It is
important to note that vi depends only on the set Si and not on the order of their insertion.
(You might think about why this is important.)
Assuming general position, there are d halfspaces whose intersection defines vi . (For example,
in Fig. 45(a), we label these halfspaces as h4 and h7 .)
• If none of these d halfspaces were the last to be inserted, then vi = vi−1 , and there is no
change. (As is the case in Fig. 45(b), where h5 is the last to be inserted.)
h5 h3 h3 h5 h3 h3 h5 h3 h3
c vi = vi−1 c c
h2 h2 h2
h4 h4 h4
vi vi vi−1
h1 h1 h1
h7 h7 h7
h6 h6 h6
(a) (b) (c)
Thus, the optimum changes if and only if either one of the d defining halfspaces was the last
halfspace inserted. Since all of the i halfspaces are equally likely to be last, this happens with
probability d/i. Therefore, pi = d/i.
This probabilistic analysis has been conditioned on the assumption that Si was the subset of
halfspace seen so far, but since the final probability does not depend on any properties of Si
(just on d and i), the probabilistic analysis applies unconditionally to all subsets of size i.
Returning to our analysis, since pi = d/i, and applying the induction hypothesis that
Td−1 (i) = γd−1 (d − 1)! i, we have
n n
X X d
Td (n) ≤ d + pi di + Td−1 (i) ≤ d + di + γd−1 (d − 1)! i
i
i=d+1 i=d+1
Xn
≤ (d + d2 + γd−1 d!) ≤ (d + d2 + γd−1 d!)n.
i=d+1
To complete the proof, we just need to select γd so that the right hand side is at most γd d!.
To achieve this, it suffices to set
d + d2
γd =
+ γd−1 .
d!
Plugging this value into the above formula yields
d + d2
2
Td (n) ≤ (d + d + γd−1 d!)n ≤ + γd−1 d! n ≤ γd d! n,
d!
as desired.
Eliminating the Dependence on Dimension: As mentioned above, we don’t like the fact that
the “constant” γd changes with the dimension. To remedy this, note that because d! grows
so rapidly compared to either d or d2 , it is easy to show thatP(d + d2 )/d! ≤ 1/2d for almost
all sufficiently large values of d. Because the geometric series ∞ d
d=1 1/2 , converges, it follows
that there is a constant γ (independent of dimension) such that γd ≤ γ for all d. Thus, we
have that Td (n) ≤ O(d! n), where the constant factor hidden in the big-Oh does not depend
on dimension.
∆
(a) (b)
We begin by showing that the process of converting an arbitrary polygonal subdivision into
a trapezoidal decomposition increases its size by at most a constant factor. We derive the
exact expansion factor in the next claim.
Claim: Given an n-element set S of line segments, the resulting trapezoidal map T (S) has
at most 6n + 4 vertices and 3n + 1 trapezoids.
Proof: To prove the bound on the number of vertices, observe that each vertex shoots two
bullet paths, each of which will result in the creation of a new vertex. Thus each original
vertex gives rise to three vertices in the final map. Since each segment has two vertices,
this implies at most 6n vertices. The remaining four come from the bounding rectangle.
To bound the number of trapezoids, observe that for each trapezoid in the final map,
its left side (and its right as well) is bounded by a vertex of the original polygonal
subdivision. The left endpoint of each line segment can serve as the left bounding vertex
for two trapezoids (one above the line segment and the other below) and the right
endpoint of a line segment can serve as the left bounding vertex for one trapezoid. Thus
each segment of the original subdivision gives rise to at most three trapezoids, for a total
of 3n trapezoids. The last trapezoid is the one bounded by the left side of the bounding
box.
An important fact to observe about each trapezoid is that its existence is determined by
exactly four entities from the original subdivision: a segment on top, a segment on the
bottom, a bounding vertex on the left, and a bounding vertex on the right. The bounding
vertices may be endpoints of the upper or lower segments, or they may below to completely
different segments. This simple observation will play an important role later in the analysis.
• The left and right endpoints of the new segment need to have bullets fired from them.
• One of the earlier created walls might hit the new line segment. When this happens the
wall is trimmed back. (We store which vertex shot the bullet path for this wall, so we
know which side of the wall to trim.)
The process is illustrated in Fig. 47, where we insert a new segment (red) into the trapezoidal
map from Fig. 46.
Fig. 47: Inserting a segment into the trapezoidal map: (a) Locate the left endpoint and trace the
segment through trapezoids, (b) shoot bullet paths from endpoints and trim walls that have been
crossed, (c) four original trapezoids have been replaced by seven new trapezoids (shaded).
Observe that the structure of the trapezoidal decomposition does not depend on the order in
which the segments are added. (This fact will be exploited later in the running time analysis,
and it is one of the reasons that trimming back the walls is so important.) The following is
also important to the analysis.
Claim: Ignoring the time spent to locate the left endpoint of an segment, the time that
it takes to insert the ith segment and update the trapezoidal map is O(ki ), where ki
denotes the number of newly created trapezoids.
Proof: Consider the insertion of the ith segment, and let wi denote the number of existing
walls that this segment intersects. We need to shoot four bullets (two from each end-
point) and then trim each of the wi walls, for a total of wi + 4 operations that need to
be performed. If the new segment did not cross any of the walls, then we would get
exactly four new trapezoids. For each of the wi walls we cross, we add one more to the
number of newly created trapezoids, for a total of wi + 4. Thus, letting ki = wi + 4 be
the number of trapezoids created, the number of update operations is exactly ki . Each
of these operations can be performed in O(1) time given any reasonable representation
of the trapezoidal map as a planar subdivision, for example, a doubly connected edge
list (DCEL).
Lemma: Consider the randomized incremental construction of a trapezoidal map, and let
ki denote the number of new trapezoids created when the ith segment is added. Then
E[ki ] = O(1), where the expectation is taken over all possible permutations of the
segments as the insertion orders.
Proof: The analysis will be based on a backwards analysis. Recall that such an analysis
involves analyzing the expected value assuming that the last insertion was random.
Let Ti denote the trapezoidal map resulting after the insertion of the ith segment. Be-
cause we are averaging over all permutations, among the i segments that are present in
Ti , each one has an equal probability 1/i of being the last one to have been added. For
each of the segments s we want to count the number of trapezoids that would have been
created, had s been the last segment to be added.
We say that a trapezoid ∆ of the existing map depends on an segment s, if s would have
caused ∆ to be created had s been the last segment to be inserted. (For example, in
Fig. 48(a), the shaded trapezoids depend on s, and none of the others do.) We want
to count the number of trapezoids that depend on each segment, and then compute
the average over all segments. If we let δ(∆, s) = 1 if segment ∆ depends on s, and 0
otherwise, then the expected value is
1X 1X X
E[ki ] = (no. of trapezoids that depend on s) = δ(∆, s).
i i
s∈Si s∈Si ∆∈Ti
Some segments might have resulted in the creation of lots of trapezoids and others would
have resulted in very few. How can we analyze such an unruly quantity? The trick is,
rather than counting the number of trapezoids that depend on each segment, we count
the number segments that each trapezoid depends on. In other words we can express
s ∆
(a) (b)
We know that the total number of trapezoids in the end is at most 3n + 4 = O(n). Since the
expected number of new trapezoids created with each insertion is O(1), it follows that the
total number of trapezoids that are created (and perhaps destroyed) throughout the entire
process is O(n). This fact is important in bounding the total time needed for the randomized
incremental algorithm.
The only question that we have not considered in the construction is how to locate the
trapezoid that contains left endpoint of each newly added segment. We will consider this
question, and the more general question of how to do point location in our next lecture.
q
q
si
(a) (b)
Fig. 49: (a) point location and (b) vertical ray-shooting queries.
It will be useful to generalize the above problem. Rather than assuming that the input is
a subdivision of space into cells (what is commonly referred to as a cell complex ), we will
assume that the input is merely a set of n line segments S = {s1 , . . . , sn }. The objective is to
answer vertical ray-shooting queries, which means, given a query point q, what line segment
si (if any) lies immediately below the query point (see Fig. 49(b)). Observe that the ability
to answer vertical ray-shooting queries implies that point-location queries can be answered.
We simply label each segment with the identity of the subdivision cell that lies immediately
above it.
We will make the usual general-position assumption that no two segment endpoints share the
same x-coordinate (and hence there are no vertical lines), and that the query point does not
lie on any segment nor directly above a segment endpoint.
For many years the best methods known for solving planar point location had an extra
log factor, either in the space or in the query time. (That is, the space was O(n log n) or
the query time was O(log2 n). David Kirkpatrick achieved a breakthrough by presenting
a time/space optimal algorithm. Kirkpatrick’s algorithm has fairly high constant factors.
Somewhat simpler and more practical optimal algorithms were discovered since then.
Recap of Trapezoidal Maps: Our point-location data structure will be based on the randomized
trapezoidal map construction from the previous lecture. In that lecture we showed that a
trapezoidal map of O(n) space could be constructed in (randomized) O(n log n) expected
time. In this lecture we show how to modify the construction so that, as a by product, we
obtain a data structure for answering vertical ray-shooting queries. The preprocessing time
for the data structure will also be O(n log n) in the expected case, the space required for the
data structure will be O(n), and the query time will be O(log n). The latter two bounds will
hold unconditionally.
Let us recap some of the concepts from the previous lecture. Recall that the input as a set
of segments in the plane S = {s1 , . . . , sn } in the plane, which are assumed to have been
randomly permuted. Let Si denotes the subset consisting of the first i segments of S. Let
T = T (S) denote the trapezoidal map of S, which is the subdivision generated by shooting
vertical rays both upwards and downwards from each line-segment endpoint until striking
another segment (or hitting the bounding box of the input). Let Ti denote the trapezoidal
map of Si .
p p s s X
X Y Y
X Y X Y
(a) (b)
Our construction of the point location data structure mirrors the incremental construction
of the trapezoidal map, as given in the previous lecture. In particular, if we freeze the
construction just after the insertion of any segment, the current structure will be a point
location structure for the current trapezoidal map.
In Fig. 51 below we show a simple example of what the data structure looks like for two line
segments. For example, if the query point is in trapezoid D, we would first detect that it is
to the right of enpoint p1 (right child), then left of q1 (left child), then below s1 (right child),
then right of p2 (right child), then above s2 (left child).
Incremental Construction: The question is how do we build this data structure incrementally?
First observe that when a new line segment is added, we only need to adjust the portion of
the tree that involves the trapezoids that have been deleted as a result of this new addition.
Each trapezoid that is deleted will be replaced with a search structure that determines the
newly created trapezoid that contains it.
Suppose that we add a line segment s. This results in the replacement of an existing set
of trapezoids with a set of new trapezoids. As a consequence, we will replace the leaves
associated with each such deleted trapezoid with a local search structure, which locates the
new trapezoid that contains the query point. There are three cases that arise, depending on
how many endpoints of the segment lie within the current trapezoid.
Single (left or right) endpoint: A single trapezoid A is replaced by three trapezoids, de-
noted X, Y , and Z. Letting p denote the endpoint, we create an x-node for p, and
one child is a leaf node for the trapezoid X that lies outside vertical projection of the
segment. For the other child, we create a y-node whose children are the trapezoids Y
and Z lying above and below the segment, respectively (see Fig. 52(a)).
Two segment endpoints: This happens when the segment lies entirely inside the trape-
zoid. In this case one trapezoid A is replaced by four trapezoids, U , X, Y , and Z.
Letting p and q denote the left and right endpoints of the segment, we create two x-
nodes, one for p and the other for q. We create a y-node for the line segment, and join
everything together (see Fig. 52(b)).
No segment endpoints: This happens when the segment cuts completely through a trape-
zoid. A single trapezoid is replaced by two trapezoids, one above and one below the
segment, denoted Y and Z. We replace the leaf node for the original trapezoid with a
y-node whose children are leaf nodes associated with Y and Z (see Fig. 52(c)).
A Y s A Y X
s X s q U A s
p p p X Y
Z Z
A p A p A s
X s U q X Y
Y Z s X
Y Z
Fig. 52: Line segment insertion and updates to the point location structure. The single-endpoint
case (left) and the two-endpoint case (right). The no-endpoint case is not shown.
It is important to notice that (through sharing) each trapezoid appears exactly once as a
leaf in the resulting structure. How does this sharing occur? Whenever we add a segment,
the wall trimming that results can result in two distinct trapezoids being merged into one
(see trapezoid Y in Fig. 53(a) and X and Y in Fig. 53(b)). When this happens, the various
p1
B q1 A q1
p1 s1 s1 q2
G
E p2 s2
D B G
A p2
s2 q2 C s2 E
C F
D F
p1
A q1
B q1
s1 K s1 q2
p1 I q3
p3 s3 B p2 s2 q3
M
A L
H p2 s2 q2
N p3 s2 s3 s3 N
J F s3 s3
H F M
I J K L
Fig. 53: Line segment insertion.
Analysis: We claim that the size of the point location data structure is O(n) and the query time
is O(log n), both in the expected case. As usual, the expectation depends only on the order
of insertion, not on the line segments or the location of the query point.
To prove the space bound of O(n), observe that the number of new nodes added to the
structure with each new segment is proportional to the number of newly created trapezoids.
Last time we showed that with each new insertion, the expected number of trapezoids that
were created was O(1). Therefore, we add O(1) new nodes with each insertion in the expected
case, implying that the total size of the data structure is O(n).
Analyzing the query time is a little subtler. In a normal probabilistic analysis of data struc-
tures we think of the data structure as being fixed, and then compute expectations over
random queries. Here the approach will be to imagine that we have exactly one query point
to handle. The query point can be chosen arbitrarily (imagine an adversary that tries to se-
lect the worst-possible query point) but this choice is made without knowledge of the random
choices the algorithm makes. We will show that, given a fixed query point q, the expected
search path length for q is O(log n), where the expectation is over all segment insertion orders.
(Note that this does not imply that the expected maximum depth of the tree is O(log n). We
will discuss this issue later.)
Let q denote the query point. Rather than consider the search path for q in the final search
structure, we will consider how q moves incrementally through the structure with the addition
of each new line segment. Let ∆i denote the trapezoid of the map that q lies in after the
insertion of the first i segments. Observe that if ∆i−1 = ∆i , then insertion of the ith segment
did not affect the trapezoid that q was in, and therefore q will stay where it is relative to the
What saves us is the observation that, as i becomes larger, the more trapezoids we have,
and the smaller the probability that any random segment will affect a given trapezoid. In
particular, we will show that Prob(Xi (q)) ≤ 4/i. We do this through a backwards analysis.
Consider the trapezoid ∆i that contained q after the ith insertion. Recall from the previous
lecture that each trapezoid is dependent on at most four segments, which define the top and
bottom edges, and the left and right sides of the trapezoid. Clearly, ∆i would have changed
as a result of insertion i if any of these four segments had been inserted last. Since, by the
random insertion order, each segment is equally likely to be the last segment to have been
added, the probability that one of ∆i ’s dependent segments was the last to be inserted is at
most 4/i. Therefore, Prob(Xi (q)) ≤ 4/i.
From this, it follows that the expected path length for the query point q is at most
n n
X 4 X 1
D(q) ≤ 3 = 12 .
i i
i=1 i=1
Pn 1
Recall that i=1 i is the Harmonic series, and for large n, its value is very nearly ln n. Thus
we have
D(q) ≤ 12 · ln n = O(log n).
Guarantees on Search Time: (Optional) One shortcoming with this analysis is that even
though the search time is provably small in the expected case for a given query point, it
might still be the case that once the data structure has been constructed there is a single very
long path in the search structure, and the user repeatedly performs queries along this path.
Hence, the analysis provides no guarantees on the running time of all queries.
It is far from trivial, but it can be shown that by repeated application of the randomized
incremental construction, it is possible to achieve worst-case search time of O(log n), worst-
case size of O(n), and expected-case construction time is O(n log n).9 The idea is to engineer
9
M. Hemmer, M. Kleinbort, and D. Halperin. Optimal randomized incremental construction for guaranteed
logarithmic planar point location. Comput. Geom., 58:110–123, 2016.
Line Segment Intersection Revisited: (Optional) Earlier this semester we presented a plane-
sweep algorithm for computing line segment intersection. The algorithm had a running time
of O((n + I) log n), where I is the number of intersection points. It is interesting to note
that the randomized approach we discussed today can be adapted to deal with intersecting
segments as well. In particular, whenever a segment is added, observe that in addition to it
stabbing vertical segments, it may generally cross over one of the existing segments. When
this occurs, the algorithm must determine the trapezoid that is hit on the other side of the
segment, and then continue the process of walking the segment. Note that the total size of
the final decomposition is O(n + I), which would suggest that the running time might be
the same as the plane-sweep algorithm. It is remarkable, therefore, that the running time is
actually better. Intuitively, the reason is that the O(log n) factor in the randomized algorithm
comes from the point location queries, which are applied only to the left endpoint of each of
the n segments. With a bit of additional work, it can be shown that the adaptation of the
randomized algorithm to general (intersecting) segments runs in O(I + n log n) time, thus
removing the log factor from the I term.
face
In this lecture we consider the question of how to represent planar cell complexes, called a
doubly-connected edge list (or DCEL). The DCEL is a common edge-based representation.
Vertex and face information is also included for whatever geometric application is using the
data structure. There are three sets of records one for each element in the cell complex: vertex
records, a edge records, and face records. For the purposes of unambiguously defining left and
right, each undirected edge is represented by two directed half-edges.
We will assume that the faces of complex do not have holes inside of them. (More formally,
we say that the boundary of each face is simply connected.) This assumption can be always
Vertex: Each vertex stores information pertinent to the vertex, such as its coordinates and
identity. Along with this, it stores a pointer to any incident directed edge that has this
vertex as its origin, v.inc edge.
Edge: Each undirected edge is represented as two oppositely-directed half-edges. Each edge
has a pointer to the oppositely directed edge, called its twin. It also has an origin and
destination vertex. Each directed edge is associate with two faces, one to its left and
one to its right (with respect to an observer facing the edge’s direction).
We store a pointer to the origin vertex e.org. (We do not need to define the destination,
e.dest, since it may be defined to be e.twin.org.)
We store a pointer to the face to the left of the edge e.left (we can access the face to
the right from the twin edge). This is called the incident face. We also store the next
and previous directed edges in counterclockwise order about the incident face, e.next
and e.prev, respectively.
Face: Each face f stores a pointer to a single edge for which this face is the incident face,
f.inc edge. (See the text for the more general case of dealing with holes.)
e.twin
e e.org
e.next
e.prev
e.left
The figure shows two ways of visualizing the DCEL. One is in terms of a collection of doubled-
up directed edges. An alternative way of viewing the data structure that gives a better sense
of the connectivity structure is based on covering each edge with a two element block, one
for e and the other for its twin. The next and prev pointers provide links around each face of
the polygon. The next pointers are directed counterclockwise around each face and the prev
pointers are directed clockwise.
Of course, in addition the data structure may be enhanced with whatever application data is
relevant. In some applications, it is not necessary to know either the face or vertex information
(or both) at all, and if so these records may be deleted. See the book for a complete example.
For example, suppose that we wanted to enumerate the vertices that lie on some face f . Here
is the code:
Merging subdivisions: To illustrate the use of the DCEL data structure, consider the following
application. We are given two planar subdivisions, A and B, each represented as a DCEL,
and we want to compute their overlay. We will make the general-position assumption that
no two vertices share the same location, and no two edges are collinear. Thus, the only
interactions between the two subdivisions occur when a pair of edges cross over one another.
In particular, whenever two edges of these subdivision cross, we want to create a new vertex
at the intersection point, split the two edges in two fragment, and connect these fragments
together about this vertex (see Fig. 56).
a1 a1
b1 b1
Our approach will be to modify the plane-sweep algorithm to generate the DCEL of the over-
laid subdivision. The algorithm will destroy the original subdivisions, so it may be desirable
to copy them before beginning this process. The first part of the process is straightforward,
but perhaps a little tedious. This part consists of building the edge and vertex records for the
new subdivision. The second part involves building the face records. It is more complicated
because it is generally not possible to know the face structure at the moment that the sweep is
advancing, without looking “into the future” of the sweep to see whether regions will merge.
(You might try to convince yourself of this.) Our textbook explains how to update the face
information. We will focus on updating just the edge information.
The critical step of the overlaying process occurs with we sweep an intersection event between
two edges, one from each of the subdivisions. Let us denote these edges as a1 ∈ A and b1 ∈ B.
Recall that each edge of the subdivision is represented by two half edges. We will assume
that a1 and b1 are selected so that they are directed from left to right across the sweep-line
(see Fig. 56). The process will make use of two auxiliary procedures:
• split(a1, a2) splits an edge a1 into two consecutive edges a1 followed by a2 , and links
a2 into the structure (see Fig. 57(a)).
• splice(a1, a2, b1, b2) takes two such split edges, which are assumed to meet cycli-
cally in counterclockwise order about a common intersection point in the order ha1 , b1 , a2 , b2 i,
(a) (b)
The splitting procedure creates the new edge and links it into place (see the code block below).
The edge constructor is given the origin and destination of the new edge and creates a new
edge and its twin. The procedure below initializes all the other fields. Also note that the
destination of a1 , that is the origin of a1 ’s twin must be updated, which we have omitted.
Split an edge into two edges
split(edge a1, edge a2) { // a2 is returned
a2 = new edge(v, a1.dest()); // create edge (v,a1.dest)
a2.next = a1.next; a1.next.prev = a2;
a1.next = a2; a2.prev = a1;
a1t = a1.twin; a2t = a2.twin; // the twins
a2t.prev = a1t.prev; a1t.prev.next = a2t;
a1t.prev = a2t; a2t.next = a1t;
}
The splice procedure interlinks four edges around a common vertex in the counterclockwise
order a1 (entering), b1 (entering), a2 (leaving), b2 (leaving). (See the code block below.)
Splice four edges together
splice(edge a1, edge a2, edge b1, edge b2) {
a1t = a1.twin; a2t = a2.twin; // get the twins
b1t = b1.twin; b2t = b2.twin;
a1.next = b2; b2.prev = a1; // link the edges together
b2t.next = a2; a2.prev = b2t;
a2t.next = b1t; b1t.prev = a2t;
b1.next = a1t; a1t.prev = b1;
}
Given these two utilities, the function merge(a1, b1) given in the following code block splits
the edges and links them to a common vertex.
d
!1/2
X
kp − qk = (pi − qi )2
i=1
denote the standard Euclidean distance between two points p, q ∈ Rd . Let P = {p1 , p2 , . . . , pn }
be a set of points in Rd , which we call sites. Define VP (pi ), called the Voronoi cell, for pi , to
be the set of points q in space that are closer to pi than to any other site, that is,
When P is clear from context, we will omit it and refer to this simply as V(pi ). Clearly, the
Voronoi cells of two distinct points of P are disjoint. The union of the closure of the Voronoi
cells defines a cell complex, which is called the Voronoi diagram of P , and is denoted Vor(P )
(see Fig. 58(a)).
VP (pi)
pi
h(pi, pj )
pj
(a) (b)
The cells of the Voronoi diagram are (possibly unbounded) convex polyhedra. To see this,
observe that the set of points that are strictly closer to one site pi than to another site pj is
equal to the open halfspace whose bounding hyperplane is the perpendicular bisector between
pi and pj . Denote this halfspace h(pi , pj ). It is easy to see that a point q lies in V(pi ) if and
only if q lies within the intersection of h(pi , pj ) for all j 6= i. In other words,
\
V(pi ) = h(pi , pj )
j6=i
Nearest neighbor queries: Given a point set P , we wish to preprocess P so that, given a
query point q, it is possible to quickly determine the closest point of P to q. This can be
answered by first computing a Voronoi diagram and then locating the cell of the diagram
that contains q. (In the plane, this can be done by building the trapezoidal map of the
edges of the Voronoi diagram. Each trapezoid lies within a single Voronoi cell, and can
be labeled with the generating point.)
Computational morphology and shape analysis: A useful structure in shape analysis
is called the medial axis. The medial axis of a shape (e.g., a simple polygon) is defined to
be the union of the center points of all locally maximal disks that are contained within
the shape (see Fig. 59). If we generalize the notion of Voronoi diagram to allow sites
that are both points and line segments, then the medial axis of a simple polygon can be
extracted easily from the Voronoi diagram of these generalized sites.
Fig. 59: (a) A simple polygon, (b) its medial axis and a sample maximal disk, and (c) center-based
clustering (with cluster centers shown as black points).
Properties of the Voronoi diagram: Here are some properties of the Voronoi diagrams in the
plane. These all have natural generalizations to higher dimensions.
pk
pi pi
pj pj
Voronoi vertices: It follows that the vertex at which three Voronoi cells V(pi ), V(pj ), and
V(pk ) intersect, called a Voronoi vertex is equidistant from all sites (see Fig. 60(b)).
Thus it is the center of the circle passing through these sites, and this circle contains no
other sites in its interior. (In Rd , the vertex is defined by d+1 points and the hypersphere
centered at the vertex passing through these points is empty.)
Degree: Generally three points in the plane define a unique circle (generally, d + 1 points in
Rd ). If we make the general position assumption that no four sites are cocircular, then
each vertex of the Voronoi diagram is incident to three edges (generally, d + 1 facets).
Convex hull: A cell of the Voronoi diagram is unbounded if and only if the corresponding
site lies on the convex hull. (Observe that a site is on the convex hull if and only if it
is the closest point from some point at infinity, namely the point infinitely far along a
vector orthogonal to the supporting line through this vertex.) Thus, given a Voronoi
diagram, it is easy to extract the vertices of the convex hull in linear time.
Size: Letting n denote the number of sites, the Voronoi diagram with exactly n faces. It
follows from Euler’s formula 10 that the number of Voronoi vertices is roughly 2n and
the number of edges is roughly 3n. (See the text for details. In higher dimensions the
diagram’s combinatorial complexity ranges from O(n) up to O(ndd/2e ).)
Computing Voronoi Diagrams: There are a number of algorithms for computing the Voronoi
diagram of a set of n sites in the plane. Of course, there is a naive O(n2 log n) time algorithm,
which operates by computing V(pi ) by intersecting the n − 1 bisector halfplanes h(pi , pj ), for
j 6= i. However, there are much more efficient ways, which run in O(n log n) time. Since the
convex hull can be extracted from the Voronoi diagram in O(n) time, it follows that this is
asymptotically optimal in the worst-case.
Historically, O(n2 ) algorithms for computing Voronoi diagrams were known for many years
(based on incremental constructions). When computational geometry came along, a more
complex, but asymptotically superior O(n log n) algorithm was discovered. This algorithm
was based on divide-and-conquer. But it was rather complex, and somewhat difficult to
10
Euler’s formula for planar graphs states that a planar graph with v vertices, e edges, and f faces satisfies
v − e + f = 2. There are n faces, and since each vertex is of degree three, we have 3v = 2e, from which we infer that
v − (3/2)v + n = 2, implying that v = 2n − 4. A similar argument can be used to bound the number of edges.
sweep line
unantcipated events
Fig. 61: Plane sweep for Voronoi diagrams. Note that the position of the indicated vertices depends
on sites that have not yet been encountered by the sweep line, and hence are unknown to the
algorithm. (Note that the sweep line moves from top to bottom.)
The Beach Line: The sweeping process will involve sweeping two different object. First, there
will be a horizontal sweep line, moving from top to bottom. We will also maintain an x-
monotonic curve called a beach line. (It is so named because it looks like waves rolling up
on a beach.) The beach line lags behind the sweep line in such a way that it is unaffected
by sites that have yet to be seen. Thus, there are no unanticipated events on the beach line.
The sweep-line status will be based on the manner in which the Voronoi edges intersect the
beach line, not the actual sweep line.
Let’s make these ideas more concrete. We subdivide the halfplane lying above the sweep line
into two regions: those points that are closer to some site p above the sweep line than they
are to the sweep line itself, and those points that are closer to the sweep line than any site
above the sweep line.
What are the geometric properties of the boundary between these two regions? The set of
bisector for
p and `
p p
beach line
`
`
(a) (b) (c)
Fig. 62: The beach line. Notice that only the portion of the Voronoi diagram that lies above the
beach line is computed. The sweep-line status maintains the intersection of the Voronoi diagram
with the beach line.
Thus, the beach line consists of the lower envelope of these parabolas, one for each site (see
Fig. 62(c)). Note that the parabola associated with some sites may be redundant in the sense
that they will not contribute to the beach line. Because the parabolas are x-monotone, so is
the beach line. Also observe that the point where two arcs of the beach line intersect, which
we call a breakpoint, is equidistant from two sites and the sweep line, and hence must lie
on some Voronoi edge. In particular, if the beach line arcs corresponding to sites pi and pj
share a common breakpoint on the beach line, then this breakpoint lies on the Voronoi edge
between pi and pj . From this we have the following important characterization.
Lemma: The beach line is an x-monotone curve made up of parabolic arcs. The breakpoints
(that is, vertices) of the beach line lie on Voronoi edges of the final diagram.
Fortune’s algorithm consists of simulating the growth of the beach line as the sweep line
moves downward, and in particular tracing the paths of the breakpoints as they travel along
the edges of the Voronoi diagram. Of course, as the sweep line moves, the parabolas forming
the beach line change their shapes continuously. As with all plane-sweep algorithms, we will
maintain a sweep-line status and we are interested in simulating the discrete event points
where there is a “significant event”, that is, any event that changes the topological structure
of the Voronoi diagram or the beach line.
Sweep-Line Status: The algorithm maintains the current location (y-coordinate) of the
sweep line. It stores, in left-to-right order the sequence of sites that define the beach
The algorithm consists of processing these two types of events. As the Voronoi vertices are
being discovered by Voronoi vertex events, it will be an easy matter to update the diagram
as we go (assuming any reasonable representation of this planar cell complex), and so to link
the entire diagram together. Let us consider the two types of events that are encountered.
Site events: A site event is generated whenever the horizontal sweep line passes over a site pi .
As we mentioned before, at the instant that the sweep line touches the point, its associated
parabolic arc will degenerate to a vertical ray shooting up from the point to the current beach
line. As the sweep line proceeds downwards, this ray will widen into an arc along the beach
line. To process a site event we determine the arc of the sweep line that lies directly above
the new site. (Let us make the general position assumption that it does not fall immediately
below a vertex of the beach line.) Let pj denote the site generating this arc. We then split
this arc in two by inserting a new entry at this point in the sweep-line status. (Initially this
corresponds to a infinitesimally small arc along the beach line, but as the sweep line sweeps
on, this arc will grow wider. Thus, the entry for h. . . , pj , . . .i on the sweep-line status is
replaced by the triple h. . . , pj , pi , pj , . . .i (see Fig. 63).
It is important to consider whether this is the only way that new arcs can be introduced into
the sweep line. In fact it is. We will not prove it, but a careful proof is given in the text. As
a consequence, it follows that the maximum number of arcs on the beach line can be at most
2n − 1, since each new point can result in creating one new arc, and splitting an existing arc,
for a net increase of two arcs per point (except the first). Note that a point may generally
contribute more than one arc to the beach line. (As an exercise you might consider what is
the maximum number of arcs a single site can contribute.)
The nice thing about site events is that they are all known in advance. Thus, the sites can
be presorted by the y-coordinates and inserted as a batch into the event priority queue.
Voronoi vertex events: In contrast to site events, Voronoi vertex events are generated dynami-
cally as the algorithm runs. As with the line segment intersection algorithm, the important
Sweep-line algorithm: We can now present the algorithm in greater detail. The main structures
that we will maintain are the following:
(Partial) Voronoi diagram: The partial Voronoi diagram that has been constructed so
far will be stored in any reasonable data structure for storing planar subdivisions, for
example, a doubly-connected edge list. There is one technical difficulty caused by the
fact that the diagram contains unbounded edges. This can be handled by enclosing
everything within a sufficiently large bounding box. (It should be large enough to contain
all the Voronoi vertices, but this is not that easy to compute in advance.) An alternative
is to create an imaginary Voronoi vertex “at infinity” and connect all the unbounded
edges to this imaginary vertex.
Beach line: The beach line consists of the sorted sequence of sites whose arcs form the beach
line. It is represented using a dictionary (e.g. a balanced binary tree or skip list). As
mentioned above, we do not explicitly store the parabolic arcs. They are just there for
the purposes of deriving the algorithm. Instead for each parabolic arc on the current
beach line, we store the site that gives rise to this arc.
The key search operation is that of locating the arc of the beach line that lies directly
above a newly discovered site. (As an exercise, before reading the next paragraph you
might think about how you would design a binary search to locate this arc, given that
you only have the sites, not the actual arcs.)
The algorithm proceeds like any plane sweep algorithm. The algorithm starts by inserting
the topmost vertex into the sweep-line status. We extract an event, process it, and go on
to the next event. Each event may result in a modification of the Voronoi diagram and the
beach line, and may result in the creation or deletion of existing events.
Here is how the two types of events are handled in somewhat greater detail.
The analysis follows a typical analysis for plane sweep. Each event involves O(1) processing
time plus a constant number operations to the various data structures (the sweep line status
and the event queue). The size of the data structures is O(n), and each of these operations
takes O(log n) time. Thus the total time is O(n log n), and the total space is O(n).
Convex hull: The boundary of the exterior face of the Delaunay triangulation is the bound-
ary of the convex hull of the point set.
Circumcircle property: The circumcircle of any triangle in the Delaunay triangulation is
“empty,” that is, the interior of the associated circular disk contains no sites of P (see
the blue circle in Fig. 65(b)).
(a) (b)
Fig. 65: (a) The Voronoi diagram of a set of sits (broken lines) and the corresponding Delaunay
triangulation (solid lines) and (b) circle-related properties.
Proof: This is because the center of this circle is the corresponding dual Voronoi vertex,
and by definition of the Voronoi diagram, the three sites defining this vertex are its
nearest neighbors.
Empty circle property: Two sites pi and pj are connected by an edge in the Delaunay
triangulation, if and only if there is an empty circle passing through pi and pj (see the
red circle in Fig. 65(b)).
Proof: If two sites pi and pj are neighbors in the Delaunay triangulation, then their cells
are neighbors in the Voronoi diagram, and so for any point on the Voronoi edge between
these sites, a circle centered at this point passing through pi and pj cannot contain any
other point (since they must be closest). Conversely, if there is an empty circle passing
through pi and pj , then the center c of this circle is a point on the edge of the Voronoi
diagram between pi and pj , because c is equidistant from each of these sites and there
is no closer site (see Fig. 65(b)). Thus the Voronoi cells of two sites are adjacent in the
Voronoi diagram, implying that this edge is in the Delaunay triangulation.
Closest pair property: The closest pair of sites in P are neighbors in the Delaunay trian-
gulation (see the green circle in Fig. 65(b)).
Proof: Suppose that pi and pj are the closest sites. The circle having pi and pj as its
diameter cannot contain any other site, since otherwise such a site would be closer to
one of these two points, violating the hypothesis that these points are the closest pair.
Therefore, the center of this circle is on the Voronoi edge between these points, and so
it is an empty circle.
Given a point set P with n sites where there are h sites on the convex hull, it is not hard
to prove by Euler’s formula that the Delaunay triangulation has 2n − 2 − h triangles, and
3n − 3 − h edges. The ability to determine the number of triangles from n and h only works
in the plane. In Rd , the number of simplices (the d-dimensional generalization of a triangle)
can range from O(n) up to O(ndd/2e ). For example, in R3 the Delaunay triangulation of n
sites may have as many as O(n2 ) tetrahedra. (If you want a challenging exercise, try to create
such a point set.)
Euclidean Minimum Spanning Tree: The Delaunay triangulation possesses a number of in-
teresting properties that are not obviously related to the Voronoi diagram structure. One of
these is its relation to the minimum spanning tree. Given a set of n points in the plane, we
pairs of distinct points, and edge (pi , pj ) has weight equal to the Euclidean distance from pi
to pj . Given a graph, the minimum spanning tree (MST) is a set of n − 1 edges that connect
the points (into a free tree) such that the total weight of edges is minimized. The MST of
the Euclidean graph is called the Euclidean minimum spanning tree (EMST), see Fig. 66(c).
Fig. 66: (a) A point set and its EMST, (b) the Delaunay triangulation, and (c) the overlay of the
two.
We could compute the EMST by brute force by constructing the Euclidean graph and then
invoking Kruskal’s algorithm to compute its MST. This would lead to a total running time of
O(n2 log n). However there is a much faster method based on Delaunay triangulations. First
compute the Delaunay triangulation of the point set. We will see later that it can be done
in O(n log n) time. Then compute the MST of the Delaunay triangulation by, say, Kruskal’s
algorithm and return the result. This leads to a total running time of O(n log n). The reason
that this works is given in the following theorem.
Theorem: The minimum spanning tree of a set P of point sites (in any dimension) is a
subgraph of the Delaunay triangulation (see Fig. 66(c)).
Proof: Let T be the EMST for P , let w(T ) denote the total weight of T . Let a and b be any
two sites such that ab is an edge of T . Suppose to the contrary that ab is not an edge in
the Delaunay triangulation. This implies that there is no empty circle passing through
a and b, and in particular, the circle whose diameter is the segment ab contains another
site, call it c (see Fig. 67.)
T T0
c c
a b a b
(a) (b)
The removal of ab from the EMST splits the tree into two subtrees. Assume without
loss of generality that c lies in the same subtree as a. Now, remove the edge ab from
the EMST and add the edge bc in its place. The result will be a spanning tree T 0 whose
weight is
w(T 0 ) = w(T ) + kbck − kabk.
Since ab is the diameter of the circle, any other segment lying within the circle is shorter.
By the way, this suggests another interesting question. Among all triangulations, we might
ask, does the Delaunay triangulation minimize the total edge length? The answer is no (and
there is a simple four-point counterexample). However, this (erroneous) claim was made in
a famous paper on Delaunay triangulations, and you may still hear it quoted from time to
time.
The triangulation that minimizes total edge weight is called the minimum weight triangulation
(MWT). The computational complexity of computing the MWT was open for many years,
and in 2008 it was proved that this problem is NP-hard. The hardness proof is quite complex,
and computer assistance was needed to verify the correctness of some of the constructions
used in the proof.
Spanner Properties: A natural observation about Delaunay triangulations is that its edges would
seem to form a resonable transporation road network between the points. On inspecting a few
examples, it is natural to conjecture that the length of the shortest path between two points
in a planar Delaunay triangulation is not significantly longer than the straight-line distance
between these points.
This is closely related to the theory of geometric spanners, that is, geometric graphs whose
shortest paths are not significantly longer than the straight-line distance. Consider any point
set P and a straight-line graph G whose vertices are the points of P . For any two points
p, q ∈ P , let δG (p, q) denote the length of the shortest path from p to q in G, where the weight
of each edge is its Euclidean length. Given any parameter t ≥ 1, we say that G is a t-spanner
if for any two points p, q ∈ P , the shortest path length between p and q in G is at most a
factor t longer than the Euclidean distance between these points, that is
δG (p, q) ≤ tkpqk
n
= O(n2 )
Observe that when t = 1, the graph G must be the complete graph, consisting of 2
edges. Of interest is whether there exist O(1)-spanners having O(n) edges.
It can be proved that the edges of the Delaunay triangulation form a spanner (see Fig. 68).
We will not prove the following result, which is due to Keil and Gutwin.
Theorem: Given
√ a set of points P in the plane, the Delaunay triangulation of P is a t-spanner
for t = 4π 3/9 ≈ 2.418.
q
Fig. 68: Spanner property of the Delaunay Triangulation.
It had been conjectured for many years that the Delaunay triangulation is a (π/2)-spanner
(π/2 ≈ 1.5708). This was disproved in 2009, and the lower bound now stands at roughly
1.5846. Closing the gap between the upper and lower bound is an important open problem.
Theorem: Among all triangulations of a given planar point set, the Delaunay triangulation
has the lexicographically largest angle sequence.
Before getting into the proof, we should recall a few basic facts about angles from basic
geometry. First, recall that if we consider the circumcircle of three points, then each angle
of the resulting triangle is exactly half the angle of the minor arc subtended by the opposite
two points along the circumcircle. It follows as well that if a point is inside this circle then it
will subtend a larger angle and a point that is outside will subtend a smaller angle. Thus, in
Fig. 69(a) below, we have θ1 > θ2 > θ3 .
θ1 > θ2 > θ3
θ2 d d d d
θ1
θ3
a a a θcd a φab
θbc θad φad φbc
θab φcd
c c c c
b b b b
(a) (b) (c) (d)
We will not give a formal proof of the theorem. (One appears in the text.) The main idea
is to show that for any triangulation that fails to satisfy the empty circle property, it is
possible to perform a local operation, called an edge flip, which increases the lexicographical
sequence of angles. An edge flip is an important fundamental operation on triangulations in
the plane. Given two adjacent triangles 4abc and 4cda, such that their union forms a convex
quadrilateral abcd, the edge flip operation replaces the diagonal ac with bd (see Fig. 69(b)).
Note that it is only possible when the quadrilateral is convex.
Suppose that the initial triangle pair violates the empty circle condition, in that point d lies
inside the circumcircle of 4abc. (Note that this implies that b lies inside the circumcircle
of 4cda.) If we flip the edge it will follow that the two circumcircles of the two resulting
triangles, 4abd and 4bcd are now empty (relative to these four points), and the observation
above about circles and angles proves that the minimum angle increases at the same time. In
particular, in Fig. 69(c) and (d), we have
φab > θab φbc > θbc φcd > θcd φda > θda .
a2x + a2y
ax ay 1
bx by b2x + b2y 1
inCircle(a, b, c, d) ≡ det > 0.
cx cy c2x + c2y 1
dx dy d2x + d2y 1
This is called the incircle test. It is notable that the incircle test in 2-D can be reduced to an
orientation test in 3-D, where we have effectively lifted the point onto a paraboloid in 3-space
by creating an addition z-coordinate whose value is x2 + y 2 .
b b b
d
d d
a a a
Deriving the Incircle Test (Optional): We will not prove the correctness of this test, but we
will show a somewhat simpler assertion, namely that if the four points are cocircular then the
above determinant is equal to zero. (It follows from continuity that as d moves from inside
the circle to the outside, the sign of the determinant changes as well.)
Suppose that a, b, c, and d are all cocircular then there exists a center point q = (qx , qy ) and
a radius r such that
(ax − qx )2 + (ay − qy )2 = r2 ,
and similarly for the other three points. (We won’t compute q and r, but merely assume their
existence for now.) Expanding this and collecting common terms we have
If we do the same for the other three points, b, c, and d, and express this in the form of a
matrix, we have
a2x + a2y
ax ay 1 −2qx
bx by
b2x + b2y 1
−2qy
= 0.
cx cy c2x + c2y 1 1
dx dy d2x + d2y 1 qx2 + qy2 − r2
In other words, there exists a linear combination of the columns of the 4 × 4 matrix that is
equal to the zero vector. We know from linear algebra that this is true if and only if the
determinant of the matrix is zero.
b b b b
c p c p c p c p
a a a a
(a) (b)
The algorithm for the incremental algorithm is shown in the code block below, and an example
is presented in Fig. 72. The current triangulation is kept in a global data structure. The edges
should be thought of as pointers to entries in the DCEL representation.
As you can see, the algorithm is very simple. There are only two elements that have not been
shown are the implementation. The first is the update operations on the data structure for the
simplicial complex. These can be done in O(1) time each on any reasonable representation (a
DCEL, for example). The other issue is locating the triangle that contains p. We will discuss
this below.
Local vs. Global Delaunay: There is one major issue in establishing the correctness of the
algorithm. When we performed empty-circle tests, we applied the empty circle tests only
for the newly created triangles containing the site p, and then only for sites that lay on the
opposite side of an edge of each such triangle.
Why this works is related to an important issue in Delaunay triangulations. We know from
the empty circumcircle condition that in a Delaunay triangulation, the circumcircle of every
triangle is empty of other sites. This suggests two different criteria for testing whether a
triangulation is Delaunay:
Global Delaunay: The circumcircle of each triangle 4abc contains no other site d. (Fig. 73(a)
shows a violation.)
11
Some care must be taken in the construction of this enclosing triangle. It is not sufficient that it simply contains
all the points. It should be so large that the vertices of the triangle do not lie in the circumcircles of any of the
triangles of the final triangulation. Our book suggests a symbolic alternative, which is more reliable.
SwapTest(ab) {
if (ab is an edge on the exterior face) return
Let d be the vertex to the right of edge ab
if (inCircle(b, p, a, d)) { // d violates the incircle test
Flip edge ab // replace ab with pd
SwaptTest(ad) // check/fix the new suspect edges
SwaptTest(db)
}
}
flip db
4pde: OK
4peb: OK
4pcf : OK
4pbc: OK
4pfa: OK e e e
4pca: fails!
Done! d flip ca d d
b b b
p a p a p a
c c c
f f
Fig. 72: Delaunay point insertion.
! ! !
d d d
d e e
c b c b c b c b
a a a a
(a) (b) (c) (d)
insert p
p
Fig. 74: Number of structural changes is equal to p’s degree after insertion (three initial edges and
three edge flips).
To perform the backwards analysis, we consider the situation after the insertion of the ith
site. Let di be a random variable that indicates the degree of the newly inserted site in our
randomized algorithm. Let Pi = {p1 , . . . , pi } denote the first i sites to be inserted. Although
the diagram depends on which particular i sites are in this subset, our analysis will not. For
1 ≤ j ≤ i, let deg(pj ) denote the degree of site pj in triangulation DT (Pi ) just after the ith
insertion.
Because the diagram does not depend on the insertion order, each of the sites of Pi has an
equal probability of 1i of being the last site to be inserted. Recall that (by Euler’s formula),
the triangulation has at most 3i edges. It is easy to see that the sum of vertex degrees is
equal to twice the total number of edges (since each edge is counted twice), that is, 6i. We
conclude that expected value of di , denoted E[di ], satisfies:
i
1X 6i
E[di ] = deg(pi ) ≤ = 6.
i i
j=1
Therefore, by the magic of backwards analysis, the expected number of structural changes
following the insertion of the ith site is, in expectation, just 6.
Bounding the Location Cost: The second aspect of the expected-case running time is the cost
of determining which triangle contains each newly created site. As mentioned earlier, we
will employ a bucketing approach, as we did with the trapezoidal-map algorithm. Think of
each triangle of the current triangulation as a bucket that holds the sites that lie within this
triangle and have yet to be inserted (see Fig. 75(a)). When a new site p is inserted, a number
of old triangles are deleted (shaded red in Fig. 75(a)) and a number of new triangles are
created (shaded blue in Fig. 75(b)). All the points in the buckets of the old triangles need to
be moved into the associated new triangle. This process is called rebucketing.
For the sake of simplifying the analysis, let us assume that the cost of rebucketing a single
point during a single insertion is O(1). (The issue is that the cost of rebucketing depends on
the degree of the newly inserted site. In the previous section we showed that the average degree
is a constant, so this assumption is not unreasonable.) We will show through a backwards
analysis that, in expectation, any fixed site is rebucketed O(log n) times.
p p c q b
Let us fix a site q ∈ P . Consider the situation just after the insertion of the ith site. We
may assume that q has not yet been inserted, since otherwise its rebucketing cost is zero
after the ith insertion. For 1 ≤ i ≤ n, let Xi (q) denote the random event that q is moved
to a new triangle after the ith insertion, and let Prob(Xi (q)) denote the probability of this
event. Letting B(q) denote the average number of times that q is rebucketed throughout the
algorithm, we have
Xn
B(q) ≤ Prob(Xi (q)).
i=1
To bound Prob(Xi (q)), let ∆ be the triangle containing q after the ith insertion. As observed
above, after we insert the ith site, all the newly created triangles are incident to this new
site. Thus, ∆ would have come into existence as a result of the last insertion if and only if
one of its three incident vertices happened to be the last to be inserted (see Fig. 75(c)). Since
∆ is incident to exactly three sites, and every site is equally likely to be the last inserted, it
follows that the probability that ∆ came into existence is 3i . (We are cheating a bit here by
ignoring the three initial sites at infinity.) Therefore, Prob(Xi (q)) ≤ 3i .
From this, it follows that the expected number of times that the point q is rebucketed is
n n
X 3 X 1
B(q) ≤ = 3 .
i i
i=1 i=1
Pn 1
Recall that i=1 i is the Harmonic series, and for large n, its value is very nearly ln n. Thus
we have
B(q) ≤ 3 · ln n = O(log n).
Although the diagram depends on the order in which the sites have been added, this bound
does not. Summing over all the n sites, it follows that the total time spent rebucketing all
the points is ni=1 B(pi ) = O(n log n).
P
edge
face
vertex
(a) (b)
Fig. 76: Arrangement of lines; (a) the basic elements of an arrangement and (b) adding a vertex
at infinity to form a proper planar graph.
Proof: The fact that the number of vertices is n2 is clear from the fact that (since no two
as desired.
By the way, this generalizes to higher dimensions as well. The combinatorial complexity of
an arrangement of n hyperplanes in Rd is Θ(nd ). Thus, these structures are only practical in
spaces of relatively low dimension when n is not too large.
Incremental Construction: Arrangements are used for solving many problems in computational
geometry. But in order to use an arrangement, we first must be able to construct it.12 We
will present a simple incremental algorithm, which builds an arrangement by adding lines
one at a time. Unlike the other incremental algorithms we have seen so far, this one is not
randomized. Its worst-case asymptotic running time, which is O(n2 ), holds irrespective of the
insertion order. This is asymptotically optimal, since this is the size of the arrangement. The
algorithm will also require O(n2 ) space, since this is the amount of storage needed to store
the final result.
Let L = {`1 , . . . , `n } denote the set of lines. We will add lines one by one and update the
arrangement after each insertion. We will show that the ith line can be inserted in O(i)
time (irrespective Pnof the insertion order). Summing over i, this yields a total running time
proportional to i=1 i = O(n ). 2
Suppose that the first i − 1 lines have already been inserted. Consider the insertion of `i . We
start by determining the leftmost (unbounded) face of the arrangement that contains this line.
Observe that at x = ∞, the lines are sorted from top to bottom in increasing order of their
slopes. In time O(i) we can determine where the slope of `i falls relative to the slopes of the
prior i − 1 lines, and this determines the leftmost face of the arrangement that contains this
line. (In fact, we could do this in O(log i) time by storing the slopes in an ordered dictionary,
but this would not improve our overall running time. By our assumption that no two lines
are parallel, there are no duplicate slopes.)
The newly inserted line cuts through a sequence of i − 1 edges and i faces of the existing
arrangement. In order to process the insertion, we need to determine which edges are cut by
`i , and then we split each such edge and update the DCEL for the arrangement accordingly.
In order to determine which edges are cut by `i , we “walk” this line through the current
arrangement, from one face to the next. Whenever we enter a face, we need to determine
through which edge `i exits this face. We answer the question by a very simple strategy. We
walk along the edges of the face, say in a counterclockwise direction until we find the exit
edge, that is, the other edge that `i intersects. We then jump to the face on the other side of
this edge and continue the trace with the neighboring face. This is illustrated in Fig. 77(a).
The DCEL data structure supports such local traversals in time linear in the number of
edges traversed. (You might wonder why we don’t generalize the trapezoidal map algorithm.
12
This is not quite accurate. For some applications, it suffices to perform a plane-sweep of the arrangement. If we
think of each line as an infinitely long line segment, the line segment intersection algorithm that was presented in
class leads to an O(n2 log n) time and O(n) space solution. There exists a special version of plane sweep for planar
line arrangements, called topological plane sweep, which runs in O(n2 ) time and O(n) space. In spite of its fancy
name, topological plane sweep is quite easy to implement.
ZA(`i) left-bounding
`i `i `i
right-bounding
(a) (b) (c)
Fig. 77: Adding the line `i to the arrangement; (a) traversing the arrangement and (b) the zone of
a line `i . (Note that only a portion of the zone is shown in the figure.)
Clearly, the time that it takes to perform the insertion is proportional to the total number
of edges that have been traversed in this tracing process. A naive argument says that we
encounter i − 1 lines, and hence pass through i faces (assuming general position). Since each
face is bounded by at most i lines, each facial traversal will take O(i) time, and this gives a
total O(i2 ), which is much higher than the O(i) time that we promised earlier. Why is this
wrong? It is based on bound of the total complexity of the faces traversed. To improve this,
we need to delve more deeply into a concept of a zone of an arrangement.
Zone Theorem: The most important combinatorial property of arrangements (which is critical
to their efficient construction) is a rather surprising result called the zone theorem. Given an
arrangement A of a set L of n lines, and given a line ` that is not in L, the zone of ` in A(L),
denoted ZA (`), is the set of faces of the arrangement that are intersected by ` (shaded in
Fig. 77(b)). For the purposes of the above construction, we are only interested in the edges of
the zone that lie below `i , but if we bound the total complexity of the zone, then this will be
an upper bound on the number of edges traversed in the above algorithm. The combinatorial
complexity of a zone (as argued above) is at most O(n2 ). The Zone theorem states that the
complexity is actually much smaller, only O(n).
Theorem: (Zone Theorem) Given an arrangement A(L) of n lines in the plane, and given
any line ` in the plane, the total number of edges in all the cells of the zone ZA (`) is at
most 6n.
As with many combinatorial proofs, the key is to organize matter so that the counting can
be done in an easy way. This is not trivial. We cannot count cell-by-cell, since some cells
have high complexity and some low. We also cannot count line-by-line, because some lines
contribute many edges to the zone and others just a few. The key in the proof is finding a
(clever!) way to add up the edges so that each line appears to induce only a constant number
of edges into the zone. (Note that our text counts zone edges a bit differently.)
Proof: The proof is based on a simple inductive argument. For the sake of illustration, let
us rotate the plane so that ` is horizontal. By general position, we may assume that
none of the lines of L are parallel to `. We split the edges of the zone into two groups,
those that bound some face from the left side and those that bound some face from
the right side. An edge of a face is said to be left bounding if the face lies in the right
halfplane of the line defining this edge, and a face is right bounding if the face lies in the
ea
` ` `
`1 `1
eb
Now, let us add `1 and see how many more left-bounding edges are generated. Because
`1 is leftmost, it intersects the rightmost face of the zone. Observe that all of the edges
of this face are left-bounding edges. By convexity, `1 intersects the boundary of this
face in two edges, denoted ea and eb , where ea is above `, and eb is below. Its insertion
creates a new left-bounding edge running along `1 between ea and eb , and it splits each
of the edges ea and eb into two new left-bounding edges. Thus, there is a net increase
by three edges, for a total of 3(n − 1) + 3 = 3n edges.
We assert that `1 cannot contribute any other left-bounding edges to the zone. This is
because the lines containing ea and eb block any possibility of this. Therefore, there are
at most 3n left bounding edges, as desired.
General position test: Given a set of n points in the plane, determine whether any three
are collinear.
` `
Maximum stabbing line: Given a set of n line segments in the plane, compute the line `
that stabs (intersects) the maximum number of these line segments (see Fig. 79(c)).
Ham Sandwich Cut: Given n red points and m blue points, find a single line ` that si-
multaneously bisects these point sets. It is a famous fact from mathematics, called the
Ham-Sandwich Theorem, that such a line always exists. If the two point sets are sepa-
rable by a line (that is, the red convex hull and the blue convex hull do not intersect),
then this can be solved in time O(n + m) (see Fig. 79(d)).
In the remainder of the lecture, we’ll see how problems like these can be solved through the
use of arrangements.
1
2 2
2 5
3 5
1 4
4 1
3
4 3
5
(a) (b)
Sweeping an arrangement in this manner takes O(n2 log n) time, and O(n) space. Because
it is more space-efficient, this is often an attractive alternative to constructing the entire
subdivision.
Topological Plane Sweep: (Optional) As mentioned above, the priority queue is the slowest
part of plane sweeping an arrangement. Remarkably, there is a way to save this O(log n)
factor, but we must abandon hope of sweeping events in purely left-to-right order. There is
a somewhat more “relaxed” version of plane sweep, which works for line arrangements in the
plane. The method is called topological plane sweep. It runs in O(n2 ) time (thus, eliminating
an O(log n) factor from the running time) and uses O(n) space.
It achieves efficiency relaxing the requirement that vertices be swept in strict left-to-right
order. Rather, it uses a more “local” approach for deciding which vertex of the arrangement
to sweep next.13 This local approach guarantees that the vertices along each line are swept
in their proper order, even though vertices lying on different lines are not necessarily swept in
their proper left-to-right order. Intuitively, we can think of the sweep line as a sort of pseu-
doline, that intersects each line of the arrangement exactly once (see Fig. 80(b)). Although
we will not present any justification, it method applicable to all the problems we will discuss
in today’s lecture.
Duality: Many of our applications will involve the dual transformation, which we introduced
earlier in the semester. Recall that the dual of a point p = (a, b) is the line p∗ : y = ax − b,
and the dual of a line ` : y = ax − b is the point `∗ = (a, b). Also recall the order-reversing
property that the point p lies above line ` (at vertical distance h) if and only if the dual line
p∗ lies below dual point `∗ (also at vertical distance h).
Narrowest k-corridor: We are given a set P of n points in the plane and an integer k, 1 ≤ k ≤ n,
and we wish to determine the narrowest pair of parallel lines that enclose at least k points
13
For details, see “Topologically sweeping an arrangement” by H. Edelsbrunner and L. J. Guibas, J. Comput. Syst.
Sci., 38 (1989), 165–194.
Fig. 81: A 3-corridor in primal and dual forms. (Note that the corridor is not as narrow as possible.)
By the order-reversing property, points that lie above/below/within the corridor (shown in
blue, red, and black in Fig. 81(a), respectively) are mapped to dual lines that pass be-
low/above/through this segment (see Fig. 81(b)). Thus, we have the following equivalent
dual formulation of this problem:
Shortest vertical k-stabber: Given an arrangement of n lines, determine the shortest ver-
tical segment that stabs (intersects) k lines of the arrangement.
It is easy to show that the shortest vertical k-stabber may be assumed to have one of its
endpoints on a vertex of the arrangement. (If the vertical line has endpoints in the interior
of two edges, we can slide it left or right and decrease its length.)
3-stabber: The 3-stabber is the simplest to describe. A perform a simple plane sweep of
the arrangement (using a vertical sweep line). Whenever we encounter a vertex of the
arrangement, we consider the distance from this vertex to the edge of the arrangement
lying immediately above this vertex and the edge lying immediately below. (These are
illustrated by the blue broken lines in Fig. 82(a).) We can solve this problem by plane
sweep in O(n2 log n) time and O(n) space. (By using topological plane sweep, the extra
log n factor in the running time can be removed.)
Note that we can use this to test whether points are in general position. It is easy to
prove that a set of n points has three or more collinear points if and only if the dual
arrangement’s minimum 3-stabber is of length zero.
k-stabber: Whenever we encounter a vertex in the plane sweep, we determine the distance
to the lines of the arrangement that lie k − 2 above and k − 2 below (see the blue broken
(a) (b)
Fig. 82: The critical events in computing the shortest vertical 3-stabber (a) and 5-stabber (b).
lines of Fig.82(b)). The reason for the “−2” is to account for two lines that pass through
the vertex itself. Recalling that the sweep-line status can be stored in a simple n-element
array, it is possible to access these entries in O(1) time for any value of k.
Halfplane Discrepancy: Next we consider a problem derived geometric sampling. Suppose that
we are given a collection of n points P lying in a unit square U = [0, 1]2 . We want to use these
points for random sampling purposes. In particular, the property that we would like these
points to possess is that for any halfplane h, we the fraction of points of P that lie within h
should be roughly equal to the area of intersection of h with U . More precisely, define µ(h)
to be the area of h ∩ U , and µP (h) = |P ∩ h|/|P |. A sample is good if µ(h) ≈ µP (h), for any
choice of h.
To make this more formal, we define the discrepancy (or more accurately, the halfplane
discrepancy) of a finite point set P with respect to a halfplane h to be
For example, in Fig. 83(a), the area of h ∩ U is µ(h) = 0.625, and there are 7 out of 13 points
in h, thus µP (h) = 7/13 = 0.538. Thus, the discrepancy of h is |0.625 − 0.538| = 0.087.
Define the halfplane discrepancy of P to be the maximum (or more properly the supremum,
or least upper bound) of this quantity over all halfplanes:
Let’s consider the problem of computing the discrepancy of a given point set P .
Since there are an uncountably infinite number of halfplanes that intersect the unit square,
we should first derive some sort of finiteness criterion on the set of halfplanes that might
produce the greatest discrepancy.
Lemma: Let h denote the halfplane that generates the maximum discrepancy with respect
to P , and let ` denote the line that bounds h. Then either:
(i) ` passes through one point of P , and this point is the midpoint of the line segment
` ∩ U , or
(ii) ` passes through two points of P .
Remark: If a line passes through one or more points of P , then should this point be included
in µP (h)? For the purposes of computing the maximum discrepancy, the answer is
to either include or omit the point, whichever produces the larger discrepancy. The
justification is that it is possible to perturb h infinitesimally so that it includes none or
all of these points without altering µ(h).
Proof: We will show that any line can be moved until it satisfies either (i) or (ii) in such
a manner that the discrepancy never decreases. First, if ` does not pass through any
point of P , then (depending on which is larger µ(h) or µP (h)) we can move the line
up or down without changing µP (h) and increasing or decreasing µ(h) to increase their
difference, until it does pass through a point of P . Next, if ` passes through a point
p ∈ P , but is not the midpoint of the line segment ` ∩ U , then we claim that we can
rotate this line about p and hence increase or decrease µ(h) without altering µP (h), to
increase their difference.
To establish the claim, consider Fig. 83(b). Suppose that the line ` passes through point
p and let r1 < r2 denote the two lengths along ` from p to the sides of the square. Observe
that if we rotate ` through a small angle θ, then to a first order approximation, the gain
due to area of the triangle on the right is r12 θ/2, since this triangle can be approximated
by an angular sector of a circle of radius r1 and angle θ. The loss due to the area of
the triangle on the left is r22 θ/2. Thus, since r1 < r2 this rotation will decrease the area
of region lying below h infinitesimally. A rotation in the opposite increases the area
infinitesimally. Since the number of points bounded by h does not change as a function
of θ, the discrepancy cannot be achieved as long as such a rotation is possible.
We say that a line is type-1 if it satisfies condition (i) and it is type-2 if it satisfies condition
(2) (see Fig. 83(c)). We will show that the discrepancy for each types of lines can be computed
in O(n2 ) time.
Type-1: For each point p ∈ P , there are only a constant number of lines ` (at most two, I
believe) through this point such that p is the midpoint of ` ∩ U . It follows that there are
at most O(n) type-1 lines. We can compute the discrepancy of each such line in O(n)
time, which leads to a total running time of O(n2 ).
Type-2: Consider a type-2 line ` that passes through two points pi , pj ∈ P . This line defines
two halfplanes, one above and one below. We’ll explain how to compute the discrepancy
of the lower halfplane, h− , and the upper halfplane, h+ , is symmetrical. First, observe
that we can compute µ(h− ) in constant time, so all that remains is computing µP (h− ),
that is, the number of points lying on or below `.
Levels: The analysis that was done above for type-2 lines suggests another useful structure within a
line arrangement. We can classify each element of the arrangement according to the number
of lines lying above and below it. We say that a point is at level k, denoted Lk , in an
arrangement if there are at most k − 1 lines (strictly) above this point and at most n − k lines
(strictly) below it. It is easy to see that Lk is an x-monotone polygonal curve (see Fig. 84(a)).
For example, L1 is the upper envelope of the lines, and Ln is the lower envelope. Assuming
general position, each vertex of the arrangement is on two levels, which meet at this vertex
in a “knocked-knee” manner. Given the arrangement A(L) of a set of n lines, it is an easy
matter to label every edge of the arrangement with its level number, by tracking its index in
the sweep-line status.
L2 L1
L3
d
c a∗ e∗
f b∗
a `∗ L3
L4 b f∗
` e
c∗ d∗
L5 L6
(a) (b)
There is a dual equivalence between a level in an arrangement and a concept called k-sets.
Given an n-element point set P and integer 1 ≤ k ≤ n, a k-element subset of P 0 ⊆ P is called
a k-set of P if there exists a halfplane h such that P 0 = P ∩ h. For example, if (pi , pj ) is
an edge of the convex hull of P , then P 0 = {pi , pj } is a 2-set of P . A classical question in
combinatorial geometry is, as a function of n and k, what is the maximum number of possible
k-sets that any n-element set can have. (The current best bounds range between O(n log k)
and O(nk 1/3 ).)
(a) (b)
Consider the dual line p∗ , and its intersection points with each of the dual lines p∗i . These
form a sequence of vertices in the arrangement along p∗ . Consider this sequence ordered from
left to right. It would be nice if this order were the desired circular order, but this is not
quite correct. It follows from the definition of our dual transformation that the a-coordinate
of each of these vertices in the dual arrangement is the slope of some line of the form ppi
in the primal plane. Thus, the sequence in which the vertices appear on the line is a slope
ordering of the points about pi , which is not quite the same as the angular ordering.
However, given this slope ordering, we can simply test which primal points lie to the left of
p (shown in blue in Fig. 85(a)), and separate them from the points that lie to the right of p
(a) (b)
Fig. 86: Geometric approximations: (a) Euclidean traveling salesman, (b) approximate convex hull.
Another important motivations for geometric approximations is that geometric inputs are
typically the results of sensed measurements, which are subject to limited precision. There is
no good reason to solve a problem to a degree of accuracy that exceeds the precision of the
inputs themselves.
Well Separated Pairs: A set of n points in space defines a set of n2 = Θ(n2 ) distinct pairs.
To see how to encode this set approximately, let us return briefly to the n-body problem.
Suppose that we wish to determine the gravitational effect of a large number of stars in a one
galaxy on the stars of distant galaxy. Assuming that the two galaxies are far enough away
from each other relative to their respective sizes, the individual influences of the bodies in
each galaxy can be aggregated into a single physical force. If there are n1 and n2 points in
the respective galaxies, the interactions due to all n1 · n2 pairs can be well approximated by
a single interaction pair involving the centers of the two galaxies.
To make this more precise, assume that we are given an n-element point set P in Rd , and
a separation factor s > 0. We say that two disjoint sets of A and B are s-well separated if
the sets A and B can be enclosed within two Euclidean balls of radius r such that the closest
distance between these balls is at least sr (see Fig. 87).
B
r
≥ sr
r
A
Observe that if a pair of points is s-well separated, it is also s0 -well separated for all s0 < s.
Of course, since any point lies within a (degenerate) ball of radius 0, it follows that a pair of
singleton sets, {{a}, {b}}, for a 6= b, is well-separated for any s > 0.
Well Separated Pair Decomposition: Okay, distant galaxies are well separated, but if you were
given an arbitrary set of n points in Rd (which may not be as nicely clustered as the stars in
galaxies) and a fixed separation factor s > 0, can you concisely approximate all n2 pairs? We
will show that such a decomposition exists, and its size is O(n). The decomposition is called
a well separated pair decomposition. Of course, we would expect the complexity to depend
on s and d as well. The constant factor hidden by the asymptotic notion grows as O(sd ).
14
As an indication of how important this algorithm is, it was listed among the top-10 algorithms of the 20th century,
along with quicksort, the fast Fourier transform, and the simplex algorithm for linear programming.
A ⊗ B = {{a, b} | a ∈ A, b ∈ B, a 6= b} .
Observe that A ⊗ A consists of all the n2 distinct pairs of A. Given a point set P and
(1) Ai , Bi ⊆ P , for 1 ≤ i ≤ m
(2) Ai ∩ Bi = ∅, for 1 ≤ i ≤ m
(3) m
S
i=1 Ai ⊗ Bi = P ⊗ P
(4) Ai and Bi are s-well separated, for 1 ≤ i ≤ m
Conditions (1)–(3) assert we have a cover of all the unordered pairs of P , and (4) asserts
that the pairs are well separated. Although these conditions alone do not imply that every
unordered pair from P occurs in a unique pair Ai ⊗ Bi (that is, the cover of P ⊗ P is actually
a partition), our construction will have this further property. An example is shown in Fig. 88.
(Although there appears to be some sort of hierarchical structure here, note that the pairs
are not properly nested within one another.)
Trivially, there exists a WSPD of size O(n2 ) by setting the {Ai , Bi } pairs to each of the
distinct pair singletons of P . Our goal is to show that, given an n-element point set P in Rd
and any s > 0, there exists a s-WSPD of size O(n) (where the constant depends on s and d).
Before doing this, we must make a brief digression to discuss the quadtree data structure, on
which our construction is based.
Quadtrees: A quadtree is a hierarchical subdivision of space into regions, called cells, that are
hypercubes. The decomposition begins by assuming that the points of P lie within a bounding
hypercube. For simplicity we may assume that P has been scaled and translated so it lies
within the unit hypercube [0, 1]d .
The initial cell, associated with the root of the tree, is the unit hypercube. The following
process is then repeated recursively. Consider any unprocessed cell and its associated node u
in the current tree. If this cell contains either zero or one point of P , then this is declared a
leaf node of the quadtree, and the subdivision process terminates for this cell. Otherwise, the
cell is subdivided into 2d hypercubes whose side lengths are exactly half that of the original
hypercube. For each of these 2d cells we create a node of the tree, which is then made a
g
SW NW SE NE
h
b c NW NE c d g h
a f
d e SW SE a b e f
(a) (b)
Fig. 90: Compressed quadtree: (a) The original quadtree, (b) after path compression.
This issue is easily remedied by a process called path compression. Every such trivial path
is compressed into a single link. This link is labeled with the coordinates of the smallest
quadtree box that contains the cluster (see Fig. 90(b)). The resulting data structure is called
a compressed quadtree. Observe that each internal node of the resulting tree separates at least
two points into separate subtrees. Thus, there can be no more than n − 1 internal nodes, and
hence the total number of nodes is O(n).
A second issue involves the efficient computation of the quadtree. It is well known that
the tree can be computed in time O(hn), where h is the height of the tree. However, even
for a compressed quadtree the tree height can be as high as n, which would imply an O(n2 )
construction time. We will not discuss it here, but it can be shown that in any fixed dimension
it is possible to construct the quadtree of an n-element point set in O(n log n) time. (The
key is handling uneven splits efficiently. Such splits arise when one child contains almost all
of the points, and all the others contain only a small constant number.)
The key facts that we will use about quadtrees below are:
(a) Given an n-element point set P in a space of fixed dimension d, a compressed quadtree
for P of size O(n) can be constructed in O(n log n) time.
(b) Each internal node has a constant number (2d ) children.
An important consequence stemming from (c) and (d) is the following lemma, which provides
an upper bound on the number of quadtree disjoint quadtree cells of size at least x that can
overlap a ball of radius r.
Packing Lemma: Consider a ball b of radius r in any fixed dimension d, and consider any
collection X of pairwise disjoint quadtree cells of side lengths at least x that overlap b.
Then d
2r r d
|X| ≤ 1+ ≤ O max 2,
x x
Proof: We may assume that all the cells of X are of side length exactly equal to x, since
making cells larger only reduces the number of overlapping cells (see Fig. 91(b)).
2r
x x G
H
b b
r
(a) (b)
By the nature of a quadtree decomposition, the cells of side length x form a hypercube
grid G of side length x. Consider a hypercube H of side length 2r that encloses b (see
Fig. 91). Clearly every cell of X overlaps this hypercube. Along each dimension, the
number of cells of G that can overlap an interval of side length 2r is at most 1 + d2r/xe.
Thus, the number of grid cubes of G that overlap H is at most (1 + d2r/xe)d . If 2r < x,
this quantity is at most 2d , and otherwise it is O((r/x)d ).
For the construction of the WSPD, we need to make a small augmentation to the quadtree
structure. We wish to associate each node of the tree, both leaves and internal nodes, with a
point that lies within its cell (if such a point exists). Given a node u, we will call this point
u’s representative and denote this as rep(u). We do this recursively as follows. If u is a leaf
node that contains a point p, then rep(u) = {p}. If u is a leaf node that contains no point,
then rep(u) = ∅. Otherwise, if u is an internal node, then it must have at least one child v
that is not an empty leaf. (If there are multiple nonempty children, we may select any one.)
Set rep(u) = rep(v).
Given a node u in the tree, let Pu denote the points that lie within the subtree rooted at
u. We will assume that each node u is associated with its level in the tree, denoted level(u).
Assuming that the original point set lies within a unit hypercube, the side lengths of the cells
are of the form 1/2i , for i ≥ 0. We define level(u) to be −log2 x, where x is the side length
Constructing a WSPD: We now have the tools needed to to show that, given an n-element
point set P in Rd and any s > 0, there exists a s-WSPD of size O(sd n), and furthermore,
this WSPD can be computed in time that is roughly proportional to its size. In particular,
the construction will take O(n log n + sd n) time. We will show that the final WSPD can be
encoded in O(sd n) total space. Under the assumption that s and d are fixed (independent of
n) then the space is O(n) and the construction time is O(n log n).
The construction operates as follows. Recall the conditions (1)–(4) given above for a WSPD.
We will maintain a collection of sets that satisfy properties (1) and (3), but in general they
may violate conditions (2) and (4), since they may not be disjoint and may not be well
separated. When the algorithm terminates, all the pairs will be well-separated, and this will
imply that they are disjoint. Each set {Ai , Bi } of the pair decomposition will be encoded as a
pair of nodes {u, v} in the quadtree. Implicitly, this pair represents the pairs Pu ⊗ Pv , that is,
the set of pairs generated from all the points descended from u and all the points descended
from v. This is particularly nice, because it implies that the total storage requirement is
proportional to the number of pairs in the decomposition.
u
u2 u4
v v
u1 u3
u u
u1 u2 u3 u4 v u1 u2 u3 u4 v
(a) (b)
The algorithm is based on a recursive subdivision process. Consider a pair of nodes {u, v}
that arise in the decomposition process. If either of the nodes is an empty leaf, then we
may ignore this pair. If both of the nodes are leaves, then they are clearly well-separated
(irrespective of the value of s), and we may output this pair. Otherwise, let us assume that
u’s cell is least as large as v’s. That is, u’s level number is not greater than v’s. (Recall that
a leaf node is treated as an infinitesimally small quadtree cell that contains the node’s point,
and its level is defined to be +∞. So if an internal node and a leaf node are compared, the
internal node is always deemed to have the larger cell.) Consider the two smallest Euclidean
balls of equal radius that enclose u’s cell and v’s cell (see Fig. 92(a)). If these balls are well
separated, then we can report {u, v} as (the encoding of) a well separated pair. Otherwise,
we subdivide u by considering its children, and apply the procedure recursively to the pairs
How do we test whether two nodes u and v are s well separated? For each internal node,
consider the smallest Euclidean balls enclosing the associated quadtree cells. For each leaf
node, consider a degenerate ball of radius zero that contains the point. In O(1) time, we can
determine whether these balls are s well separated. Note that a pair of leaf cells will always
pass this test (since the radius is zero), so the algorithm will eventually terminate.
Remark: Due to its symmetry, this procedure will generally produce duplicate pairs {Pu , Pv }
and {Pv , Pu }. A simple disambiguation rule can be applied to eliminate this issue.
Analysis: How many pairs are generated by this recursive procedure? It will simplify our proof
to assume that the quadtree is not compressed (and yet it has size O(n)). This allows us to
assume that the children of each node all have cell sizes that are exactly half the size of their
parent’s cell. (We leave the general case as an exercise.)
From this assumption, it follows that whenever a call is made to the procedure ws-pairs(),
the sizes of the cells of the two nodes u and v differ by at most a factor of two (because we
always split the larger of the two cells). It will also simplify the proof to assume that s ≥ 1
(if not, replace all occurrences of s below with max(s, 1)).
To evaluate the number of well separated pairs, we will count calls to the procedure ws-pairs().
We say that a call to ws-pairs is terminal if it does not make it to the final “else” clause. Each
terminal call generates at most one new well separated pair, and so it suffices to count the
number of terminal calls to ws-pairs. In order to do this, we will instead bound the number
of nonterminal calls. Each nonterminal call generates at most 2d recursive calls (and this is
the only way that terminal calls may arise). Thus, the total number of well separated pairs
is at most 2d times the number of nonterminal calls to ws-pairs.
To count the number of nonterminal calls to ws-pairs, we will apply a charging argument to
the nodes of the compressed quadtree. Each time we make it to the final “else” clause and
split the cell u, we assign a charge to the “unsplit” cell v. Recall that u is generally the larger
of the two, and thus the smaller node receives the charge. We assert that the total number of
charges assigned to any node v is O(sd ). Because there are O(n) nodes in the quadtree, the
bv
√
≤ sx d
x v
rv u
Rv
Let bv be a Euclidean ball centered at v’s cell of radius Rv . Summarizing the above discussion,
we know that the set of quadtree nodes u that can assess a charge to v have cell sizes of either
x or 2x and overlap bv . Clearly the cells of side length x are disjoint from one another and
the cells of side length 2x are disjoint from one another. Thus, by the Packing Lemma, the
total number of nodes that can assess a charge to node v is at most C, where
d d d
2Rv 2Rv 2Rv
C ≤ 1+ + 1+ ≤ 2 1+
x 2x x
& √ '!d
6sx d √
≤ 2 1+ ≤ 2(2 + 6s d)d .
x
(In the last inequality, we used the fact that dze ≤ 1 + z.) Since the dimension d is assumed
to be a constant and s ≥ 1, this is O(sd ).
Putting this all together, we recall that there are O(n) nodes in the compressed quadtree and
O(sd ) charges assigned to any node of the tree, which implies that there are a total of O(sd n)
total nonterminal calls to ws-pairs. As observed earlier, the total number of well separated
pairs is larger by a factor of O(2d ), which is just O(1) since d is a constant. Together with the
O(n log n) time to build the quadtree, this gives an overall running time of O((n log n) + sd n)
and O(sd n) total well separated pairs. In summary we have the following result.
Theorem: Given a point set P in Rd , and a fixed separation factor s ≥ 1, in O(n log n + sd n)
time it is possible to build an s-WSPD for P consisting of O(sd n) pairs.
(1) Ai , Bi ⊆ P , for 1 ≤ i ≤ m
(2) Sin∩ Bi = ∅, for 1 ≤ i ≤ m
A
(3) i=1 Ai ⊗ Bi = P ⊗ P
(4) Ai and Bi are s-well separated, for 1 ≤ i ≤ m,
Lemma: (WSPD Utility Lemma) If the pair {Pu , Pv } is s-well separated and x, x0 ∈ Pu and
y, y 0 ∈ Pv then:
(i) kx − x0 k ≤ 2s · kx − yk
(ii) kx0 − y 0 k ≤ 1 + 4s kx − yk
2r 2r
≥ sr y
x0 x y0
Pu Pv
Fig. 94: WSPD Utility Lemma.
Proof: Since the pair is s-well separated, we can enclose each of Pu and Pv in a ball of radius
r such that the minimum separation between these two balls is at least sr. It follows
that max(kx − x0 k, ky − y 0 k) ≤ 2r, and any pair from {x, x0 } × {y, y 0 } is separated by a
distance of at least sr. Thus, we have
2r 2r 2
kx − x0 k ≤ 2r = sr ≤ kx − yk = kx − yk,
sr sr s
Approximating the Diameter: The diameter of a point set is defined to be the maximum dis-
tance between any pair of points of the set. (For example, the points x and y in Fig. 95(a)
define the diameter.)
2r
y y
pv P v
≥ sr
Pu
x x
pu
2r
(a) (b)
The diameter can be computed exactly by brute force in O(n2 ) time. For points in the
plane, it is possible to compute the diameter15 in O(n log n) time. Generalizing this method
to higher dimensions results in an O(n2 ) running time, which is no better than brute force
search.
Using the WSPD construction, we can easily compute an ε-approximation to the diameter of
a point set P in linear time. Given ε, we let s = 4/ε and construct an s-WSPD. As mentioned
above, each pair (Pu , Pv ) in our WSPD construction consists of the points descended from
two nodes, u and v, in a compressed quadtree. Let pu = rep(u) and pv = rep(v) denote
the representative points associated with u and v, respectively. For every well separated pair
{Pu , Pv }, we compute the distance kpu − pv k between their representative, and output the
pair achieving the largest such distance.
To prove correctness, let x and y be the points of P that realize the diameter. Let {Pu , Pv }
be the well separated pair containing these points, and let pu and pv denote their respective
representatives. By the WSPD Utility Lemma we have
4
kx − yk ≤ 1+ kpu − pv k = (1 + ε)kpu − pv k.
s
Since {x, y} is the diametrical pair, we have
kx − yk
≤ kpu − pv k ≤ kx − yk,
1+ε
15
This is nontrivial, but is not much harder than a homework exercise. In particular, observe that the diameter
points must lie on the convex hull. After computing the hull, it is possible to perform a rotating sweep that finds the
diameter.
Closest Pair (Exact!): The same sort of approach could be used to produce an ε-approximation
to the closest pair as well, but surprisingly, there is a much better solution. If we were to
generalize the above algorithm, we would first compute an s-WSPD for an appropriate value
of s, and for each well separated pair {Pu , Pv } we would compute the distance kpu − pv k,
where pu = rep(u) and pv = rep(v), and return the smallest such distance. As before, we
would like to argue that (assuming s is chosen properly) this will yield an approximation to
the closest pair. It is rather surprising to note that, if s is chosen carefully, this approach
yields the exact closest pair, not just an approximation.
To see why, consider a point set P , let x and y be the closest pair of points and let pu and
pv be the representatives from their associated well separated pair. If it were the case that
x = pu and y = pv , then the representative-based distance would be exact. Suppose therefore
that either x 6= pu or y 6= pv . But wait! If the separation factor is high enough, this would
imply that either kx − pu k < kx − yk or ky − pv k < kx − yk, either of which contradicts the
fact that x and y are the closest pair.
To make this more formal, let us assume that {x, y} is the closest pair and that s > 2. We
know that Pu and Pv lie within balls of radius r that are separated by a distance of at least
sr > 2r. If pu 6= x, then we have
Low-Stretch Spanners: Recall that a set P of n points in Rd defines a complete weighted graph,
called the Euclidean graph, in which each point is a vertex, and every pair of vertices is
connected by an edge whose weight is the Euclidean distance between these points. This graph
is dense, meaning that it has Θ(n2 ) edges. Intuitively, a spanner is a sparse graph (having only
O(n) edges) in which shortest paths are not significantly longer than the Euclidean distance
between points. Such a graph is called a (Euclidean) spanner.
More formally, suppose that we are given a set P in Rd and a parameter t ≥ 1, called the
stretch factor. A t-spanner is a weighted graph G whose vertex set is P and, given any pair
of points x, y ∈ P we have
kx − yk ≤ δG (x, y) ≤ t · kx − yk,
where δG (x, y) denotes the length of the shortest path between x and y in G.
In an earlier lecture, we showed that the Delaunay triangulation of P is an O(1)-spanner.
This was only really useful in the plane, since in dimension 3 and higher, the Delaunay
triangulation can have a quadratic number of edges. Here we consider the question of how
WSPD-based Spanner Construction: Given the point set P and a (constant) stretch factor t,
the idea is to build an s-WSPD for P , where s is an appropriately chosen separation factor
(which will depend on t). We will then create one edge in the spanner from each well-separated
pair.
Given t, we set s = 4(t + 1)/(t − 1). (Later we will justify the mysterious choice.) For each
well-separated pair {Pu , Pv } associated with the nodes u and v of the quadtree, let pu = rep(u)
and let pv = rep(v). Add the undirected edge {pu , pv } to our graph. Let G be the resulting
undirected weighted graph (see Fig. 96). G will be the desired spanner. Clearly the number of
edges of G is equal to the number of well-separated pairs, which is O(sd n) = O(n), and it can
be built in the same O(n log n + sd n) = O(n log n) running time as the WSPD construction.
rep(v)
Pu rep(u) rep(u)
Pv rep(v)
WSPD Spanner
(a) (b)
kx − yk ≤ δG (x, y) ≤ t · kx − yk.
Clearly, the first inequality holds trivially, because (by the triangle inequality) no path in
any graph can be shorter than the distance between the two points. To prove the second
inequality, we apply an induction based on the number of edges of the shortest path in the
spanner.
For the basis case, observe that, if x and y are joined by an edge in G, then clearly δG (x, y) =
kx − yk ≤ t · kx − yk for all t ≥ 1.
If, on the other hand, there is no direct edge between x and y, we know that x and y must
lie in some well-separated pair {Pu , Pv } defined by the pair of nodes {u, v} in the quadtree.
let pu = rep(u) and pv = rep(v) be the respective representative points. (It might be that
pu = x or pv = y, but not both.) Let us consider the length of the path from x to pu to pv to
y. Since the edge {pu , pv } is in the graph, we have
By the WSPD Utility Lemma (with {x, pu } from one pair and {y, pv } from the other) we
have
2 4
max(kx − pu k, kpv − yk) ≤ · kx − yk and kpu − pv k ≤ 1+ kx − yk.
s s
To complete the proof, observe that it suffices to select s so that 1 + 4(t + 1)/s ≤ t. Towards
this end, let us set
t+1
s = 4 .
t−1
This is well defined for any t > 1. By substituting in this value of s, we have
4(t + 1)
δG (x, y) ≤ 1+ kx − yk = (1 + (t − 1))kx − yk = t · kx − yk,
4(t + 1)/(t − 1)
Theorem: Given a point set P in Rd and ε > 0, a (1 + ε)-spanner for P containing O(n/εd )
edges can be computed in time O(n log n + n/εd ).
To see why this works, consider any pair of points {x, y}, and let w(x, y) = kx − yk denote the
weight of the edge between them in the complete Euclidean graph. Let T denote the edges of
the Euclidean minimum weight spanning tree, and w(T ) denote the total weight of its edges.
For each edge {x, y} ∈ T , let πG (x, y) denote the shortest path (as a set of edges) between x
and y in the spanner, G. Since G is a spanner, we have
w(πG (x, y)) = δG (x, y) ≤ (1 + ε)kx − yk.
Now, consider the subgraph G0 ⊆ G formed by taking the union of all the edges of πG (x, y)
for all {x, y} ∈ T . That is, G and G0 have the same vertices, but each edge of the MST is
replaced by its spanner path. Clearly, G0 is connected (but it may not be a tree). We can
bound the weight of G0 in terms of the weight of the Euclidean MST:
X X
w(G0 ) = w(πG (x, y)) ≤ (1 + ε)kx − yk
{x,y}∈T {x,y}∈T
X
= (1 + ε) kx − yk = (1 + ε)w(T ).
{x,y}∈T
However, because G and G0 share the same vertices, and the edge set of G0 is a subset of the
edge set of G, it follows that w(MST(G) ≤ w(MST(G0 )). (To see this, observe that if you
have fewer edges from which to form the MST, you may generally be forced to use edges of
higher weight to connect all the vertices.) Combining everything we have
w(MST(G)) ≤ w(MST(G0 )) ≤ w(G0 ) ≤ (1 + ε)w(T ),
Eulerian Paths. The foundations of graph theory are largely credited to Euler who established
its first result by resolving the well-known Eulerian path problem in 1735. In its original form,
the problem simply asked to find a path that crossed each of seven bridges exactly once; see
Figure 99(left).
⇒
Fig. 99: Seven Bridges of Königsberg, and the origin of graph theory. (Figures from [1, 2])
Euler’s topological insight was to recognize that the subpaths within each land mass are
irrelevant to the solution. This allows one to consider the abstract setting provided by the
usual graph model; see Figure 99(right). Next, observing how the path first enters into a node
through an edge before leaving through a different edge, Euler correctly identified the issue
with vertices of odd degree. In particular, an Eulerian path exists if and only if the graph has
As hinted in the previous example, one of the main uses of topological ideas is to identify an
obstruction to the existence of an object.
Fig. 100: Graph minors and coloring. (Figures from [3, 4, 5])
Another example of obstruction is provided in the context of graph coloring, which has many
applications in scheduling and distributed computing. Recall that a t-coloring of a graph is
an assignment of one of t colors to each vertex such that no two adjacent vertices get the
same color; see Figure 100(c). Clearly, a coloring of Kt requires at least t colors. One of
the deepest unsolved problems in graph theory is the Hadwiger conjecture (1943) postulating
that Kt minors are the only obstruction to the existence of colorings with fewer than t colors.
Beyond the discrete spaces commonly studied in graph theory, a topological space can be any
set endowed with a topology, i.e., a neighborhood structure. The mathematical subject of topology is
the formal study of properties of topological spaces which are invariant under continuous functions.
Such properties are simply referred to as topological invariants.
Genus. Intuitively, the genus of a connected and orientable surface is the number of holes or
handles on it; see Figure 101. It is a traditional joke that a topologist cannot distinguish his
coffee mug from his doughnut; as both have genus one, they may be (continuously) deformed
into one another and are in that sense topologically equivalent. In contrast, the mismatch in
the genus is an obstruction to the existence of continuous mappings from spheres to tori.
In relation to the previous examples, the genus of a graph is the smallest g such that the
graph can be drawn without crossing on an orientable surface of genus g. Because the Earth
is (locally) flat, planar graphs can be drawn on the sphere implying they have genus zero.
More generally, the genus is one of the measures of complexity of the graph, and can be
exploited to obtain faster algorithms for graphs with small genus. Alas, deciding whether a
given graph has genus g is NP-complete.
While we may be interested in studying surfaces, or other topological spaces, we need simpler
discrete structures to keep computations easy or at all feasible. This workaround does not allow
us to compute everything we might have wanted, but it does provide very useful information. For
example, the previous example showed how the genus can be used to classify surfaces. It turns out
there is a closely related topological invariant which is more amenable to computation.
Euler’s Polyhedron Formula. The following remarkable formula by Euler is considered, to-
gether with his resolution of the Seven Bridges of Königsberg problem, as the first two theo-
rems in topology. Consider a polyhedron P ⊂ R3 , and denote the number of vertices, edges,
and faces of P by V , E, and F , respectively. The Euler characteristic χ is defined as:
χ = V − F + E. (2)
For any convex polyhedron P , we have that χ = 2; see Figure 102. As the Euler characteristic
is a topological invariant, one correctly anticipates that it also evaluates to 2 for the sphere.
Fig. 102: Convex polyhedra with χ = 2. (Figures from [10, 11, 12, 13, 14])
The previous example confirms the intuition that convex polytopes are suitable as discrete
approximations to the sphere. In order to approximate arbitrary surfaces, which may not be
convex, we are going to need more flexible structures.
Simplicial Complexes. You are probably familiar with triangular subdivisions of planar shapes,
and the three-dimensional models suitable for rendering pipelines in computer games. Just a
Fig. 103: The Utah teapot, arguably the most important object in computer graphics history.
It will prove useful to use a notation that easily generalizes to higher dimensions. We start
with a set of points S ⊂ Rd , for d ≥ 0. We define a p-simplex σ as a subset of p + 1 points
in S, and we say that σ has dimension dim σ = p. For a geometric realization, the simplex
σ is the convex hull of p + 1 affinely-independent points; see Figure 104. We write this as
σ = conv{v0 , . . . , vp }. To capture the structure of the simplex, we define a k-face of σ is a
simplex τ with (1) τ ⊆ σ, and (2) dim τ = k for −1 ≤ k ≤ p; we write this as τ σ and call
σ a coface of τ . We say a (co)face of σ is proper if its dimension is different from dim σ, and
write ∂σ for the proper faces of σ. Finally, the interior of σ is defined as |σ| = σ − ∂σ.
(a) A 3-simplex. (b) Four 2-simplices. (c) Six 1-simplices. (d) Four 0-simplices.
Before we can use simplicial complexes as proxies of topological spaces, we also need to ap-
proximate the continuous maps between such spaces through their simplicial proxies. We start by
building some intuition as to how continuous maps act on spaces.
Continuous Maps. Imagine we have two surfaces X and Y , and a mapping f : X → Y . In this
case, f takes a point x ∈ X to the corresponding point y = f (x) ∈ Y . Visually, y is where x
ends up after going through some deformation that takes X to Y ; see Figure 105. When do
Fig. 105: A continuous deformation of a cow model (X) into a ball (Y ). (Figure from [15])
You are probably familiar with the notion of continuous functions from calculus which suggests
we use an ε-neighborhood V ⊆ Y around y and show that there is a corresponding δ = δ(ε)
such that all points in an δ-neighborhood U ⊆ X around x are mapped by f into V , i.e.,
f (U ) ⊆ V . In the particularly familiar context of a univariate function g : R → R, the
neighborhoods in question are immediately realized as open intervals of the form (a, b) ⊂ R,
where there is no shortage of intervals in the continuum which is R for us to choose from.
Specifically, we require that limε→0 δ(ε) = 0; see Figure 106(a).
Fig. 106: Essentially equivalent definitions of continuous functions. (Figures from [16, 17])
It is plausible to conclude that neighborhoods, rather than the ε and δ, are all we need for
continuity. Only that for general spaces, such as the surfaces X and Y , we have to work with
their particular neighborhoods as specified by their respective topologies; see Figure 106(b).
While not all topologies furnish neighborhoods as convenient as the intervals on the real line,
a meaningful version of continuous maps can be defined for spaces with similar topologies.
Given our enhanced understanding of continuity, it is about time to formalize what we mean
by topologically equivalent and simplicial proxy.
Simplicial Neighborhoods. Take a point x in the underlying space |X|. b To examine the conti-
nuity of f at x, we need to consider the neighborhood of x on |X|. While x may belong to
b b
many simplices of X, b there is a unique simplex that contains x in its interior ; let us denote
this simplex by σ(x). If another point x0 ∈ X b is a neighbor of x, it might be the case that
0 0
x ∈ |σ(x)|. However, we need to allow x to go outside |σ(x)| and reach farther parts of X. b
Let us consider what lies beyond |σ(x)|. For example, if dim X b = 3 and σ(x) is an edge with
0
dim σ(x) = 1, x could start at x in |σ(x)| and wander into a different simplex. Recalling the
geometric realization, we consider an ε-neighborhood around x. We allow this neighborhood
to expand over nearby interior points of adjacent simplices without crossing any boundaries,
i.e., mimicking open intervals from calculus. For example, we do not connect x to the inte-
rior of an adjacent edge e unless there is a path through the interior of a common face or
tetrahedron, i.e., a coface. As such, the neighborhood of x is contained in the cofaces of σ(x).
X̂ 7→ Ŷ
The cofaces of a simplex σ ∈ K constitute its star ; we write this as StK (σ) = {τ ∈ K | σ τ }.
Taking the union of all interior points, we define the star neighborhood as NK (σ) = ∪τ ∈StK (σ) |τ |;
see Figure 107. It will suffice for our purposes to consider the neighborhoods of vertices in Xb and
Yb .
Star Condition. Recalling the definition of continuity, we require our maps fb : |X| b → |Yb | to
satisfy fb(NXb (v)) ⊆ NYb (u) for all vertices v ∈ X b and some vertex u = φ(v) ∈ Yb ; see
Figure 107. This star condition has the following important consequence. Fix a point x ∈ |X|, b
and let σ ∈ X and τ ∈ Y denote the unique simplices containing x and f (x), respectively, in
b b b
their interiors. Assuming σ is the p-simplex [v0 , . . . , vp ], we have by the definition of the star
that x ∈ NXb (σ) ⊆ NXb (vi ), for all 0 ≤ i ≤ p; in fact NXb (σ) = ∩pi=0 NXb (vi ). Passing through
fb, the star condition implies that fb(x) ∈ fb(NXb (σ)) ⊆ ∩pi=0 NYb (φ(vi )) 6= ∅. By the same
token, we get that [φ(v0 ), . . . , φ(vp )] is a simplex in Yb which must coincide with τ 3 fb(x),
i.e., fb(σ) = τ .
Instead of arbitrary continuous maps, there is great appeal to working with piecewise-linear
maps on triangulations. In fact, the star condition was chosen to provide exactly that.
Simplicial Approximations. Assume that fb : |X| b → |Yb | satisfies the star condition, and let
b → Vert Yb be the associated vertex map. Fixing a p-simplex σ = conv{v0 , . . . , vp },
φfb : Vert X
we may express any x ∈ |σ| as a linear Ppcombination of the vertices. Using the so-called
barycentric coordinates, we write x = i=0 λi vi , where λi > 0 ∀i. The expression can be
While the star condition seems to provide all we need, it is only a convenient assumption we had
to introduce. What about continuous maps from |X| b to |Yb | that the assumption fails to capture?
Subdivisions. Assume that a continuous map fb : |X| b → |Yb | does not satisfy the star condition.
Then, there must be a vertex v ∈ X such that fb(NXb (v)) is not contained in NYb (u) for any
b
vertex u ∈ Yb . Equivalently, NXb (v) is not contained in any fb−1 (NYb (u)). In other words,
NXb (v) is relatively too large. Can we make the star of v smaller without changing fb?
Fig. 108: Barycentric subdivisions of a triangle with an incident edge. New elements are highlighted.
It becomes clear that we need to keep |X| b intact, so that fb remains essentially the same, while
making some stars smaller to satisfy the star condition. As the stars are defined by X, b we
seek a finer triangulation of |X|. One way to achieve that is to subdivide every simplex σ into
b
smaller ones {σi0 } such that |σ| = ∪σi0 . In particular, we make use of the barycenter of each
simplex in X,b which is defined as the average of its vertices. For p = 1 to dim X,b we insert the
barycenter σc of each p-simplex σ as a new vertex, and form new p-simplices σi0 by connecting
σc to each (p − 1)-simplex of the (subdivided) (p − 1)-faces of ∂σ; denote this barycentric
subdivision by Sd. A simple induction shows that every p-simplex is replaced by (p + 1)! new
p
p-simplices; see Figure 108. More importantly, for any p-simplex σ, diam(σi0 ) ≤ p+1 diam(σ).
By repeating as needed, the diameters of all simplices are rapidly reduced such that the
star neighborhoods of all vertices in Sdk X b are covered by the pre-image of some vertex in Yb .
k b
Specifically, Sd X satisfies the star condition for a finite k ≥ 0 and a simplicial approximation
can then be defined on Sdk X; b this is known as the simplicial approximation theorem.
Chains. WeP define the p-chains Cp as so-called formal sums of p-simplices: a p-chain c is written
as c = i ai σi , where σi ranges over all p-simplices in K and ai simply indicates whether σi is
included in c or not. To facilitate the counting of simplices, we define an addition operation.
The sum of two chains c1 + c2 is the chain with all simplices in either c1 or c2 , but not both,
i.e., their symmetric difference. In other words, we choose ai as modulo 2 coefficients.
The algebraic framework we are about to develop will compensate for the lack of geometric
visuals with greater expressive power, as will prove essential to our computations.
Using this new language, we say that (Cp , +) is an abelian group. In particular, if K has np
p-simplices, then (Cp , +) is (isomorphic to) the set of binary vectors of length np with the usual
exclusive-or operation ⊕. Hence, (Cp , +) is not just any group; it is a vector space!
Boundary Maps. By our definition of chains, any p-simplex σ ∈ K also belongs to the chain
group Cp . As the boundary of σ is a collection of (p − 1)-simplices, it will be convenient to
express the boundary in one shot as an element in Cp−1 . Letting σ = [v0 , . . . , vp ] we write:
p
X
∂p σ = [v0 , . . . , vbi , . . . , vp ], (3)
i=0
where vbi indicates that vi is excluded in the corresponding (p − 1) face. We can also take the
boundary of a collection of p-simplices, i.e., a p-chain, to obtain the sum of their boundaries
P as
a single (p−1)-chain. We denote this mapping by ∂p : Cp → Cp−1 , and write ∂p c = i ai ∂p σi .
Naturally, every chain group Cp gets its own boundary map ∂p , though we often drop the
subscript of ∂p as we have been doing already with addition and summation. The combined action
of those two operators gives rise to a rich algebraic structure essential to our computations.
Algebra II. A mapping δ : (A, •) → (B, ) is called a homomorphism if it commutes with the
group operation, i.e., δ(α • α0 ) = δα δα0 for all α, α0 ∈ A. (Note the switch from • to .)
Effectively, we have replaced the simplicial complex with a sequence of algebraic modules,
i.e., the chain complex. The added algebraic structuring of our chains quickly becomes useful
for computation. Building upon the familiar language of vector algebra, we obtain a particularly
convenient expression.
With the aid of these algebraic tools, we can now start using chains and see what comes out.
Boundaries and Cycles. Unlike the whole convex polytopes considered in Euler’s equation, the
chains we defined may correspond to an entire simplicial complex or just a subset of its
simplices. While some of the chains carry useful information about the complex, many do not.
Let us examine the 1-chains on triangulations of surfaces like the ones shown in Figure 101.
There are many chains that cannot help us distinguish the sphere from any of the tori, e.g.,
the boundary of a single triangle. In contrast, other types of chains only arise if there is a
handle; they include edges that wrap around one or more handles. We call that latter type
cycles. How do we extract the number of handles from these cycles?
It is easy to see a cycle, but our computations will benefit from an algebraic characterization.
If α is a 1-cycle, it consists of a set of vertices each shared by two edges. It follows that ∂1 α
counts each vertex twice modulo 2 yielding 0. But, the same could be said about the boundary
of any set of triangles whether it wraps around a handle or not. Hence, we distinguish two
subsets of p-chains that have no boundary: those that arise as the boundary of some (p + 1)-
chain under the action of ∂p+1 are the p-boundaries Bp , and the rest are the p-cycles Zp .
As outlined above, the fundamental lemma of homology asserts that ∂p ∂p+1 c = 0 for every
integer p and all chains c ∈ Cp+1 . Furthermore, as ∂p commutes with addition, both Bp and Zp
are subgroups of Cp , where Bp is in turn a subgroup of Zp .
Multiplicity of Representation. There would typically be multiple 1-cycles that wrap around a
single handle. Some of those cycles are minimal, containing only the edges that wrap around
the handle, while others contain extra 1-boundaries that carry no additional information.
Namely, for any α ∈ Zp and β ∈ Bp , we have that α0 = α + β ∈ Zp .
The above discussion suggests that we need to recognize equivalent cycles while ignoring the
contribution of any boundaries. To formalize this notion, we need a few more tools from algebra.
Before we apply quotients, we recall that the order of a group is the total number of elements,
and for abelian groups, like p-chains, the rank is the cardinality of a maximal linearly independent
subset, i.e., the number of p-simplices.
Homology Groups. We define the p-th homology group Hp as Zp /Bp . Now, to count the number
of p-holes, we seek to compute the rank of Hp ; this rank is known as the p-th Betti number
The computation of the Betti numbers relies on the following fundamental theorem in algebra.
Algebra IV. Let V and W be vector spaces and T : V → W be a linear transformation. We define
the kernel of T as the subspace of V , denoted Ker(T ) of all vectors v such that T (v) = 0.
The remaining elements v ∈ V for which T (v) 6= 0 are mapped to a subspace of W ; the image
of T . The rank-nullity theorem states that dim V = dim Image(T ) + dim Ker(T ).
In the context of p-chains, we get that Zp is the kernel of ∂p , while Bp−1 is its image. Hence,
rank Cp = rank Zp + rank Bp−1 . Note that B−1 = 0, and for a d-dimensional complex Zd+1 = 0.
The Euler Characteristic (Redux). Recalling the alternating sum in Euler’s polyhedron for-
mula, we can now use the Betti numbers to derive the generalized Euler-Poincaré formula.
X X
χ= (−1)p rank Cp = (−1)p (rank Zp + rank Bp−1 )
p≥0 p≥0
A remarkable fact is that homology groups do not depend on the triangulation used, i.e., they are
indeed topological invariants. Hence, the sequence of Betti numbers reveals important qualitative
features of the underlying space. Now, all that remains is to compute the ranks as in Equation 6.
Matrix Reduction. As discussed above, recognizing Zp as Ker(∂p ) we seek to compute the rank
of the matrix ∂p of dimensions rank Cp−1 × rank Cp ; see Equation 5. Using essentially the
Gaussian elimination algorithm, we can reduce the matrix ∂p without changing its rank by
a series of transformations, i.e., row and column operations, into the Smith normal form;
see Figure 109. As we work with modulo 2 coefficients, we obtain an initial segment of
the diagonal being 1 and everything else being 0. Namely, the leftmost rank Bp−1 columns
rank Cp
rank Zp
rank Bp−1
rank Cp−1
Fig. 109: Reducing the boundary matrix ∂p to the Smith normal form.
Beyond the topological invariants of the spaces themselves, topology is also concerned with the
invariants of maps between spaces.
∂X ∂X ∂X ∂X
... Cp+1 (X) Cp (X) Cp−1 (X) ...
b b b b
b b b
As the induced map fb# commutes with the boundary maps, it maps boundaries to boundaries
and cycles to cycles. Consequently, fb# induces a map between homology groups, which we
b → Hp (Yb ). This map H(fb) on homology is an algebraic reflection of
denote by H(fb) : Hp (X)
the continuous map f : |X|
b b → |Yb |; it is a form of functoriality as studied in category theory.
f1 f2
X
To demonstrate this powerful proof technique, we present a remarkable and far-reaching result.
f (x)
x ∂D ι D r ∂D F2 0 F2
H1 (ι) H1 (r)
Fig. 111: Self-maps on the disk D with no fixed points, and a contradiction through functoriality.
The proof above generalizes to higher dimensions; for Dn we use Hn−1 . This theorem is closely
related to the hairy ball theorem establishing the impossibility of continuous and everywhere non-
vanishing tangent vector fields on an even-dimensional sphere: you can’t comb the hair on a coconut!
Beyond the surfaces we have been using in our elementary introduction, data analysis appli-
cations frequently deal with sample points assumed to be drawn from an unknown underlying
manifold embedded in high dimensional space Rd . We conclude with a brief discussion of how the
techniques from above can be applied in this context, as has recently been in rapid development in
the computational topology and topological data analysis research communities.
A major thrust in the development of topological approaches to data analysis is to achieve
robustness against errors and imprecision in data measurements, collectively referred to as noise.
As we have seen, topological properties are less sensitive to exact distances, which can be useful in
the derivation of robust qualitative descriptors.
Homotopy Equivalence. An intuitive way to hallucinate the whole of a shape from a collection
of sample points is to grow a ball around each sample and take the union of those balls.
While this seems to work visually, there is a technical complication we need to consider. For
example, if we take a dense sample on a 1-dimensional curve, grow a ball at each sample and
take the union, we obtain a thick version of the curve; a tube of sorts. While the tube can be
deformed continuously into the original curve, it would not be possible to define a continuous
inverse, since many points on the tube will have to be mapped to the same point on the
curve. Still, we would expect the union of balls to capture the topology of the original shape.
This generalized notion of topological equivalence is called homotopy equivalence; while it is
weaker form of equivalence compared to homeomorphism, it can be much more convenient.
Applying the idea outlined above, we work with the union of balls of a suitable radius. Unsur-
prisingly, we replace the geometric object represented by the union of balls by an algebraic object
amenable to processing, i.e., a (abstract) simplicial complex.
Nerves. Taking the collection of balls centered at each sample point, we associate a vertex with
each ball and a p-simplex with each subset of (p + 1) balls with a non-empty intersection.
This type of complex is known as the nerve of the collection of objects; the balls in this case
as shown in Figure 112. The homotopy-equivalence of this Cêch complex and the union of
balls follows from the nerve lemma, which requires that the intersections of any set of objects
is contractible, i.e., homotopy-equivalent to a point. This turns out to be the case for any
collection of closed convex objects, not only balls, which can be related to Helly’s theorem.
There remains the issue of choosing a suitable radius. In addition, the choice of radius is not
completely separate from the density of the sample and the shape of the manifold. As the choice of
radius impacts the topology type observed through the union of balls, how do we identify the most
likely topology? This type of question motivated the recent development of a rich and exciting
theory that came to be known as persistent homology.
To appreciate the issue of scale, we consider different choices of radii for the example in Fig-
ure 112.
Filtrations. As seen in Figure 113 below, a very small radius results in a disconnected union of
balls, while an overly large radius yields a single blob with the hole filled in. Now, imagine a
continuous process of growing the radii from r = 0 to r = ∞, where we think of r as a function
of time t. As this process results in a sequence of nested shapes, it is called a filtration, with
t being the filtration parameter. At some point, say r(t0 ) = a, we recover the topology of the
circle for the first time. Then, at a later point t1 > t0 , with r(t1 ) = b > a, the hole is filled
in. Along the way, the number of connected components decreases as r goes from 0 to a.
While filtrations provide a dynamical model of the evolution of topological features, we still
need a way to extract the salient topological features as they appear and ultimately disappear. In
addition, we would like to discard extraneous features arising due to the sampling and noise.
Persistence. We define the birth and death of a topological feature as the values of the filtration
parameter when it first appears and when it gets filled in, respectively. Then, the persistence
of the feature is the difference between the two. In the example above, the persistence of the
1-cycle is t1 −t0 . Under reasonable conditions on the sampling, features with larger persistence
are more likely to capture salient aspects of the underlying shape of the data, while features
with small persistence can be disregarded, e.g., the many connected components in Figure 113.
Outlook. For this brief introduction, we did not cover the algorithmic aspects of computational
topology. The matrix reduction algorithm was simply presented as a variant of Gaussian elim-
ination, and we did not discuss the extensions needed to compute persistent homology. Other
important considerations involve more compact complexes than the Cêch complex, e.g., the
Vietoris-Rips complex, or the simplification of simplicial complexes to reduce their sizes with-
out changing their homotopy type, as would be beneficial for efficient computation. Finally,
the extracted persistent homology features can be summarized into convenient topological
signatures, known as persistence diagrams and barcodes, with an associated metric structure
such that it can be used to efficiently compare two data sets using their salient topological
properties. We hope the reader will be excited to further explore these topics, while catching
up on all the technical details that could not be presented here in more depth.
Affine Geometry: An affine geometry consists of a set of scalars (the real numbers), a set of
points, and a set of free vectors (or simply vectors). Points are used to specify position. Free
vectors are used to specify direction and magnitude, but have no fixed position in space.
(This is in contrast to linear algebra where there is no real distinction between points and
vectors. However this distinction is useful, since the two are conceptually quite different.)
The following are the operations that can be performed on scalars, points, and vectors. Vector
operations are just the familiar ones from linear algebra. It is possible to subtract two points.
The difference p − q of two points results in a free vector directed from q to p (see Fig. 114).
It is also possible to add a point to a vector. In point-vector addition p + v results in the
point which is translated by v from p. Letting S denote an generic scalar, V a generic vector
and P a generic point, the following are the legal operations in affine geometry:
~u + ~v p
p + ~v
~v p−q ~v
~u q
p
vector addition point subtraction point subtraction
Fig. 114: Affine operations.
A number of operations can be derived from these. For example, we can define the subtraction
of two vectors ~u − ~v as ~u + (−1) · ~v or scalar-vector division ~v /α as (1/α) · ~v provided α 6= 0.
aff(p0 , p1 ; α0 , α1 ) = α0 p0 + α1 p1 = p0 + α1 (p1 − p0 ).
Note that the middle term of the above equation is not legal given our list of operations. But
this is how the affine combination is typically expressed, namely as the weighted average of
two points. The right-hand side (which is easily seen to be algebraically equivalent) is legal.
An important observation is that, if p0 6= p1 , then the point aff(p0 , p1 ; α0 , α1 ) lies on the line
joining p0 and p1 . As α1 varies from −∞ to +∞ it traces out all the points on this line (see
Fig. 115).
r = p + 23 (q − p) α<0
p p p
1p + 2q 0<α<1
3 3
q
q q (1 − α)p + αq α>1
In the special case where 0 ≤ α0 , α1 ≤ 1, aff(p0 , p1 ; α0 , α1 ) is a point that subdivides the line
segment p0 p1 into two subsegments of relative sizes α1 to α0 . The resulting operation is called
a convex combination, and the set of all convex combinations traces out the line segment p0 p1 .
It is easy to extend both types of combinations to more than two points, by adding the
condition that the sum α0 + α1 + α2 = 1.
The set of all affine combinations of three (non-collinear) points generates a plane. The set
of all convex combinations of three points generates all the points of the triangle defined by
the points. These shapes are called the affine span or affine closure, and convex closure of
the points, respectively.
Euclidean Geometry: In affine geometry we have provided no way to talk about angles or dis-
tances. Euclidean geometry is an extension of affine geometry which includes one additional
operation, called the inner product, which maps two real vectors (not points) into a nonneg-
ative real. One important example of an inner product is the dot product, defined as follows.
Suppose that the d-dimensional vectors ~u and ~v are represented by the (nonhomogeneous)
coordinate vectors (u1 , u2 , . . . , ud ) and (v1 , v2 , . . . , vd ). Define
d
X
~u · ~v = ui vi ,
i=1
~v
v̂ = .
k~v k
Distance between points: Denoted either dist(p, q) or kpqk is the length of the vector
between them, kp − qk.
Angle: between two nonzero vectors ~u and ~v (ranging from 0 to π) is
~u · ~v
ang(~u, ~v ) = cos−1 = cos−1 (û · v̂).
k~ukk~v k
Orientation of Points: In order to make discrete decisions, we would like a geometric operation
that operates on points in a manner that is analogous to the relational operations (<, =, >)
with numbers. There does not seem to be any natural intrinsic way to compare two points in
d-dimensional space, but there is a natural relation between ordered (d + 1)-tuples of points
in d-space, which extends the notion of binary relations in 1-space, called orientation.
Given an ordered triple of points hp, q, ri in the plane, we say that they have positive orienta-
tion if they define a counterclockwise oriented triangle, negative orientation if they define a
clockwise oriented triangle, and zero orientation if they are collinear, which includes as well
the case where two or more of the points are identical (see Fig. 116). Note that orientation
depends on the order in which the points are given.
r q
q
r q
r
q p=r
p p p
positive negative zero zero
Fig. 116: Orientations of the ordered triple (p, q, r).
Orientation is formally defined as the sign of the determinant of the points given in homoge-
neous coordinates, that is, by prepending a 1 to each coordinate. For example, in the plane,
we define
1 px py
Orient(p, q, r) = det 1 qx qy .
1 rx ry
Observe that in the 1-dimensional case, Orient(p, q) is just q − p. Hence it is positive if p < q,
zero if p = q, and negative if p > q. Thus orientation generalizes <, =, > in 1-dimensional
space. Also note that the sign of the orientation of an ordered triple is unchanged if the points
are translated, rotated, or scaled (by a positive scale factor). A reflection transformation,
e.g., f (x, y) = (−x, y), reverses the sign of the orientation. In general, applying any affine
transformation to the point alters the sign of the orientation according to the sign of the
matrix used in the transformation.
Areas and Angles: The orientation determinant, together with the Euclidean norm can be used
to compute angles in the plane. This determinant Orient(p, q, r) is equal to twice the signed
area of the triangle 4pqr (positive if CCW and negative otherwise). Thus the area of the
triangle can be determined by dividing this quantity by 2. In general in dimension d the area
of the simplex spanned by d + 1 points can be determined by taking this determinant and
dividing by d! = d · (d − 1) · · · 2 · 1. Given the capability to compute the area of any triangle
(or simplex in higher dimensions), it is possible to compute the volume of any polygon (or
polyhedron), given an appropriate subdivision into these basic elements. (Such a subdivision
does not need to be disjoint. The simplest methods that I know of use a subdivision into
overlapping positively and negatively oriented shapes, such that the signed contribution of
the volumes of regions outside the object cancel each other out.)
Recall that the dot product returns the cosine of an angle. However, this is not helpful for
distinguishing positive from negative angles. The sine of the angle θ = ∠pqr (the signed
angled from vector p − q to vector r − q) can be computed as
Orient(q, p, r)
sin θ = .
kp − qk · kr − qk
(Notice the order of the parameters.) By knowing both the sine and cosine of an angle we
can unambiguously determine the angle.
Topology Terminology: Although we will not discuss topology with any degree of formalism,
we will need to use some terminology from topology. These terms deserve formal definitions,
but we are going to cheat and rely on intuitive definitions, which will suffice for the simple,
well behaved geometric objects that we will be dealing with. Beware that these definitions
are not fully general, and you are referred to a good text on topology for formal definitions.
For our purposes, for r > 0, define the r-neighborhood of a point p to be the set of points
whose distance to p is strictly less than r, that is, it is the set of points lying within an open
ball of radius r centered about p. Given a set S, a point p is an interior point of S if for some
radius r the neighborhood about p of radius r is contained within S. A point is an exterior
point if it lies in the interior of the complement of S. A points that is neither interior nor
exterior is a boundary point. A set is open if it contains none of its boundary points and
closed if its complement is open. If p is in S but is not an interior point, we will call it a
boundary point.
We say that a geometric set is bounded if it can be enclosed in a ball of finite radius. A set
is compact if it is both closed and bounded.
In general, convex sets may have either straight or curved boundaries and may be bounded
or unbounded. Convex sets may be topologically open or closed. Some examples are shown
in Fig. 117. The convex hull of a finite set of points in the plane is a bounded, closed, convex
polygon.
b −b maximum
b si,j = aj −ai minimum
slope
j i slope
∆b pj
pi bj − bi
∆a 8th smallest slope
a aj − ai
Fig. 118: (a) Slope analysis, (b) the slope si,j , and (c) the slope set S = {si,j | 1 ≤ i < j ≤ n}.
In order to study the properties of s, a statistician considers the set of slopes of the lines
joining pairs of a points (since each slope represents the increase in benefit for a unit increase
in the amount of treatment). For 1 ≤ i < j ≤ n, define
bj − bi
si,j = ,
aj − ai
(see Fig. 118(b)). So that we don’t need to worry about infinite slopes, let us make the
simplifying assumption that the a-coordinates of the points are pairwise distinct, and to
let us assume that the slopes are distinct. Let S = {si,j | 1 ≤ i < j ≤ n}. Clearly
avoid ties,
|S| = n2 = n(n − 1)/2 = O(n2 ). Although the set S of slopes is of quadratic size, it is defined
by a set of n points. Thus, a natural question is whether we can answer statistical questions
about the set S in time O(n) or perhaps O(n log n), rather than the obvious O(n2 ) time.
Here are some natural questions we might ask about the set S (see Fig. 118(c)):
Counting Negative Slopes and Inversions: In this lecture we will consider the last problem,
that is, counting the number of slopes that lie within a given interval [s− , s+ ]. Before con-
sidering the general problem, let us consider a simpler version by considering the case where
s− = 0 and s+ = +∞. In other words, we will count the number of pairs (i, j) where si,j
is nonnegative. This problem is interesting statistically, because it represents the number of
instances in which increasing the amount of treatment results in an increase in the therapeutic
benefit.
Our approach will be to count the number of pairs such that si,j is strictly negative. There
is no loss of generality in doing this, since we can simply subtract the count from n2 to
obtain the number of nonnegative slopes. (The reason for this other formulation is that it
will allow us to introduce the concept of inversion counting, which will be useful for the
general problem.) It will simplify the presentation to make the assumption that the sets of
a-coordinates and b-coordinates are distinct.
Suppose we begin by sorting the points of P in increasing order by their a-coordinates. Let
P = hp1 , . . . , pn i be the resulting ordered sequence, and let B = hb1 , . . . , bn i be the associated
sequence of b-coordinates. Observe that, for 1 ≤ i < j ≤ n, bi > bj if and only if si,j is
negative. For 1 ≤ i < j ≤ n, we say that the pair (i, j) is an inversion for B if bi > bj .
Clearly, our task reduces to counting the number of inversions of B (see Fig. 119(a)).
6 points 15 slopes
7 negative slopes
b5 7 inversions B1[i] (6) induces
b2 3 inversions
i j
b1
B1: 3 4 6 B2: 1 2 5
b6
b4
b3
M: 1 2 3 4 5 6
a1 a2 a3 a4 a5 a6
(a) (b)
The running time exactly matches that of MergeSort. It obeys the well known recurrence
T (n) = 2T (n/2) + n, which solves to O(n log n).
By combining this with the above reduction from slope range counting over negative slopes,
we obtain an O(n log n) time algorithm for counting nonnegative slopes.
General Slope Range Counting and Duality: Now, let us consider the general range counting
problem. Let [s− , s+ ] be the range of slopes to be counted. It is possible to adapt the
above inversion-counting approach, subject to an appropriate notion of “order”. In order to
motivate this approach, we will apply a geometric transformation that converts the problem
into a form where this order is more apparent. This transformation, called point-line duality
will find many uses later in the semester.
To motivate duality, observe that a point in R2 is defined by two coordinates, say (a, b). A
nonvertical line line in R2 can also be defined by two parameters, a slope and y-intercept.
In particular, we associate a point p = (a, b) with the line y = ax − b, whose slope is a and
16
More formally, we maintain the invariant that B1 [i] > B2 [j 0 ] for 1 ≤ j 0 ≤ j −1 and B2 [j] ≥ B1 [i0 ] for 1 ≤ i0 ≤ i−1.
Interestingly, this is just si,j . In other words, we have the following nice relationship: Given
two points, the x-coordinate of the intersection of their dual lines is the slope of the line
passing through the points (see Fig. 120). (The reason for negating the b coordinate is now
evident. Otherwise, we would get the negation of the slope.)
p∗j : y = aj x − bj
b −b y
si,j = aj −ai p∗i : y = aix − bi
bj j i
pj
bi pi
x
ai aj b −b
si,j = aj −ai
j i
(a) (b)
Fig. 120: Point-line duality and the relationship between the slope of a line between two points
and the x-coordinate of the duals of the two points.
Slope Range Counting in the Dual: Based on the above observations, we see that the problem
of counting the slopes of S that lie within the interval [s− , s+ ] can be reinterpreted in the
following equivalent form. Given a set of n nonvertical lines in R2 and given an interval
[s− , s+ ], count the pairs of lines whose intersections lie within the vertical slab whose left side
is x = s− and whose right side is s+ (see Fig. 121(a)).
How can we count the number of such intersection points efficiently? Again, this can be done
through inversion counting. To see this, observe that two lines intersect within the slab if
and only if the order of their intersection with the left side of the slab is the inverse of their
intersection with the right side of the slab.
We can reduce the problem to inversion counting, therefore, as follows. First, consider the
order in which the lines intersect the left side of the slab (taken from top to bottom). In
particular, the line y = ai x − bi intersects at the point y = ai s− − bi . Sort the lines according
in decreasing order of these y-coordinates, thus obtaining the order from top to bottom, and
renumber them from 1 to n according to this order (see Fig. 121(a)). Next, compute the
order in which the (renumbered) lines intersect the right side of the slab. In particular, line
i is associated with the value y = ai s+ − bi . Letting Y = hy1 , . . . , yn i denote the resulting
Fig. 121: Intersections in the vertical slab [s− , s+ ] and inversion counting.
sequence, it is easy to see that the number of inversions in −Y is equal to the number of pairs
of lines that intersect within the slab. The time to compute the intersection along the left
side and sort according to this order is O(n log n), and the time to compute the intersections
with the right side and count the inversions is also O(n log n). Therefore, the total running
time is O(n log n).
Negative Slope Range Counting Revisited: By the way, you might wonder what the earlier
instance of counting negative slopes maps to in this instance. In this case the interval is
[−∞, 0]. Observe that a vertical line at x = −∞ (from top to bottom) intersects the lines in
increasing order of slope, or equivalently, in order of a-coordinates. Thus, sorting the points
from top to bottom order by their intersection with s− = −∞ is equivalent to the sorting by
a-coordinates, which is just what we we did in the case of negative slopes.
The right side of the slab is determined by the top-to-bottom order of intersections of the
lines with vertical line at x = 0. Clearly, line i intersects this vertical at y = −bi . Therefore,
counting the inversions of the sequence −Y = h−y1 , . . . , −yn i is equivalent to the process of
counting inversions in the sequence B = hb1 , . . . , bn i, exactly as we did before. Thus, the case
of counting negative slopes can indeed be seen to be a special case of this algorithm.
Review: In summary, we have seen how an apparently 2-dimensional geometric problem involving
O(n2 ) (implicitly defined) objects can be solved in O(n log n) time through reduction to
a simple 1-dimensional sorting algorithm. Namely, we showed how to solve the slope range
counting problem in O(n log n) time. The problems of computing the minimum and maximum
slopes can also be solved in O(n log n) time. We will leave this problem as an exercise. The
problem of computing the k-th smallest slope is a considerably harder problem. It is not too
hard to devise a randomized algorithm whose running time is O(n log2 n). Such an algorithm
applies a sort of “randomized binary search” in dual space to locate the intersection point
of the desired rank. Improving the expected running time to O(n log n) time is a nontrivial
exercise, and making the algorithm deterministic is even more challenging. I do not know of
an efficient solution to the problem of computing the average slope.
Geometric Background: Let us recall some standard terminology. A circle is the set of points
that are equidistant from some center point. In 3-space this is called a sphere and in general
Rd space it is called a hypersphere. More formally, given a center point c = (c1 , . . . , cd ) ∈ Rd
and a positive radius r ∈ R, the hypersphere is the set of points p = (p1 , . . . , pd ) such that
d
X
(pi − ci )2 = r2 .
i=1
In 2-dimensional space, this is often called a disk. (Note that the terms “ball” and “disk”
refer to the solid object, while “circle,” “sphere,” and “hypersphere” refer to its boundary.)
We will present an algorithm for the MEB problem in R2 , and so we will use the terms “disk”
and “ball” to mean the same things.
Before discussing algorithms, we begin with two useful geometric observations. First, three
(noncollinear) points in the plane define a unique circle. We will not prove this, but it follows
from standard results in algebra. The second observation is presented in the following claim.
Claim: Consider a finite set S of points in the plane such that no four points are cocircular.
the minimum enclosing disk either has at least three points on its boundary, or it has
two points, and these points form the diameter of the circle. If there are three points
then they subdivide the circle bounding the disk into arcs of angle at most π.
Proof: Clearly if there are no points on the boundary the disk’s radius can be decreased
about its center until a single point lies on the boundary. If there is only one point
on the boundary then the disk can be shrunken about this point until a second point
is contacted (see Fig. 122(a)). If there are two points contacted, and they are not the
diameter of the disk, then between them there must be arc of length greater than π. It
follows that there is a family of disks whose centers lie on the perpendicular bisector of
these two points. By moving the center closer to the midpoint of these points, we obtain
a disk that is smaller and still contains all the points (see Fig. 122(b)). s
Thus, none of these configurations could be a candidate for the minimum enclosing disk.
Also observe that if there are three points that define the minimum enclosing disk they
subdivide the circle into three arcs each of angle at most π (see Fig. 122(c)). Because
points are in general position we may assume there cannot be four or more cocircular
points.
This immediately suggests a simple O(n4 ) time algorithm. In O(n3 ) time we can enumerate
all triples of points and then for each we generate the resulting circle and test whether it
encloses all the points in O(n) additional time, for an O(n4 ) time algorithm. You might make
a few observations to improve this a bit (e.g. by using only triples of points on the convex
hull). But even so a reduction from O(n4 ) to O(n) is quite dramatic.
Linearization: We cannot solve the MEB problem by a direct reduction to LP. In this section we’ll
discuss an approach that “almost” reduces the planar MEB problem to a linear programming
problem in 3-space. This serves to illustrate the similarity between this problem and LP.
Recall that in the MEB problem in R2 we are given a set P = {p1 , . . . , pn }, where pi =
(pi,x , pi,y ). These points are contained within a circle centered at point c and radius r if and
only if
(pi,x − cx )2 + (pi,y − cy )2 ≤ r2 , for 1 ≤ i ≤ n.
We are asked to determine whether there exists cx , cy and r (with r as small as possible)
satisfying these n inequalities. The problem is that these inequalities clearly involve quantities
like c2x and r2 and so are not linear inequalities in the parameters of interest.
The technique of linearization can be used to fix this. For each inequality, let us expand it
and rearrange the terms, yielding:
Observe that we now have n linear inequalities in three variables cx , cy and R. (We have
effectively replaced r with R.)
Great! We can apply linear programming to find the solution—or can we? The problem is
that the previous objective function was to minimize r. But r is no longer a parameter in the
new version of the problem. Observe that r2 = R + c2x + c2y , and minimizing r is equivalent
to minimizing r2 , we could say that the objective is to minimize R + c2x + c2y . Unfortunately,
this is a nonlinear function of the variables cx , cy and R. In summary, we have introduced a
change of variables that make the constraints linear, but the objective function is no longer
linear. Thus, this is not an instance of LP, and it would seem that we are back to square-one.
Claim: If pi ∈
/ Bi−1 then pi is on the boundary of the minimum enclosing disk for the first i
points, Bi .
Proof: The proof makes use of the following geometric observation. Given two intersecting
disks B1 and B2 of radii r1 and r2 , respectively, where r1 < r2 , the portion of B2 ’s
boundary that lies within B1 is an arc of angle less than π. To see why, observe that if
the arc were of angular extent greater than π it would contain two diametrically opposite
points. But these points would be at distance 2r2 from each other, which exceeds B1 ’s
diameter.
Now, suppose to the contrary that pi is not on the boundary of Bi . Let ri−1 and ri
denote the radii of Bi−1 and Bi , respectively. Because Bi covers a point that is not
covered by Bi−1 it follows that ri−1 < ri . By the above observation, the portion of
Bi ’s boundary that lies within Bi−1 is an arc of angle less than π (the heavy curve in
Fig. 123).
Bi?
Bi−1
pi
Since pi is not on the boundary of Bi , the points defining Bi must be chosen from among
the first i − 1 points, from which it follows that they all lie within this arc (the red points
in Fig. 123). This would imply that between two of the points is an arc of angle greater
than π (the arc not shown with a heavy line) which, by the earlier claim cannot be a
minimum enclosing disk.
Aided with this observation, the we can derive an algorithm is similar in structure to the
LP algorithm. First, we randomly permute the points and insert them one by one. For each
LP-Type: The above reduction shows that the MEB problem is closely related to LP. There are
in fact a number of related problems, like MEB, in which the incremental approach can be
applied. This concept was described formally by Sharir and Welzl, in which they introduced
the notion of LP-type problems. The input is given as a finite set S of elements, and there
is an objective function f that maps subsets of S to values from a totally ordered set. (For
example, think of f as the function that maps a set of points to the radius of their minimum
enclosing disk.) The objective function is required to satisfy two key properties:
Monotonicity: For sets A ⊆ B ⊆ S, f (A) ≤ f (B) ≤ f (S). That is, adding elements
increases the objective function.
Locality: For sets A ⊆ B ⊆ S and every x ∈ S, if f (A) = f (B) = f (A ∪ {x}), then
f (A) = f (B ∪ {x}). Intuitively, if x is redundant for A, it is redundant for every
The randomized incremental LP algorithm (due to Seidel) that we introduced earlier can be
readily generalized to handle LP-type problems.
Kirkpatrick’s Algorithm: Kirkpatrick’s idea starts with the assumption that the planar subdi-
vision is a triangulation, and further that the outer face is a triangle. If this assumption is not
met, then we begin by triangulating all the faces of the subdivision (see Fig. 124). The label
associated with each triangular face is the same as a label for the original face that contained
it. For the outer face is not a triangle, first compute the convex hull of the polygonal sub-
division, triangulate everything inside the convex hull. Then surround this convex polygon
with a large triangle (call the vertices a, b, and c), and then add edges from the convex hull
to the vertices of the convex hull. It may sound like we are adding a lot of new edges to
the subdivision, but recall from earlier in the semester that the number of edges and faces
in any straight-line planar subdivision is proportional to n, the number of vertices. Thus the
addition only increases the size of the structure by a constant factor.
Note that once we find the triangle containing the query point in the augmented graph, then
we will know the original face that contains the query point. The triangulation process can
be performed in O(n log n) time by a plane sweep of the graph, or in O(n) time if you want to
use sophisticated methods like the linear time polygon triangulation algorithm. In practice,
many straight-line subdivisions, may already have convex faces and these can be triangulated
easily in O(n) time.
Let T0 denote the initial triangulation. What Kirkpatrick’s method does is to produce a
sequence of triangulations, T0 , T1 , T2 , . . . , Tk , where k = O(log n), such that Tk consists only
c
Fig. 124: Triangulation of a planar subdivision.
of a single triangle (the exterior face of T0 ), and each triangle in Ti+1 overlaps a constant
number of triangles in Ti .
We will see how to use such a structure for point location queries later, but for now let
us concentrate on how to build such a sequence of triangulations. Assuming that we have
Ti , we wish to compute Ti+1 . In order to guarantee that this process will terminate after
O(log n) stages, we will want to make sure that the number of vertices in Ti+1 decreases by
some constant factor from the number of vertices in Ti . In particular, this will be done by
carefully selecting a subset of vertices of Ti and deleting them (and along with them, all the
edges attached to them). After these vertices have been deleted, we need retriangulate the
resulting graph to form Ti+1 . The question is: How do we select the vertices of Ti to delete,
so that each triangle of Ti+1 overlaps only a constant number of triangles in Ti ?
There are two things that Kirkpatrick observed at this point, that make the whole scheme
work.
Constant degree: We will make sure that each of the vertices that we delete have constant
(≤ d) degree (that is, each is adjacent to at most d edges). Note that the when we
delete such a vertex, the resulting hole will consist of at most d − 2 triangles. When we
retriangulate, each of the new triangles, can overlap at most d triangles in the previous
triangulation.
Independent set: We will make sure that no two of the vertices that are deleted are adjacent
to each other, that is, the vertices to be deleted form an independent set in the current
planar graph Ti . This will make retriangulation easier, because when we remove m
independent vertices (and their incident edges), we create m independent holes (non
triangular faces) in the subdivision, which we will have to retriangulate. However, each
of these holes can be triangulated independently of one another. (Since each hole contains
a constant number of vertices, we can use any triangulation algorithm, even brute force,
since the running time will be O(1) in any case.)
An important question to the success of this idea is whether we can always find a sufficiently
large independent set of vertices with bounded degree. We want the size of this set to be at
least a constant fraction of the current number of vertices. Fortunately, the answer is “yes,”
and in fact it is quite easy to find such a subset. Part of the trick is to pick the value of d to
be large enough (too small and there may not be enough of them). It turns out that d = 8 is
good enough.
We will present the proof of this lemma later. The number 18 seems rather large. The number
is probably smaller in practice, but this is the best bound that this proof generates. However,
the size of this constant is one of the reasons that Kirkpatrick’s algorithm is not used in
practice. But the construction is quite clever, nonetheless, and once a optimal solution is
known to a problem it is often not long before a practical optimal solution follows.
Kirkpatrick Structure: Assuming the above lemma, let us give the description of how the point
location data structure, the Kirkpatrick structure, is constructed. We start with T0 , and
repeatedly select an independent set of vertices of degree at most eight. We never include
the three vertices a, b, and c (forming the outer face) in such an independent set. We delete
the vertices from the independent set from the graph, and retriangulate the resulting holes.
Observe that each triangle in the new triangulation can overlap at most eight triangles in the
previous triangulation. Since we can eliminate a constant fraction of vertices with each stage,
after O(log n) stages, we will be down to the last three vertices.
The constant factors here are not so great. With each stage, the number of vertices falls by
a factor of 17/18. To reduce to the final three vertices, implies that (18/17)k = n or that
k = log18/17 n ≈ 12 lg n.
It can be shown that by always selecting the vertex of smallest degree, this can be reduced
to a more palatable 4.5 lg n.
The data structure is based on this decomposition. The root of the structure corresponds to
the single triangle of Tk . The nodes at the next lower level are the (new) triangles of Tk−1 ,
followed by Tk−2 , until we reach the leaves, which are the triangles of our initial triangulation,
T0 (see Fig. 125).
T0 T1 E T2 T3
a a
i b c b F B
k l
j d o K d K
e f e
IH G C D
f m G
J J T4
g p n g h J A
Fig. 125: Decomposing and triangulation by repeatedly removing an independent set and re-
triangulating.
Each node corresponding to a triangle in triangulation Ti+1 , stores pointers to all the triangles
it overlaps in Ti . Since there are at most eight of these, the structure has bounded degree.
Note that this structure is a directed acyclic graph (DAG) and not a tree, because one triangle
may have many parents in the data structure (see Fig. 126).
To locate a point, we start with the root, Tk . If the query point does not lie within this single
triangle, then we are done (it lies in the exterior face). Otherwise, we search each of the (at
most eight) triangles in Tk−1 that overlap this triangle. When we find the correct one, we
search each of the triangles in Tk−2 that overlap this triangles, and so forth. Eventually we
B D C
F E G H I J K
a b c d h e f g
i l n o p m k j
will find the triangle containing the query point in the last triangulation, T0 , and this is the
desired output.
Construction and Analysis: The structure has O(log n) levels (one for each triangulation), it
takes a constant amount of time to move from one level to the next (at most eight point-in-
triangle tests), thus the total query time is O(log n). The size of the data structure is the sum
of sizes of the triangulations. Since the number of triangles in a triangulation is proportional
to the number of vertices, it follows that the size is proportional to
(using standard formulas for geometric series). Thus the data structure size is O(n) (again,
with a pretty hefty constant).
The last thing that remains is to show how to construct the independent set of the appropriate
size. We first present the algorithm for finding the independent set, and then prove the bound
on its size.
It is easy to see that the algorithm runs in O(n) time (e.g., by keeping unmarked vertices in
a stack and representing the triangulation so that neighbors can be found quickly.)
Intuitively, the argument that there exists a large independent set of low degree is based on
the following simple observations. First, because the average degree in a planar graph is less
than six, there must be a lot of vertices of degree at most eight (otherwise the average would
be unattainable). Second, whenever we add one of these vertices to our independent set, only
eight other vertices become ineligible for inclusion in the independent set.
Here is the rigorous argument. Recall from Euler’s formula, that if a planar graph is fully
triangulated, then the number of edges e satisfies e = 3n − 6. If we sum the degrees of all the
vertices, then each edge is counted twice. Thus the average degree of the graph is
X
deg(v) = 2e = 6n − 12 < 6n.
v
Cuts and topological lines: The algorithm is called topological plane sweep because we do not
sweep a straight vertical line through the arrangement, but rather we sweep a curved topo-
logical line that has the essential properties of a vertical sweep line in the sense that this line
intersects each line of the arrangement exactly once. The notion of a topological line is an
intuitive one, but it can be made formal in the form of something called a cut. Recall that the
faces of the arrangement are convex polygons (possibly unbounded). (Assuming no vertical
lines) the edges incident to each face can naturally be partitioned into the edges that are above
the face, and those that are below the face. Define a cut in an arrangement to be a sequence
of edges c1 , c2 , . . . , cn , in the arrangement, one taken from each line of the arrangement, such
that for 1 ≤ i ≤ n − 1, ci and ci+1 are incident to the same face of the arrangement, and ci
is above the face and ci+1 is below the face (see Fig. 127).
The topological plane sweep starts at the leftmost cut of the arrangement. This consists of
all the left-unbounded edges of the arrangement. Observe that this cut can be computed in
O(n log n) time, because the lines intersect the cut in inverse order of slope. The topological
sweep line will sweep to the right until we come to the rightmost cut, which consists all of
the right-unbounded edges of the arrangement. The sweep line advances by a series of what
are called elementary steps. In an elementary steps, we find two consecutive edges on the cut
c2
c3
c4 c
5
c6
that meet at a vertex of the arrangement (we will discuss later how to determine this), and
push the topological sweep line through this vertex (see Fig. 128). Observe that on doing so
these two lines swap in their order along the sweep line.
It is not hard to show that an elementary step is always possible, since for any cut (other than
the rightmost cut) there must be two consecutive edges with a common right endpoint. In
particular, consider the edge of the cut whose right endpoint has the smallest x-coordinate.
It is not hard to show that this endpoint will always allow an elementary step. Unfortunately,
determining this vertex would require at least O(log n) time (if we stored these endpoints in
a heap, sorted by x-coordinate), and we want to perform each elementary step in O(1) time.
Hence, we will need to find some other method for finding elementary steps.
Upper and Lower Horizon Trees: To find elementary steps, we introduce two simple data
structures, the upper horizon tree (UHT) and the lower horizon tree (LHT). To construct
the upper horizon tree, trace each edge of the cut to the right. When two edges meet, keep
only the one with the higher slope, and continue tracing it to the right. The lower horizon
tree is defined symmetrically. There is one little problem in these definitions in the sense that
these trees need not be connected (forming a forest of trees) but this can be fixed conceptually
at least by the addition of a vertical line at x = +∞. For the upper horizon we think of its
slope as being +∞ and for the lower horizon we think of its slope as being −∞. Note that
we consider the left endpoints of the edges of the cut as not belonging to the trees, since
otherwise they would not be trees. It is not hard to show that with these modifications, these
are indeed trees. Each edge of the cut defines exactly one line segment in each tree. An
example is shown below.
The important things about the UHT and LHT is that they give us an easy way to determine
the right endpoints of the edges on the cut. Observe that for each edge in the cut, its right
endpoint results from a line of smaller slope intersecting it from above (as we trace it from
left to right) or from a line of larger slope intersecting it from below. It is easy to verify that
the UHT and LHT determine the first such intersecting line of each type, respectively. It
follows that if we intersect the two trees, then the segments they share in common correspond
(a) (b)
exactly to the edges of the cut. Thus, by knowing the UHT and LHT, we know where are the
right endpoints are, and from this we can determine easily which pairs of consecutive edges
share a common right endpoint, and from this we can determine all the elementary steps that
are legal. We store all the legal steps in a stack (or queue, or any list is fine), and extract
them one by one.
(1) Input the lines and sort by slope. Let C be the initial (leftmost) cut, a list of lines in
decreasing order of slope.
(2) Create the initial UHT incrementally by inserting lines in decreasing order of slope.
Create the initial LHT incrementally by inserting line in increasing order of slope. (More
on this later.)
(3) By consulting the LHT and UHT, determine the right endpoints of all the edges of
the initial cut, and for all pairs of consecutive lines (`i , `i+1 ) sharing a common right
endpoint, store this pair in stack S.
(4) Repeat the following elementary step until the stack is empty (implying that we have
arrived at the rightmost cut).
(a) Pop the pair (`i , `i+1 ) from the top of the stack S.
(b) Swap these lines within C, the cut (we assume that each line keeps track of its
position in the cut).
(c) Update the horizon trees. (More on this later.)
(d) Consulting the changed entries in the horizon tree, determine whether there are any
new cut edges sharing right endpoints, and if so push them on the stack S.
The important unfinished business is to show that we can build the initial UHT and LHT in
O(n) time, and to show that, for each elementary step, we can update these trees and all other
relevant information in O(1) amortized time. By amortized time we mean that, even though
a single elementary step can take more than O(1) time, the total time needed to perform all
O(n2 ) elementary steps is O(n2 ), and hence the average time for each step is O(1).
This is done by an adaptation of the same incremental “face walking” technique we used in
the incremental construction of line arrangements. Let’s consider just the UHT, since the
LHT is symmetric. To create the initial (leftmost) UHT we insert the lines one by one in
new line
v v
(a) (b)
Next we show how to update the UHT after an elementary step. The process is quite similar
(see Fig. 130(b)). Let v be the vertex of the arrangement which is passed over in the sweep
step. As we pass over v, the two edges swap positions along the sweep line. The new lower
edge, call it `, which had been cut off of the UHT by the previous lower edge, now must be
reentered into the tree. We extend ` to the left until it contacts an edge of the UHT. At its
first contact, it will terminate (and this is the only change to be made to the UHT). In order
to find this contact, we start with the edge immediately below ` the current cut. We traverse
the face of the UHT in counterclockwise order, until finding the edge that this line intersects.
Observe that we must eventually find such an edge because ` has a lower slope than the other
edge intersecting at v, and this edge lies in the same face.
Analysis: A careful analysis of the running time can be performed using the same amortization
proof (based on pebble counting) that was used in the analysis of the incremental algorithm.
We will not give the proof in full detail. Observe that because we maintain the set of legal
elementary steps in a stack (as opposed to a heap as would be needed for standard plane
sweep), we can advance to the next elementary step in O(1) time. The only part of the
elementary step that requires more than constant time is the update operations for the UHT
and LHT. However, we claim that the total time spent updating these trees is O(n2 ). The
argument is that when we are tracing the edges (as shown in the previous figure) we are
“essentially” traversing the edges in the zone for L in the arrangement. (This is not quite
true, because there are edges above ` in the arrangement, which have been cut out of the upper
tree, but the claim is that their absence cannot increase the complexity of this operation, only
decrease it. However, a careful proof needs to take this into account.) Since the zone of each
line in the arrangement has complexity O(n), all n zones have total complexity O(n2 ). Thus,
the total time spent in updating the UHT and LHT trees is O(n2 ).
s t s t s t
Claim: The shortest path between any two points that avoids a set of polygonal obstacles is
a polygonal curve, whose vertices are either vertices of the obstacles or the points s and
t.
Proof: We show that any path π that violates these conditions can be replaced by a slightly
shorter path from s to t. Since the obstacles are polygonal, if the path were not a
polygonal curve, then there must be some point p in the interior of free space, such
that the path passing through p is not locally a line segment. If we consider any small
neighborhood about p (small enough to not contain s or t or any part of any obstacle),
then since the shortest path is not locally straight, we can shorten it slightly by replacing
this curved segment by a straight line segment jointing one end to the other. Thus, π is
not shortest, a contradiction.
Thus π is a polygonal path. Suppose that it contained a vertex v that was not an
obstacle vertex. Again we consider a small neighbor hood about v that contains no part
of any obstacle. We can shorten the path, as above, implying that π is not a shortest
path.
From this it follows that the edges that constitute the shortest path must travel between s
and t and vertices of the obstacles. Each of these edges must have the property that it does
not intersect the interior of any obstacle, implying that the endpoints must be visible to each
other. More formally, we say that two points p and q are mutually visible if the open line
segment joining them does not intersect the interior of any obstacle. By this definition, the
two endpoints of an obstacle edge are not mutually visible, so we will explicitly allow for this
case in the definition below.
It follows from the above claim that the shortest path can be computed by first computing
the visibility graph and labeling each edge with its Euclidean length, and then computing
the shortest path by, say, Dijkstra’s algorithm (see CLR). Note that the visibility graph is
not planar, and hence may consist of Ω(n2 ) edges. Also note that, even if the input points
have integer coordinates, in order to compute distances we need to compute square roots,
and then sums of square roots. This can be approximated by floating point computations. (If
exactness is important, this can really be a problem, because there is no known polynomial
time procedure for performing arithmetic with arbitrary square roots of integers.)
Computing the Visibility Graph: We give an O(n2 ) procedure for constructing the visibility
graph of n line segments in the plane. The more general task of computing the visibility graph
of an arbitrary set of polygonal obstacles is a very easy generalization. In this context, two
vertices are visible if the line segment joining them does not intersect any of the obstacle line
segments. However, we allow each line segment to contribute itself as an edge in the visibility
graph. We will make the general position assumption that no three vertices are collinear, but
this is not hard to handle with some care. The algorithm is not output sensitive. If k denotes
the number of edges in the visibility graph, then an O(n log n + k) algorithm does exist, but
it is quite complicated.
The text gives an O(n2 log n) time algorithm. We will give an O(n2 ) time algorithm. Both
algorithms are based on the same concept, namely that of performing an angular sweep around
each vertex. The text’s algorithm operates by doing this sweep one vertex at a time. Our
algorithm does the sweep for all vertices simultaneously. We use the fact (given in the lecture
on arrangements) that this angular sort can be performed for all vertices in O(n2 ) time. If we
build the entire arrangement, this sorting algorithm will involve O(n2 ) space. However it can
be implemented in O(n) space using an algorithm called topological plane sweep. Topological
plane sweep provides a way to sweep an arrangement of lines using a “flexible” sweeping
line. Because events do not need to sorted, we can avoid the O(log n) factor, which would
otherwise be needed to maintain the priority queue.
Here is a high-level intuitive view of the algorithm. First, recall the algorithm for computing
trapezoidal maps. We shoot a bullet up and down from every vertex until it hits its first
line segment. This implicitly gives us the vertical visibility relationships between vertices and
segments (see the leftmost part of Fig. 132). Now, we imagine that angle θ continuously sweeps
out all slopes from −∞ to +∞. Imagine that all the bullet lines attached to all the vertices
begin to turn slowly counterclockwise. If we play the mind experiment of visualizing the
rotation of these bullet paths, the question is what are the significant event points, and what
happens with each event? As the sweep proceeds, we will eventually determine everything
that is visible from every vertex in every direction. Thus, it should be an easy matter to piece
together the edges of the visibility graph as we go.
Let us consider this “multiple angular sweep” in greater detail.
It is useful to view the problem both in its primal and dual form. For each of the 2n segment
endpoints v = (va , vb ), we consider its dual line v ∗ : y = va x − vb . Observe that a significant
event occurs whenever a bullet path in the primal plane jumps from one line segment to
another. This occurs when θ reaches the slope of the line joining two visible endpoints v and
Same segment: If v and w are endpoints of the same segment, then they are visible, and
we add the edge (v, w) to the visibility graph (see Fig. 133(a)).
Invisible: Consider the distance from v to w. First, determine whether w lies on the same
side as f (v) or b(v). For the remainder, assume that it is f (v) (see Fig. 133(b)). (The
case of b(v) is symmetrical).
Compute the contact point of the bullet path shot from v in direction θ with segment
f (v). If this path hits f (v) strictly before w, then we know that w is not visible to v,
and so this is a “non-event”.
Segment entry: Consider the segment that is incident to w. Either the sweep is just about
to enter this segment or is just leaving it. If we are entering the segment, then we set
f (v) to this segment (see Fig. 133(c)).
This is a pretty simple algorithm (although there are a number of cases). The only information
that we need to keep track of is (1) a priority queue for the events, and (2) the f (v) and
b(v) pointers for each vertex v. The priority queue is not stored explicitly. Instead it is
available from the line arrangement of the duals of the line segment vertices. By performing
a topological sweep of the arrangement, we can process all of these events in O(n2 ) time.
(There a few technical details in the implementation of the topological plane sweep, but we
will ignore them.)
Fig. 134: Approximating the minimum enclosing ball (MEB): (a) exact solution, (b) MEB of a
random sample, (c) MEB of a possible coreset.
For a given optimization problem, the relevant questions are: (1) does a small coreset exist?
(2) if so, how large must the coreset be to guarantee a given degree of accuracy? (3) how
quickly can such a coreset be computed? Ideally, the coreset should be significantly smaller
than n. For many optimization problems, the coreset size is actually independent of n (but
does depend on ε).
In this lecture, we will present algorithms for computing coresets for a problem called the
directional width. This problem can be viewed as a way of approximating the convex hull of
a point set.
Directional Width and Coresets: Consider a set P of points in real d-dimensional space Rd .
Given vectors ~u, ~v ∈ Rd , let (~v · ~u) denote the standard inner (dot) product in Rd . From basic
linear algebra we know that, given any vector ~u of unit length, for any vector ~v , (~v · ~u) is
the length of ~v ’s orthogonal projection onto ~u. The directional width of P in direction ~u is
defined to be the minimum distance between two hyperplanes, both orthogonal to ~u, that has
P “sandwiched” between them. More formally, if we think of each point p ∈ P as a vector
p~ ∈ Rd , the directional width can be formally defined to be
p · ~u) − min(~
WP (~u) = max(~ p · ~u)
p∈P p∈P
(see Fig. 135(a)). Note that this is a signed quantity, but we are typically interested only in
its magnitude.
P P
WP (~u) ~u WC (~u) ~u
(a) (b)
Fig. 135: Directional width and coresets. In (b) the points of C are shown as black points.
The directional width has a number of nice properties. For example, it is invariant under
translation and it scales linearly if P is uniformly scaled.
Quick-and-Dirty Construction: Let’s begin by considering a very simple, but not very efficient,
coreset for directional widths. We will apply the a utility lemma, which states that it is
possible to reduce the problem of computing a coreset for directional widths to one in which
the convex hull of the point set is “fat”.
Before giving the lemma, let us give a definition. Let B denote a d-dimensional unit ball, and
for any scalar λ > 0, let λB be a scaled copy of B by a factor λ. Given α ≤ 1, we say that a
convex body K in Rd is α-fat if there exist two positive scalars λ1 and λ2 , such that K lies
within a translate of λ2 B, K contains a translate of λ1 B, and λ1 /λ2 = α (see Fig. 136(a)).
Observe that any Euclidean ball √ is 1-fat. A line segment is 0-fat. It is easy to verify that a
d-dimensional hypercube is (1/ d)-fat. We say that a point set P is α-fat if its convex hull,
conv(P ), is α-fat (see Fig. 136(b)).
α = λλ1
K 2
λ2 λ2
λ1 P λ1
(a) (b)
Fig. 136: The definition of α-fatness for: (a) a convex body K and (b) for a point set P .
∈P (T T)−1w
~ ∈ TP
P TP w
~ ∈C ∈ TC
~u (T T)−1~u
~v
(T T)−1~v
(a) (b) (c) (d)
The resulting transformation will not generally preserve directional widths, but for our
purposes, it suffices that it preserves the ratios of directional widths. (More formally,
through basic linear algebra, we can show that for any unit vector ~u the ratio of the
widths two sets C and P along ~u is equal to the ratio of the widths of T C and T P
relative to the transformed direction (T T )−1 ~u (see Fig. 137(c)–(d)). We will omit the
simple proof.) The maximum ratio of directional widths (over all unit vectors ~u) is
therefore preserved, which implies that the coreset condition is also preserved.
To obtain the O(n) running time, it suffices to compute a constant factor approximation
to the John ellipsoid. Such a construction has been given by Barequet and Har-Peled.
Armed with the above lemma, we may proceed as follows to compute our quick-and-dirty
coreset. First, we assume that P has been fattened, by the above procedure. P is contained
within a unit ball B and that conv(P ) contains a translate of the shrunken ball αB. Because
P is sandwiched between αB and B, it follows that the width of P along any direction is at
least 2α and at most 2. Since no width is smaller than 2α, in order to achieve a relative error
of ε, it suffices to approximate any width to an absolute error of at most 2αε, which we will
denote by ε0 .
Let H = [−1, +1]d be a hypercube that contains B. Subdivide H into a grid of hypercubes
whose diameters are at most ε0 /2 (see Fig. 138(a)). Each edge of H will be subdivided into
O(1/ε0 ) = O(1/ε) intervals. Thus, the total number of hypercubes in the grid is O(1/εd ). For
each such hypercube, if it contains a point of P , add any one such point to C. The resulting
number of points of C cannot exceed the number of hypercubes, which is O(1/εd ).
∈P ∈P
∈C ∈C
(a) (b)
Fig. 138: The quick-and-dirty coreset construction: (a) of size O(1/εd ) and (b) the improved
construction of of size O(1/εd−1 ).
We can do this efficiently by hashing each point according to the index of the hypercube it
lies within. We retain one point from each nonempty hash bucket. This can be done in O(n)
time.
Improved Construction: It is possible make a small improvement in the size of the quick-and-
dirty coreset. Observe from Fig. 138(a) that we may select many points from the interior
of conv(P ), which clearly can play no useful role in the coreset construction. Rather than
partition H into small hypercubes, we can instead partition the upper (d − 1)-dimensional
facet of H into O(1/εd−1 ) cubes of diameter ε0 /2, and then extrude each into a “column”
that passes through H. For each column, take the highest and lowest point to add to C (see
Fig. 138(b)). We leave it as an easy geometric exercise to show that this set of points suffices.
Smarter Coreset Construction: The above coreset construction has the advantage of simplic-
ity, but, as shall see next, it is possible to construct much smaller coresets for directional
widths. We will reduce the size from O(1/εd−1 ) to O(1/ε(d−1)/2 ), thus reducing the exponen-
tial dependency by half.
Our general approach will be similar to the one taken above. First, we will assume that the
point set P has been “fattened” so that it lies within a unit ball, and its convex hull contains
a ball of radius at least α, where α ≤ 1 is a constant depending on dimension. As observed
earlier, since the width of P in any direction is at least 2α, in order to achieve a relative error
of ε, it suffices to compute a coreset whose absolute difference in width along any direction
is at most ε0 = 2αε.
S
∈Q
∈C
conv(P )
Fig. 139: Smarter coreset construction. (Technically, the points of Q are connected to the closest
point of P , not conv(P ).)
In the figure we have connected each point of Q to its closest point on conv(P ). It is a bit
easier to conceptualize the construction as sampling points from conv(P ). (Recall that the
coreset definition requires that the coreset is a subset of P .) There are a couple of aspects of
the construction that are noteworthy. First, observe that the construction tends to sample
points of P that lie close to regions where the curvature of P ’s convex hull is higher (see
Fig. 139). This is useful, because areas of high curvature need more points to approximate
them well. Also, because the points on S are chosen to be δ-dense on S, it can be shown that
they will be at least this dense on P ’s convex hull. Before presenting the proof of correctness,
we will prove a technical lemma.
Lemma 2: Let 0 < δ ≤ 1/2, and let q, q 0 ∈ Rd such that kqk ≥ 1 and kq 0 − qk ≤ δ (see
Fig. 140). Let B(q 0 ) be a ball centered at q 0 of radius kq 0 k. Let ~u be a unit length vector
17
This clever construction was discovered in the context of polytope approximation independently by E. M. Bron-
stein and L. D. Ivanov, “The approximation of convex sets by polyedra,” Siber. Math J., 16, 1976, 852–853 and
R. Dudley, “Metric entropy of some classes of sets with differentiable boundaries,” J. Appr. Th., 10, 1974, 227–236.
Proof: (Sketch) We will prove the lemma in R2 and leave the generalization to Rd as an
exercise. Let o denote the origin, and let ` = kqk be the distance from q to the origin.
Let us assume (through a suitable rotation) that ~u is aligned with the x-coordinate axis.
The quantity (p0 · ~u) is the length of the projection of p0 onto the x-axis, that is, it is just
the x-coordinate of p0 . We want to show that this coordinate cannot be smaller than
−δ 2 .
B(q 0) S
P
q 00
p0 q0 p0 q0
o ~u q p ~u q
δ δ
`≥1 `≥1
wδ ≤ δ 2 ≤ δ2
(a) (b)
We will prove a slightly stronger version of the above. In particular, let us assume that
q 0 is contained within a square of side length 2δ centered at q. This suffices because this
square contains all points that lie within distance δ of q. Observe that the boundary of
the ball B(q 0 ) passes through the origin. We wish to bound how far such a ball might
protrude over the (−x)-axis. Its easy to see that worst case arises when q 0 is placed in
the upper left corner of the square (see Fig. 140(a)). Call this point q 00 .
The distance between q 00 and the origin is (` − δ)2 + δ 2 . Therefore, the amount by
p
which the ball of radius kq 00 k centered at kq 00 k may protrude over the (−x)-axis is at
most p
(` − δ)2 + δ 2 − (` − δ)
which we will denote by wδ . Since p lies in this ball, to complete the proof it suffices to
show that wδ ≤ δ 2 .
To simplify
p this, let us multiply it by a fraction whose numerator
p and denominator are
both (` − δ)2 + δ 2 + (` − δ). It is easily verified that (` − δ)2 + δ 2 ≥ ` − δ. Using
this and the fact that ` ≥ δ, we have
To establish the correctness of the construction, consider any direction ~u. Let p ∈ P be
the point that maximizes (p · ~u). We will show that there is a point p0 ∈ C such that
(p · ~u) − (p0 · ~u) ≤ ε0 /2. In particular, let us translate the coordinate system so that p is at the
origin, and let us rotate space so that ~u is horizontal (see Fig. 140(b)). Let q be the point at
Range reporting: Return a list of all the points of P that lie within Q
Range counting: Return a count of all the points of P that lie within Q. There are a
number of variations.
Weights: Each point p ∈ P is associated with a numeric weight w(p). Return the sum
of weights of the points of P lying within Q
Semigroup weights: The weights need not be numbers and the operation need not be
addition. In general, the weights of P are drawn from any commutative semigroup.
A commutative semigroup is pair (Σ, ◦), where Σ is a set, and ◦ : Σ × Σ → Σ is a
commutative and associative binary operator on Σ. The objective is to return the
“sum” of the weights of the elements of P ∩ Q, where “◦” takes the role of addition.
For example, if we wanted to compute the maximum weight of a set of real values, we
could use the semigroup (R, max). If we wanted to know the parity of the number
of points of P in Q, we could take the semigroup ({0, 1}, ⊕), where ⊕ denotes
exclusive-or (or equivalently, addition modulo 2).
Group weights: A group is a special case of a semigroup, where inverses exist. (For
example, the semigroup of reals under addition (R, +) is a group (where subtraction
plays the role of inverse), but the semigroup (R, max) is not a group (since the max
operator does not have inverses).
If it is known that the semigroup is, in fact, a group, the data structure may take
advantage of this to speed-up query processing. For example, the query processing
algorithm has the flexibility to both “add” and “subtract” weights.
Approximation: Range searching in dimensions greater than two tends to have high com-
plexity (either with respect to storage or query time). One way to ameliorate these
Fig. 141: Canonical sets for interval queries. For range reporting, canonical subsets are generated
as needed by traversing the subtree.
We claim that the canonical subsets corresponding to any range can be identified in O(log n)
time from this structure. Given any interval [xlo , xhi ], we search the tree to find the rightmost
leaf u whose key is less than xlo and the leftmost leaf v whose key is greater than xhi . (To
make this possible for all ranges, we could add two sentinel points with values of −∞ and +∞
to form the leftmost and rightmost leaves.) Clearly all the leaves between u and v constitute
the points that lie within the range. To form these canonical subsets, we take the subsets of
all the maximal subtrees lying between the paths from the root u and v.
Here is how to compute these subtrees. The search paths to u and v may generally share
some common subpath, starting at the root of the tree. Once the paths diverge, as we follow
the left path to u, whenever the path goes to the left child of some node, we add the canonical
subset associated with its right child. Similarly, as we follow the right path to v, whenever
the path goes to the right child, we add the canonical subset associated with its left child.
As mentioned earlier, to answer a range reporting query we simply traverse the canonical
subtrees, reporting the points of their leaves. To answer a range counting query we return
the sum of weights associated with the nodes of the canonical subtrees.
Since the search paths to u and v are each of length O(log n), it follows that O(log n) canonical
subsets suffice to represent the answer to any query. Thus range counting queries can be
answered in O(log n) time. For reporting queries, since the leaves of each subtree can be
listed in time that is proportional to the number of leaves in the tree (a basic fact about
binary trees), it follows that the total time in the search is O((log n) + k), where k is the
number of points reported.
In summary, 1-dimensional range queries can be answered in O(log n) (counting) or ((log n) +
k) (reporting) time, using O(n) storage. This concept of finding maximal subtrees that are
contained within the range is fundamental to all range search data structures. The only
question is how to organize the tree and how to locate the desired sets. Let see next how can
we extend this to higher dimensional range queries.
Kd-trees: The natural question is how to extend 1-dimensional range searching to higher dimen-
sions. First we will consider kd-trees. This data structure is easy to implement and quite
p4 p9
p5 p10
p2
p8
p3 p6
p3 p4 p5 p8 p9 p10
p1 p7
p1 p2 p6 p7
The cutting process has a geometric interpretation. Each node of the tree is associated
implicitly with a rectangular region of space, called a cell. (In general these rectangles may
be unbounded, but in many applications it is common to restrict ourselves to some bounded
rectangular region of space before splitting begins, and so all these rectangles are bounded.)
The cells are nested in the sense that a child’s cell is contained within its parent’s cell. Hence,
these cells define a hierarchical decomposition of space. This is illustrated on the left side of
Fig. 142.
There are two key decisions in the design of the tree.
How is the cutting dimension chosen? The simplest method is to cycle through the di-
mensions one by one. (This method is shown in Fig. 142.) Since the cutting dimension
A kd-tree is a special case of a more general class of hierarchical spatial subdivisions, called
binary space partition trees (or BSP trees) in which the splitting lines (or hyperplanes in
general) may be oriented in any direction.
Constructing the kd-tree: It is possible to build a kd-tree in O(n log n) time by a simple top-
down recursive procedure. The most costly step of the process is determining the median
coordinate for splitting purposes. One way to do this is to maintain two lists of pointers to
the points, one sorted by x-coordinate and the other containing pointers to the points sorted
according to their y-coordinates. (In dimension d, d such arrays would be maintained.) Using
these two lists, it is an easy matter to find the median at each step in constant time. In linear
time it is possible to split each list about this median element.
For example, if x = s is the cutting value, then all points with px ≤ s go into one list and
those with px > s go into the other. (In dimension d this generally takes O(d) time per point.)
This leads to a recurrence of the form T (n) = 2T (n/2) + n, which solves to O(n log n). Since
there are n leaves and each internal node has two children, it follows that the number of
internal nodes is n − 1. Hence the total space requirements are O(n).
Theorem: Given n points, it is possible to build a kd-tree of height O(log n) and space O(n)
in time O(n log n) time.
Range Searching in kd-trees: Let us consider how to answer orthogonal range counting queries.
Range reporting queries are an easy extension. Let Q denote the desired range, and u denote
the current node in the kd-tree. We assume that each node u is associated with its rectangular
cell, denoted u.cell. (Alternately, this can be computed on the fly, as the algorithm is running.)
The search algorithm is presented in the code block below.
The search algorithm traverses the tree recursively. If it arrives at a leaf cell, we check to
see whether the associated point, u.point, lies within Q in O(1) time, and if so we count it.
Otherwise, u is an internal node. If u.cell is disjoint from Q (which can be tested in O(1) time
since both are rectangles), then we know that no point in the subtree rooted at u is in the
query range, and so there is nothing to count. If u.cell is entirely contained within Q (again
testable in O(1) time), then every point in the subtree rooted at u can be counted. (These
points constitute a canonical subset.) Otherwise, u’s cell partially overlaps Q. In this case
we recurse on u’s two children and update the count accordingly.
Fig. 143 shows an example of a range search. Blue shaded nodes contribute to the search
result and red shaded nodes do not. The red shaded subtrees are not visited. The blue-shaded
subtrees are not visited for the sake of counting queries. Instead, we just access their total
weight.
included
Q excluded
g h o q
f n p
b k
e m
a h
i j `
c d a e g m n p` q
b f k ` h ko m
c d i j
Fig. 143: Range search in a kd-tree. (Note: This particular tree was not generated by the algorithm
described above.)
Analysis of query time: How many nodes does this method visit altogether? We claim that the
√
total number of nodes is O( n) assuming a balanced kd-tree. Rather than counting visited
nodes, we will count nodes that are expanded. We say that a node is expanded if it is visited
and both its children are visited by the recursive range count algorithm.
A node is expanded if and only if the cell overlaps the range without being contained within
the range. We say that such a cell is stabbed by the query. To bound the total number of
nodes that are expanded in the search, it suffices to bound the number of nodes whose cells
are stabbed.
Lemma: Given a balanced kd-tree with n points using the alternating splitting rule, any
√
vertical or horizontal line stabs O( n) cells of the tree.
Proof: Let us consider the case of a vertical line x = x0 . The horizontal case is symmetrical.
Consider an expanded node which has a cutting dimension along x. The vertical line
x = x0 either stabs the left child or the right child but not both. If it fails to stab one
of the children, then it cannot stab any of the cells belonging to the descendents of this
child either. If the cutting dimension is along the y-axis (or generally any other axis in
higher dimensions), then the line x = x0 stabs both children’s cells.
We can solve this recurrence by appealing to the Master theorem for solving recurrences,
as presented in the book by Cormen, Leiserson, Rivest and Stein. To keep the lecture
self-contained, let’s solve it by repeated expansion.
n
T (n) ≤ 1 + 2T
4
n/4 n
≤ 1 + 2 1 + 2T = (1 + 2) + 4T
4 16
n/16 n
≤ (1 + 2) + 4 1 + 2T = (1 + 2 + 4) + 8T
4 64
≤ ...
k−1
X n
≤ 2i + 2k T .
4k
i=0
To get to the basis case (T (1)) let’s set k = log4 n, which means that 4k = n. Observe
√
that 2log4 n = 2(log2 n)/2 = n1/2 = n. Since T (1) ≤ 2, we have
√ √
T (n) ≤ (2log4 n − 1) + 2log4 n T (1) ≤ 3 n = O( n).
Theorem: Given a balanced kd-tree with n points, orthogonal range counting queries can
√ √
be answered in O( n) time and reporting queries can be answered in O( n + k) time.
The data structure uses space O(n).
Multi-level Search Trees: The orthogonal range-tree data structure is a nice example of a more
general concept, called a multi-level search tree. In this method, a complex search is decom-
posed into a constant number of simpler range searches. Recall that a range space is a pair
(X, R) consisting of a set X and a collection R of subsets of X, called ranges. Given a range
space (X, R), suppose that we can decompose it into two (or generally a small number of)
range subspaces (X, R1 ) and (X, R2 ) such that any query Q ∈ R can be expressed as Q1 ∩Q2 ,
for Qi ∈ Ri . (For example, an orthogonal range query in the plane, [xlo , xhi ]×[ylo , yhi ], can be
expressed as the intersection of a vertical strip and a horizontal strip, in particular, the points
whose x-coordinates are in the range Q1 = [xlo , xhi ] × R and the points whose y-coordinates
are in the range Q2 = R × [ylo , yhi ].) The idea is to then “cascade” a number of search
structures, one for each range subspace, together to answer a range query for the original
space.
Let’s see how to build such a structure for a given point set P . We first construct an appro-
priate range search structure, say, a partition tree, for P for the first range subspace (X, R1 ).
Let’s call this tree T (see Fig. 144). Recall that each node u ∈ T is implicitly associated
with a canonical subset of points of P , which we will denote by Pu . In the case that T is a
partition tree, this is just the set of points lying in the leaves of the subtree rooted at u. (For
example, in Fig. 144, Pu6 = {p5 , . . . , p8 }.) For each node u ∈ T , we construct an auxiliary
search tree for the points of Pu , but now over the second range subspace (X, R2 ). Let Tu
denote the resulting tree (see Fig. 144). The final data structure consists of the primary tree
T , the auxiliary search trees Tu for each u ∈ T , and a link from each node u ∈ T to the
corresponding auxiliary search tree Tu . The total space is the sum of space requirements for
the primary tree and all the auxiliary trees.
Now, given a query range Q = Q1 ∩ Q2 , where Qi ∈ Ri , we answer queries as follows. Recall
from our earlier lecture that,
S the partition tree T allows us to express the answer to the query
P ∩ Q1 as a disjoint union u Pu for an appropriate (and ideally small) subset of nodes u ∈ T .
Call this subset U (Q1 ). In order to complete the query, for each u ∈ U (Q1 ), we access the
corresponding auxiliary search tree Tu in order to determine the subset of points Pu that lie
within the query range Q2 . To see why this works, observe that
[ [
P ∩ Q = (P ∩ Q1 ) ∩ Q2 = Pu ∩ Q2 = Pu ∩ Q2 .
u∈U (Q1 ) u∈U (Q1 )
Therefore, once we have computed the answers to all the auxiliary ranges Pu ∩ Q2 for all
u ∈ U (Q1 ), all that remains is to combine the results (e.g., by summing the counts or
concatenating all the lists, depending on whether we are counting or reporting, respectively).
The query time is equal to the sum of the query times over all the trees that were accessed.
A Multi-Level Approach to Orthogonal Range Searching: Let us now consider how to ap-
ply the framework of a multi-level search tree to the problem of 2-dimensional orthogonal
range queries. First, we assume that we have preprocessed the data by building a range
tree for the first range query, which in this case is just a 1-dimensional range tree for the
x-coordinates. Recall that this is just a balanced binary tree T whose leaves are the points
of P sorted by x-coordinate. Each node u of this binary tree is implicitly associated with
a canonical subset Pu ⊆ P consisting of the points lying within the leaves in u’s subtree.
Next, for each node u ∈ T , we build a 1-dimensional range tree for Pu , sorted this time by
y-coordinates. The resulting tree is called Tu .
The final data structure, called a 2-dimensional range tree consists of two levels: an x-range
tree T , where each node u ∈ T points to auxiliary y-range search tree Tu . (For d-dimensional
range trees, we will have d-levels of trees, one for each coordinate.)
Queries are answered as follows. Consider an orthogonal range query Q = [xlo , xhi ] × [ylo , yhi ].
Let Q1 = [xlo , xhi ] × R and Q2 = R ×S[ylo , yhi ]. First, we query T to determine the subset
U (Q1 ) of O(log n) nodes u such that u∈U (Q1 ) Pu forms a disjoint cover of the points of P
whose x-coordinate lies within [xlo , xhi ]. (These are the roots of the shaded subtrees in the
top half of Fig. 145.) For each u ∈ U (Q1 ), we access the auxiliary tree Tu and perform a
1-dimensional range search (based on y-coordinates) to determine the subset of Pu that lies
within Q2 , that is, the points whose y-coordinates lie within [ylo , yhi ] (see Fig.145).
What is the query time? Recall that it takes O(log n) time to locate the nodes representing
the canonical subsets for the 1-dimensional range query over the x-coordinates, and there
Pu
xlo Pu xhi
are O(log n) nodes u ∈ U (Q1 ). For each such node, we invoke a 1-dimensional range search
over the y-coordinates on the canonical subset Pu , which will result in the generation of
O(log |Pu |) ≤ O(log n) canonical sets. Thus, (ignoring constant factors) the total number of
canonical subsets accessed by the algorithm is
X
log |Pu | ≤ |U (Q1 )| · log n ≤ log2 n.
u∈U (Q1 )
As before, listing the elements of these sets can be performed in additional O(k) time by
just traversing the subtrees corresponding to the canonical subsets of the auxiliary search
trees that contribute the final result. Counting queries can be answered by precomputing
the subtree sizes for each node of each auxiliary search tree, and just adding up all those
that contribute to the query. Therefore, reporting queries can be answered in O((log2 n) + k)
time and counting queries can be answered in O(log2 n) time. It is easy to see that we can
generalize this to orthogonal range searching in Rd by cascading d levels of 1-dimensional
search trees. The log factor in the resulting query time would be logd n.
Space and Preprocessing Time: To derive a bound on the total space used, we sum the sizes
of all the trees. The primary search tree T for the x-coordinates requires only O(n) storage.
For each node u ∈ T , the size of the auxiliary search tree Tu is clearly proportional to the
number of points in this tree, which is the size of the associated canonical subset, |Pu |. Thus,
up to constant factors, the total space is
X
n+ |Pu |.
u∈T
To bound the size of the sum, observe that each point of P appears in the set Pu for each
ancestor of this leaf. Since the tree T is balanced, its depth is O(log n), and therefore, each
point of P appears in O(log n) of the canonical subsets. Since each of the n points of P
contributes O(log n) to the sum, it follows that the sum is O(n log n).
In summary, the space required by the orthogonal range tree is O(n log n). Observe that
for the purposes of reporting, we could have represented each auxiliary search tree Tu as an
array containing the points of Pu sorted by the y-coordinates. The advantage of using a tree
Improved Query Times through Fractional Cascading: Can we improve on the O(log2 n)
query time? We would like to reduce the query time to O(log n). (In general, this approach
will shave a factor of log n from the query time, which will lead to a query time of O(logd−1 n)
in Rd ).
What is the source of the extra log factor? As we descend the search the x-interval tree,
for each node we visit, we need to search the corresponding auxiliary search tree based on
the query’s y-coordinates [ylo , yhi ]. It is this combination that leads to the squaring of the
logarithms. If we could search each auxiliary in O(1) time, then we could eliminate this
annoying log factor.
There is a clever trick that can be used to eliminate the additional log factor. Observe that
we are repeatedly searching different lists (in particular, these are subsets of the canonical
subsets Pu for u ∈ U (Q1 )) but always with the same search keys (in particular, ylo and yhi ).
How can we exploit the fact that the search keys are static to improve the running times of
the individual searches?
The idea to rely on economies of scale. SupposeSthat we merge all the different lists that we
need to search into a single master list. Since u Pu = P and |P | = n, we can search this
master list for any key in O(log n) time. We would like to exploit the idea that, if we know
where ylo and yhi lie within the master list, then it should be easy to determine where they
are located in any canonical subset Pu ⊆ P . Ideally, after making one search in the master
list, we would like to be able to answer all the remaining searches in O(1) time each. Turning
this intuition into an algorithm is not difficult, but it is not trivial either.
In our case, the master list on which we will do the initial search is the entire set of points,
sorted by y-coordinate. We will assume that each of the auxiliary search trees is a sorted
array. (In dimension d, this assumption implies that we can apply this only to the last level
of the multi-level data structure.) Call these the auxiliary lists.
Here is how we do this. Let v be an arbitrary internal node in the range tree of x-coordinates,
and let v 0 and v 00 be its left and right children. Let A be the sorted auxiliary list for v and
let A0 and A00 be the sorted auxiliary lists for its respective children. Observe that A is the
disjoint union of A0 and A00 (assuming no duplicate y-coordinates). For each element in A,
we store two pointers, one to the item of equal or larger value in A0 and the other to the item
of equal or larger value in A00 . (If there is no larger item, the pointer is null.) Observe that
once we know the position of an item in A, then we can determine its position in either A0 or
A00 in O(1) additional time.
v
v0 v 00 p6 v A 123456
p5
p4 p3 v 00 A00 1 3 6
v 0 A0 2 4 5
p2 p1
(a) (b)
At the root of the tree, we need to perform a binary search against all the y-values to
determine which points lie within this interval, for all subsequent levels, once we know where
the y-interval falls with respect to the order points here, we can drop down to the next level
in O(1) time. Thus, the running time is O(log n), rather than O(log 2 n). By applying this
to the last level of the auxiliary search structures, we save one log factor, which gives us the
following result.
Theorem: Given a set of n points in Rd , orthogonal rectangular range queries can be an-
swered in O(log(d−1) n + k) time, from a data structure of space O(n log(d−1) n) which
can be constructed in O(n log(d−1) n) time.
This technique is special case of a more general data structures technique called fractional
cascading. The idea is that information about the search the results “cascades” from one level
of the data structure down to the next.
The result can be applied to range counting queries as well, but under the provision that we
can answer the queries using a sorted array representation for the last level of the tree. For
example, if the weights are drawn from a group, then the method is applicable, but if the the
weights are from a general semigroup, it is not possible. (For general semigroups, we need to
sum the results for individual subtrees, which implies that we need a tree structure, rather
than a simple array structure.)
S
W
(a) (b)
Window Queries for Orthogonal Segments: We will present a data structure, called the in-
terval tree, which (combined with a range tree) can answer window counting queries for
orthogonal line segments in O(log2 n) time, where n is the number line segments. It can
report these segments in O(k + log2 n) time, where and k is the total number of segments
reported. The interval tree uses O(n log n) storage and can be built in O(n log n) time.
We will consider the case of range reporting queries. (There are some subtleties in making
this work for counting queries.) We will derive our solution in steps, starting with easier
subproblems and working up to the final solution. To begin with, observe that the set of
segments that intersect the window can be partitioned into three types: those that have no
endpoint in W , those that have one endpoint in W , and those that have two endpoints in W .
We already have a way to report segments of the second and third types. In particular, we
may build a range tree just for the 2n endpoints of the segments. We assume that each
endpoint has a cross-link indicating the line segment with which it is associated. Now, by
applying a range reporting query to W we can report all these endpoints, and follow the cross-
links to report the associated segments. Note that segments that have both endpoints in the
window will be reported twice, which is somewhat unpleasant. We could fix this either by
sorting the segments in some manner and removing duplicates, or by marking each segment
as it is reported and ignoring segments that have already been marked. (If we use marking,
after the query is finished we will need to go back an “unmark” all the reported segments in
preparation for the next query.)
All that remains is how to report the segments that have no endpoint inside the rectangular
window. We will do this by building two separate data structures, one for horizontal and
one for vertical segments. A horizontal segment that intersects the window but neither of its
endpoints intersects the window must pass entirely through the window. Observe that such
a segment intersects any vertical line passing from the top of the window to the bottom. In
particular, we could simply ask to report all horizontal segments that intersect the left side
of W . This is called a vertical segment stabbing query. In summary, it suffices to solve the
following subproblems (and remove duplicates):
Endpoint inside: Report all the segments of S that have at least one endpoint inside W .
We will present a solution to the problem of vertical segment stabbing queries. Before dealing
with this, we will first consider a somewhat simpler problem, and then modify this simple
solution to deal with the general problem.
Vertical Line Stabbing Queries: Let us consider how to answer the following query, which is
interesting in its own right. Suppose that we are given a collection of horizontal line segments
S in the plane and are given an (infinite) vertical query line `q : x = xq . We want to report
all the line segments of S that intersect `q (see Fig. 148(a)). Notice that for the purposes of
this query, the y-coordinates are really irrelevant, and may be ignored. We can think of each
horizontal line segment as being a closed interval along the x-axis.
x = xq x = xmed
d d M
f h f h
i i
c L c R
k l k l
b e m b e m
a g j n a g j n
0 5 10 15 20 25 30 0 5 10 15 20 25 30
Stabs: {b, c, d, e}
(a) (b)
Fig. 148: Line Stabbing Query. (We have organized the horizontal segments into groups according
to their y-coordinates, but the y-coordinates can be arbitrary.)
As is true for all our data structures, we want some balanced way to decompose the set of
intervals into subsets. Since it is difficult to define some notion of order on intervals, we instead
will order the endpoints. Sort the interval endpoints along the x-axis. Let hx1 , x2 , . . . , x2n i
be the resulting sorted sequence. Let xmed be the median of these 2n endpoints. Split the
intervals into three groups, L, those that lie strictly to the left of xmed , R those that lie strictly
to the right of xmed , and M those that contain the point xmed (see Fig. 148(b)). We can then
define a binary tree by putting the intervals of L in the left subtree and recursing, putting
the intervals of R in the right subtree and recursing. Note that if xq < xmed we can eliminate
the right subtree and if xq > xmed we can eliminate the left subtree.
But how do we handle the intervals of M that contain xmed ? We want to know which of these
intervals intersects the vertical line `q . At first it may seem that we have made no progress,
since it appears that we are back to the same problem that we started with. However, we
have gained the information that all these intervals intersect the vertical line x = xmed . How
can we use this to our advantage?
Let us suppose for now that xq ≤ xmed . How can we store the intervals of M to make it easier
to report those that intersect `q . The simple trick is to sort these lines in increasing order of
their left endpoint. Let ML denote the resulting sorted list. Observe that if some interval in
Interval Trees: The general structure of the interval tree was derived above. Each node of the
interval tree has a left child, right child, and itself contains the median x-value used to split
the set, xmed , and the two sorted sets ML and MR (represented either as arrays or as linked
lists) of intervals that overlap xmed . We assume that there is a constructor that builds a node
given these three entities. The following code block presents the basic recursive step in the
construction of the interval tree. The initial call is root = IntTree(S), where S is the initial
set of intervals. Unlike most of the data structures we have seen so far, this one is not built
by the successive insertion of intervals (although it would be possible to do so). Rather we
assume that a set of intervals S is given as part of the constructor, and the entire structure
is built all at once. We assume that each interval in S is represented as a pair (xlo , xhi ). See
Fig. 149(a)) for an example.
Interval tree construction
IntTreeNode IntTree(IntervalSet S) {
if (|S| == 0) return null // no more
We assert that the height of the tree is O(log n). To see this observe that there are 2n
endpoints. Each time through the recursion we split this into two subsets L and R of sizes
at most half the original size (minus the elements of M ). Thus after at most lg(2n) levels we
will reduce the set sizes to 1, after which the recursion bottoms out. Thus the height of the
tree is O(log n).
Implementing this constructor efficiently is a bit subtle. We need to compute the median of
the set of all endpoints, and we also need to sort intervals by left endpoint and right endpoint.
The fastest way to do this is to presort all these values and store them in three separate lists.
Then as the sets L, R, and M are computed, we simply copy items from these sorted lists to
the appropriate sorted lists, maintaining their order as we go. If we do so, it can be shown
that this procedure builds the entire tree in O(n log n) time.
The algorithm for answering a stabbing query was derived above. We present this algorithm
in the following code block. Let xq denote the x-coordinate of the query line.
Line Stabbing Queries for an Interval Tree
stab(IntTreeNode t, Scalar xq) {
if (t == null) return // fell out of tree
if (xq < t.xMed) { // left of median?
for (i = 0; i < t.ML.length; i++) { // traverse ML
if (t.ML[i].lo <= xq) print(t.ML[i])// ..report if in range
else break // ..else done
}
stab(t.left, xq) // recur on left
}
else { // right of median
for (i = 0; i < t.MR.length; i++) { // traverse MR
if (t.MR[i].hi >= xq) print(t.MR[i])// ..report if in range
else break // ..else done
}
stab(t.right, xq) // recur on right
}
}
This procedure actually has one small source of inefficiency, which was intentionally included
to make code look more symmetric. Can you spot it? Suppose that xq = t.xmed ? In this case
we will recursively search the right subtree. However this subtree contains only intervals that
are strictly to the right of xmed and so is a waste of effort. However it does not affect the
asymptotic running time.
As mentioned earlier, the time spent processing each node is O(1 + k 0 ) where k 0 is the total
number of points that were recorded at this node. Summing over all nodes, the total reporting
time is O(k+v), where k is the total number of intervals reported, and v is the total number of
nodes visited. Since at each node we recur on only one child or the other, the total number of
nodes visited v is O(log n), the height of the tree. Thus the total reporting time is O(k+log n).
Vertical Segment Stabbing Queries: Now let us return to the question that brought us here.
Given a set of horizontal line segments in the plane, we want to know how many of these
Observe that this is just an orthogonal range query. (It is easy to generalize the procedure
given last time to handle semi-infinite rectangles.) The case where q lies to the right of xmed
is symmetrical.
xmed
Fig. 150: The segments that stab q lie within the shaded semi-infinite rectangle.
So the solution is that rather than storing ML as a list sorted by the left endpoint, instead
we store the left endpoints in a 2-dimensional range tree (with cross-links to the associated
segments). Similarly, we create a range tree for the right endpoints and represent MR using
this structure.
The segment stabbing queries are answered exactly as above for line stabbing queries, except
that part that searches ML and MR (the for-loops) are replaced by searches to the appropriate
range tree, using the semi-infinite range given above.
We will not discuss construction time for the tree. (It can be done in O(n log n) time, but this
involves some thought as to how to build all the range trees efficiently). The space needed is
O(n log n), dominated primarily from the O(n log n) space needed for the range trees. The
query time is O(k + log3 n), since we need to answer O(log n) range queries and each takes
O(log2 n) time plus the time for reporting. If we use the spiffy version of range trees (which
we mentioned but never discussed) that can answer queries in O(k + log n) time, then we can
reduce the total time to O(k + log2 n).
It will make things simpler to think of the segments as being open (not including their end-
points). In this way, the pairwise disjoint segments might be the edges of a planar straight
line graph (PSLG). Indeed, one of the most important application of red-blue segment in-
tersection involves computing the overlay of two PSLG’s (one red and the other blue) This
is also called the map overlay problem, and is often used in geographic information systems.
The most time consuming part of the map overlay problem is determining which pairs of
segments overlap (see Fig. 151).
Fig. 151: Red-blue line segment intersection. The algorithm outputs the white intersection points
between segments of different colors. The segments of each color are pairwise disjoint (except
possibly at their endpoints).
Let N = n + m denote the total input size and let k denote the total number of bichromatic
intersecting pairs. We will present an algorithm for this problem that runs in O(k +N log2 N )
time for the reporting problem and O(N log2 N ) time for the counting problem. Both algo-
rithms use O(N log N ) space. Although we will not discuss it (but the original paper does) it
is possible to remove a factor of log n from both the running time and space, using a somewhat
more sophisticated variant of the algorithm that we will present.
Because the set of red segments are each pairwise disjoint as are the blue segments, it follows
that we could solve the reporting problem by our plane sweep algorithm for segment inter-
section (as discussed in an earlier lecture) in O((N + k) log N ) time and O(N ) space. Thus,
the more sophisticated algorithm is an improvement on this. However, plane sweep will not
allow us to solve the counting problem.
The Hereditary Segment Tree: Recall that we are given two sets B and R, consisting of, re-
spectively, m and n line segments in the plane, and let N = m + n. Let us make the general
Associated with s
u
Su
Iu
(a) (b)
Fig. 152: Hereditary Segment Tree: Intervals, slabs and the nodes associated with a segment.
We associate a segment s with a set of nodes of the tree. A segment is said to span interval
Iu if its projection covers this interval. We associate a segment s with a node u if s spans Iu
but s does not span Ip , where p is u’s parent (see Fig. 152(b)).
Each node (internal or leaf) of this tree is associated with a list, called the blue standard list,
Bu of all blue line segments whose vertical projection contains Iu but does not contain Ip ,
where p is the parent of u. Alternately, if we consider the nodes in whose standard list a
segment is stored, the intervals corresponding to these nodes constitute a disjoint cover of the
segment’s vertical projection. The node is also associated with a red standard list, denoted
Ru , which is defined analogously for the red segments. (See the figure below, left.)
a, b, c, d, e
a, b, c, d, e
a, e a, b, e b, c, d d, e
a, b c e b e b d d
b e b d d
a a
b e b e
c c
d d
(a) (b)
Fig. 153: Hereditary Segment Tree with standard lists (left) and hereditary lists (right).
Each node u is also associated with a list Bu∗ , called the blue hereditary list, which is the union
of the Bv for all proper descendents v or u. The red hereditary list Ru∗ is defined analogously.
(Even though a segment may occur in the standard list for many descendants, there is only
Time and Space Analysis: We claim that the total size of the hereditary segment tree is O(N log N ).
To see this observe that each segment is stored in the standard list of at most 2 log N nodes.
The argument is very similar to the analysis of the 1-dimensional range tree. If you locate the
left and right endpoints of the segment among the atomic intervals, these define two paths in
the tree. In the same manner as canonical sets for the 1-dimensional range tree, the segment
will be stored in all the “inner” nodes between these two paths (see Fig. 154). The segment
will also be stored in the hereditary lists for all the ancestors of these nodes. These ancestors
lie along the two paths to the left and right, and hence there are at most 2 log N of them.
Thus, each segment appears in at most 4 log N lists, for a total size of O(N log N ).
The tree can be built in O(N log N ) time. In O(N log N ) time we can sort the 2N segment
endpoints. Then for each segment, we search for its left and right endpoints and insert the
segment into the standard and hereditary lists for the appropriate nodes and we descend each
path in O(1) time for each node visited. Since each segment appears in O(log N ) lists, this
will take O(log N ) time per segment and O(N log N ) time overall.
Computing Intersections: Let us consider how to use the hereditaray segment tree to count and
report bichromatic intersections. We will do this on a node-by-node basis. Consider any node
u. We classify the intersections into two types, long-long intersections are those between a
segment of Bu and Ru , and long-short intersections are those between a segment of Bu∗ and
Ru or between Ru∗ and Bu . Later we will show that by considering just these intersection
cases, we will consider every intersection exactly once.
Long-long intersections: Our approach follows along the lines of the inversion counting
procedures we have seen earlier in the semester. First, sort each of the lists Bu and Ru
of long segments in ascending order by y-coordinate. (Since the segments of each set are
disjoint, this order is constant throughout the interval for each set.) Let hb1 , . . . , bmu i
The total time to do this is dominated by the O(mu log mu + nu log nu ) time needed to
sort both lists. The merging and counting only requires linear time.
Long-short intersections: There are two types of long-short intersections to consider.
Long red and short blue, and long blue and short red. Let us consider the first one,
since the other one is symmetrical.
As before, sort the long segments of Ru in ascending order according to y-coordinate,
letting hr1 , r2 , . . . , rnu i denote this ordered list. These segments naturally subdivide the
slab into nu + 1 trapezoids. For each short segment b ∈ Bu∗ , perform two binary searches
among the segments of Ru to find the lowest segment ri and the highest segment rj
that b intersects. (See the figure above, right.) Then b intersects all the red segments
ri , ri+1 , . . . , rj .
Thus, after O(log nu ) time for the binary searches, the segments of Ru intersecting b can
be counted in O(1) time, for a total time of O(m∗u log nu ). Reporting can be done in time
proportional to the number of intersections reported. Adding this to the time for the
long blue and short red case, we have a total time complexity of O(m∗u log nu +n∗u log mu ).
If we let Nu = mu + nu + m∗u + n∗u , then observe that the total time to process vertex
P u is
O(Nu log Nu ) time. Summing this over all nodes of the tree, and recalling that u Nu =
rj
ri
ri
b
ri−1
ri−1
Correctness: To show that the algorithm is correct, we assert that each bichromatic intersection
is counted exactly once. For any bichromatic intersection between bi and rj consider the
leaf associated with the atomic interval containing this intersection point. As we move up to
the ancestors of this leaf, we will encounter bi in the standard list of one of these ancestors,
denoted ui , and will encounter rj at some node, denoted uj . If ui = uj then this intersection
will be detected as a long-long intersection at this node. Otherwise, one is a proper ancestor
of the other, and this will be detected as a long-short intersection (with the ancestor long and
descendent short).
The union of the boundaries of the Voronoi polygons is called the Voronoi diagram of P ,
denoted V D(P ). The dual of the Voronoi diagram is a triangulation of the point set, called
the Delaunay triangulation. Recall from our discussion of quad-edge data structure, that
given a good representation of any planar graph, the dual is easy to construct. Hence, it
suffices to show how to compute either one of these structures, from which the other can be
derived easily in O(n) time.
There are a number of algorithms for computing Voronoi diagrams and Delaunay triangula-
tions in the plane. These include:
Divide-and-Conquer: (For both VD and DT.) The first O(n log n) algorithm for this prob-
lem. Not widely used because it is somewhat hard to implement. Can be generalized
to higher dimensions with some difficulty. Can be generalized to computing Voronoi
diagrams of line segments with some difficulty.
We will cover all of these approaches, except Fortune’s algorithm. O’Rourke does not give
detailed explanations of any of these algorithms, but he does discuss the idea behind For-
tune’s algorithm. Today we will discuss the divide-and-conquer algorithm. This algorithm is
presented in Mulmuley, Section 2.8.4.
The union of these bisectors that separate the left Voronoi diagram from the right Voronoi
diagram is called the contour. A point is on the contour if and only if it is equidistant from
two points in S, one in L and one in R.
Assuming we can implement step (3) in O(n) time (where n is the size of the remaining point
set) then the running time will be defined by the familiar recurrence
T (n) = 2T (n/2) + n,
Computing the contour: What makes the divide-and-conquer algorithm somewhat tricky is the
task of computing the contour. Before giving an algorithm to compute the contour, let us
make some observations about its geomtetric structure. Let us make the usual simplifying
assumptions that no four points are cocircular.
Lemma: The contour consists of a single polygonal curve (whose first and last edges are
semi-infinite) which is monotone with respect to the y-axis.
Proof: A detailed proof is a real hassle. Here are the main ideas, though. The contour sepa-
rates the plane into two regions, those points whose nearest neighbor lies in L from those
points whose nearest neighbor lies in R. Because the contour locally consists of points
that are equidistant from two points, it is formed from pieces that are perpendicular
bisectors, with one point from L and the other point from R. Thus, it is a piecewise
polygonal curve. Because no four points are cocircular, it follows that all vertices in the
Voronoi diagram can have degree at most three. However, because the contour separates
the plane into only two types of regions, it can contain only vertices of degree two. Thus
it can consist only of the disjoint union of closed curves (actually this never happens, as
we will see) and unbounded curves. Observe that if we orient the contour counterclock-
wise with respect to each point in R (clockwise with respect to each point in L), then
each segment must be directed in the −y directions, because L and R are separated by
a vertical line. Thus, the contour contains no horizontal cusps. This implies that the
contour cannot contain any closed curves, and hence contains only vertically monotone
unbounded curves. Also, this orientability also implies that there is only one such curve.
Lemma: The topmost (bottommost) edge of the contour is the perpendicular bisector for
the two points forming the upper (lower) tangent of the left hull and the right hull.
Proof: This follows from the fact that the vertices of the hull correspond to unbounded
Voronoi polygons, and hence upper and lower tangents correspond to unbounded edges
of the contour.
These last two theorem suggest the general approach. We start by computing the upper
tangent, which we know can be done in linear time (once we know the left and right hulls, or
by prune and search). Then, we start tracing the contour from top to bottom. When we are
in Voronoi polygons V (l0 ) and V (r0 ) we trace the bisector between l0 and r0 in the negative
y-direction until its first contact with the boundaries of one of these polygons. Suppose that
We have to avoid this repeated rescanning. However, there is a way to scan the boundary of
each Voronoi polygon at most once. Observe that as we walk along the contour, each time we
stay in the same polygon V (l0 ), we are adding another edge onto its Voronoi polygon. Because
the Voronoi polygon is convex, we know that the edges we are creating turn consistently in the
same direction (clockwise for points on the left, and counterclockwise for points on the right).
To test for intersections between the contour and the current Voronoi polygon, we trace the
boundary of the polygon clockwise for polygons on the left side, and counterclockwise for
polygons on the right side. Whenever the contour changes direction, we continue the scan
from the point that we left off. In this way, we know that we will never need to rescan the
same edge of any Voronoi polygon more than once.
(a) (b)
Fig. 159: Ham sandwich cuts (a) general and (b) linearly-separable.
assume that the two sets can be separated by a line (see Fig. 159(b)). We may assume that
the points have been translated and rotated so the separating line is the y-axis. Thus all the
red points (set A) have positive x-coordinates, and all the blue points (set B) have negative
x-coordinates. As long as we are simplifying things, let’s make one last simplification, that
both sets have an odd number of points. This is not difficult to get around, but makes the
pictures a little easier to understand.
Ham-Sandwich Cuts in the Dual: Consider one of the sets, say A. Observe that for each slope
there exists one way to bisect the points. In particular, if we start a line with this slope at
positive infinity, so that all the points lie beneath it, and drop in downwards, eventually we
will arrive at a unique placement where there are exactly (n − 1)/2 points above the line, one
point lying on the line, and (n − 1)/2 points below the line (assuming no two points share
this slope). This line is called the median line for this slope.
What is the dual of this median line? Suppose that we dualize the points using the standard
dual transformation, where a point p = (pa , pb ) is mapped to the line p∗ : y = pa x − pb .
We obtain n lines in the plane. By starting a line with a given slope above the points and
translating it downwards, in the dual plane we moving a point from −∞ upwards in a vertical
line. Each time the line passes a point in the primal plane, the vertically moving point crosses
a line in the dual plane. When the translating line hits the median point (see Fig. 160(a)),
in the dual plane the moving point will hit a dual line such that there are exactly (n − 1)/2
dual lines above this point and (n − 1)/2 dual lines below this point (see Fig. 160(b)). We
define a point to be at level k, Lk , in an arrangement if there are at most k − 1 lines above
this point and at most n − k lines below this point. The median level in an arrangement of
n lines is defined to be the d(n − 1)/2e-th level in the arrangement (see Fig. 160(c)).
`∗
(a) (b) (b)
Fig. 160: The (a) median line, (b) median point, and (c) median level.
Thus, the set of bisecting lines for set A in dual form consists of a polygonal curve. Be-
cause all the points of A have positive x-coordinates, their dual lines have positive slopes (see
Computing the Ham-Sandwich Cut by Prune and Search: We could compute the inter-
section of these two curves in O(n2 ) time by a simultaneous topological plane sweep of both
arrangements (even if the points were not linearly separable). However because of linear sep-
arability, it is possible to do much better, and in fact the problem can be solved in O(n + m)
time. Since the algorithm is rather complicated, I will not describe the details, but here
are the essential ideas. The algorithm operates by prune and search. In O(n + m) time we
will generate a hypothesis for where the ham sandwich point is in the dual plane, and if
we are wrong, we will succeed in throwing away a constant fraction of the lines from future
consideration.
First observe that for any vertical line in the dual plane, it is possible to determine in O(n+m)
time whether this line lies to the left or the right of the intersection point of the median levels,
M (A) and M (B). This can be done by computing the intersection of the dual lines of A with
this line, and computing their median in O(n) time, and computing the intersection of the
dual lines of B with this line and computing their median in O(m) time. If A’s median lies
below B’s median, then we are to the left of the ham sandwich dual point, and otherwise we
are to the right of the ham sandwich dual point. It turns out that with a little more work, it
is possible to determine in O(n + m) time whether the ham sandwich point lies to the right or
left of a line of arbitrary slope. The trick is to use prune and search. We find two lines L1 and
L2 in the dual plane (by a careful procedure that I will not describe). These two lines define
four quadrants in the plane. By determining which side of each line the ham sandwich point
lies, we know that we can throw away any line that does not intersect this quadrant from
further consideration. It turns out that by a judicious choice of L1 and L2 , we can guarantee
that a fraction of at least (n + m)/8 lines can be thrown away by this process. We recurse
on the remaining lines. By the same sort of analysis we made in the Kirkpatrick and Seidel
prune and search algorithm for upper tangents, it follows that in O(n + m) time we will find
the ham sandwich point.
Faces: The boundary of a polyhedron in 3-space is bounded by vertices, edges, and faces. To
generalize this to higher dimensions, let us first introduce a few definitions. Any (d − 1)-
dimensional hyperplane h in d-dimensional space divides the space into (open) halfspaces,
denoted h− and h+ , so that Rd = h− ∪ h ∪ h+ . Let us define h− = h− ∪ h and h+ = h+ ∪ h
to be the closures of these halfspaces. We say that a hyperplane supports a polytope P (and
is called a supporting hyperplane of P ) if h ∩ P is nonempty and P is entirely contained
within either h− or h+ (see Fig. 162). The intersection of the polytope and any supporting
hyerplane is called a face of P . Faces are themselves convex polytopes of dimensions ranging
from 0 to d − 1. The 0-dimensional faces are called vertices, the 1-dimensional faces are called
edges, and the (d − 1)-dimensional faces are called facets. (Note: When discussing polytopes
in dimension 3, people often use the term “face” when they mean “facet”. It is usually clear
from context which meaning is intended.)
a Vertices: a, b, c, d
d Edges: ab, ac, ad, bc, bd, cd
b
Faces: abc, abd, acd, bcd
c
The faces of dimensions 0 to d − 1 are called proper faces (see Fig. 163). It will be convenient
to define two additional faces. The empty set is said to be a face of dimension −1 and the
entire polytope is said to be a face of dimension d. We will refer to all the faces, including
these two additional faces as the improper faces of the polytope.
There are a number of facts that follow from these definitions.
Incidence Graph: How can we represent the boundary structure of a polytope? In addition to
the geometric properties of the polytope (e.g., the coordinates of its vertices or the equation
of its faces) it is useful to store discrete connectivity information, which is often referred to as
the topology of the polytope. There are many representations for polytopes. In dimension 2,
a simple circular list of vertices suffices. In dimension 3, we need some sort of graph structure.
There are many data structures that have been proposed. They are evaluated based on the
ease with which the polytope can be traversed and the amount of storage needed. (Examples
include the DCEL, winged-edge, quad-edge, and half-edge data structures.)
A useful structure for polytopes in arbitrary dimensions is called the incidence graph. Each
node of the incidence graph corresponds to an (improper) face of the polytope. We create
an edge between two faces if their dimension differs by 1, and one (of lower dimension) is
contained within the other (of higher dimension). An example is shown in Fig. 164 for a
tetrahedron. Note the similarity between this graph and the lattice of subsets based on
inclusion relation.
∅
a b c d
a
d ac
b ab ad bc bd cd
c
abc abd acd bcd
abcd
Polarity: There are two natural ways to create polytopes. One is as the convex hull of a set of
points and the other is as the intersection of a collection of closed halfspaces (assuming it is
bounded). As we shall see, these two concepts are essentially identical, and they are connected
incidence preserving
Polar transformation h∗
p
h p∗
1/c O O
p∗
c
p inclusion reversing h∗
O
p h+ p∗−
O O
(a) (b)
Clearly, the polar transformation is an involution, that is, (p∗ )∗ = p and (h∗ )∗ = h. The polar
transformation preserves important geometric relationships. Given a hyperplane h, define
That is, h+ is the open halfspace containing the origin and h− is the other open halfspace for
h.
Claim: Let p be any point in Rd and let h be any hyperplane in Rd . The polar transformation
satisfies the following two properties.
Incidence preserving: The polarity transformation preserves incidence relationships
between points and hyperplanes. That is, p belongs to h if and only if h∗ belongs
to p∗ (see Fig. 165(b)).
Inclusion Reversing: The polarity transformation reverses relative position relation-
ships in the sense that p belongs to h+ if and only if h∗ belongs to (p∗ )− , and p
belongs to h− if and only if h∗ belongs to (p∗ )+ (see Fig. 165(b)).
Lemma: Let S = {p1 , . . . , pn } be a set of points in Rd and let P = conv (S). Then its polar
image is the intersection of the corresponding polar halfspaces, that is,
n
\
P# = p∗+
i .
i=1
Furthermore:
(a) (b)
(i) A point a ∈ Rd lies on the boundary of P if and only if the polar hyperplane a∗
supports P # .
(ii) Each k-face of P corresponds to a (d − 1 − k)-face of P # and given faces f1 , f2 of
P where f1 ⊆ f2 , the corresponding faces f1# , f2# of P # satisfy f1# ⊇ f2# . (That is,
inclusion relations are reversed.)
It is not hard to prove that the polar image of a polytope is an involution, that is (P # )# = P .
(See Boissonnat and Yvinec for proofs of all these facts.)
Thus, the polar image P # of a polytope is structurally isomorphic to P and all affine relations
on P map through polarity to P # . From a computational perspective, this means that we
compute the polar of all the points of P , consider the halfspaces that contain the origin, and
take the intersection of these halfspaces. Thus, the problems of computing convex hulls and
computing the intersection of halfspaces are computationally equivalent. (In fact, once you
have computed the incidence graph for one, you just flip it “upside-down” to get the other!)
Simple and Simplicial Polytopes: Our next objective is to investigate the relationship between
the number of vertices and number of facets on a convex polytope. Earlier in the semester
we saw that a 3-dimensional polyhedron with n vertices has O(n) edges and faces. This was
a consequence of Euler’s formula. In order to investigate the generalization of this to higher
dimensions, we begin with some definitions. A polytope is simplicial if all its proper faces
are simplices (see Fig. 167(a)). Observe that if a polytope is the convex hull of a set of points
in general position, then for 0 ≤ j ≤ d − 1, each j-face is a j-simplex. (For example, in R3 a
face with four vertices would imply that these four points are coplanar, which would violate
general position.)
(a) (b)
If we take a dual view, consider a polytope that is the intersection of a set of n halfspaces
in general position. Then each j-face is the intersection of exactly (d − j) hyperplanes. A
These naive bounds are not tight. Tight bounds can be derived using more sophisticated
relations on the numbers of faces of various dimensions, called the Dehn-Sommerville relations.
We will not cover these, but see the discussion below of the Upper Bound Theorem.
This says that the alternating sum of the numbers of faces sums to 0. For example, a cube
has 8 vertices, 12 edges, 6 facets, and together with the faces of dimension −1 and d we have
−1 + 8 − 12 + 6 − 1 = 0.
Although the formal proof of Euler’s relation is rather complex, there is a very easy way to
see why its true. First, consider the simplest polytope, namely a d-simplex, as the base case.
The Upper Bound Theorem: A polytope defined by the convex hull of n points in Rd
has O(nbd/2c ) facets.
Upper Bound Theorem (Polar Form): A polytope defined by the intersection of n half-
spaces in Rd has O(nbd/2c ) vertices.
Proof: It is not hard to show that among all polytopes, simplicial polytopes maximize the
number of faces for a given set of vertices and simple polytopes maximize the number of
vertices for a given set of faces. We will prove just the polar form of the theorem, and
the other will follow by polar equivalence.
Consider a polytope defined by the intersection of n halfspaces in general position. Let
us suppose by convention that the xd axis is the vertical axis. Given a face, its highest
vertex and lowest vertices are defined as those having the maximum and minimum xd
coordinates, respectively. (There are no ties if we assume general position.)
The proof is based on a charging argument. We will place a charge at each vertex. We
will then move the charge at each vertex to a specially chosen incident face, in such a
way that no face receives more than two charges. Finally, we will show that the number
of faces that receive charges is at most O(nbd/2c ).
First, we claim that every vertex v is either the highest or lowest vertex for a j-face,
where j ≥ dd/2e. To see this, recall that the for a simple polytope, the neighborhood
immediately surrounding any vertex is isomorphic to a simplex. Thus, v is incident to
exactly d edges (1-faces). (See Fig. 168 for an example in R5 .) Consider a horizontal
(that is, orthogonal to xd ) hyperplane passing through v. Since there are d edges in all,
at least dd/2e of these edges must lie on the same side of this hyperplane. (By general
position we may assume that no edge lies exactly on the hyperplane.)
Since the local neighborhood about v is a simplex, there is a face of dimension at least
dd/2e that spans these edges and is incident to v (this is the 3-face lying above v in
Fig. 168). Therefore, v is either the lowest or highest vertex for this face. We assess
v’s charge to this face. Thus, we may charge every vertex of the polytope to face of
dimension at least dd/2e, and every such face will be charged at most twice (once by its
lowest and once by its highest vertex).
All that remains is to count the number of faces that have been charged and multiply by
2. Recalling our earlier lemma on the naive bound on the number of j-faces of a simple
n
polytope with n facets is d−j . (Each j-face is arises from the intersection of d − j
hyperplanes and this is number of (d − j)-element subsets of hyerplanes.) Summing this
up over all the faces of dimension dd/2e and higher we find that the number of vertices
Fig. 168: Proof of the Upper Bound Theorem in R5 . In this case the three edges above v span a
3-face whose lowest vertex is v.
is at most
d
X n
2 .
d−j
j=dd/2e
n
By changing the summation index to k = d − j and making the observation that k is
O(nk ), we have that the number of vertices is at most
bd/2c bd/2c
X n X
2 = O(nk ).
k
k=0 k=0
This is a geometric series, and so is dominated asymptotically by its largest term. There-
fore it follows that the number of charges, that is, the number of vertices is at most
O nbd/2c ,
Is this bound tight? Yes it is. There is a family of polytopes, called cyclic polytopes, which
match this asymptotic bound. (See Boissonnat and Yvinec for a definition and proof.)
edge
face
(a) (b)
these holes may themselves contain holes). A subdivision is called a convex subdivision if all
the faces (except the outer one) are convex (see Fig. 169(b)).
Simple Polygons: Now, let us change directions, and consider some interesting problems involv-
ing polygons in the plane. We begin study of the problem of triangulating polygons. We
introduce this problem by way of a cute example in the field of combinatorial geometry.
We begin with some definitions. A polygonal curve is a finite sequence of line segments, called
edges joined end-to-end (see Fig. 170). The endpoints of the edges are vertices. For example,
let v0 , . . . , vn denote the set of n + 1 vertices, and let e1 , . . . , en denote a sequence of n edges,
where ei = vi−1 vi . A polygonal curve is closed if the last endpoint equals the first v0 = vn .
A polygonal curve is simple if it is not self-intersecting. More precisely this means that each
edge ei does not intersect any other edge, except for the endpoints it shares with its adjacent
edges.
polygonal curve simple closed (not simple) simple polygon
The famous Jordan curve theorem states that every simple closed plane curve divides the plane
into two regions (the interior and the exterior ). (Although the theorem seems intuitively
obvious, it is quite difficult to prove.) We define a simple polygon (or just polygon) to be the
region of the plane bounded by a simple, closed polygonal curve. We will assume that the
vertices are listed in counterclockwise order around the boundary of the polygon.
Art Gallery Problem: We say that two points x and y in a simple polygon can see each other
(or x and y are visible) if the open line segment xy lies entirely within the interior of P . (Note
that such a line segment can start and end on the boundary of the polygon, but it cannot
pass through any vertices or edges.)
If we think of a polygon as the floor plan of an art gallery, consider the problem of where
to place “guards”, and how many guards to place, so that every point of the gallery can be
seen by some guard. Such a set is called a guarding set (see Fig. 171(a)). Victor Klee posed
(a) (b)
Before getting into a solution, let’s consider some basic facts. Could there be polygons for
which no finite number of guards suffice? It turns out that the answer is no, but the proof is
not immediately obvious. You might consider placing a guard at each of the vertices. Such
a set of guards will suffice in the plane. But to show how counter-intuitive geometry can be,
it is interesting to not that there are simple nonconvex polyhedra in 3-space, such that even
if you place a guard at every vertex there would still be points in the polygon that are not
visible to any guard. (As a challenge, try to come up with one with the fewest number of
vertices.)
An interesting question in combinatorial geometry is how does the number of guards needed
to guard any simple polygon with n sides grow as a function of n? If you play around
with the problem for a while (trying polygons with n = 3, 4, 5, 6 . . . sides, for example) you
will eventually come to the conclusion that bn/3c is the right value. Fig. 171(b)) shows
that this bound is tight. Observe given such a polygon of this form with k “teeth”, the
number of vertices is n = 3k, and each guard can see into only one tooth. A cute result
from combinatorial geometry is that this number always suffices. The proof is based on three
concepts: polygon triangulation, dual graphs, and graph coloring. The remarkably clever and
simple proof was discovered by Fisk.
Theorem: (The Art-Gallery Theorem) Given a simple polygon with n vertices, there exists
a guarding set with at most bn/3c guards.
Before giving the proof, we explore some aspects of polygon triangulations. We begin by
introducing a triangulation of P . A triangulation of a simple polygon is a planar subdivision
of (the interior of) P whose vertices are the vertices of P and whose faces are all triangles (see
Fig. 172(a)). An important concept in polygon triangulation is the notion of a diagonal, that
is, a line segment between two vertices of P that are visible to one another. A triangulation
can be viewed as the union of the edges of P and a maximal set of non-crossing diagonals.
Lemma: Every simple polygon with n vertices has a triangulation consisting of n − 3 diag-
onals and n − 2 triangles.
Fig. 172: (a) A polygon triangulation, (b) the dual tree (with ears shaded), and (c) the resulting
3-coloring.
We will leave the details as an exercise, but here is a quick sketch of the proof. We start with
the observation that given any n-vertex polygon, with n ≥ 4 it has at least one diagonal.
(This may seem utterly trivial, but actually takes a little bit of work to prove. In fact it fails
to hold for polyhedra in 3-space.) The addition of the diagonal breaks the polygon into two
polygons, of say m1 and m2 vertices, such that m1 + m2 = n + 2 (since both share the vertices
of the diagonal). Thus by induction, there are (m1 − 2) + (m2 − 2) = n + 2 − 4 = n − 2
triangles total. A similar argument holds to determine the number of of diagonals.
It is a well known fact from graph theory that any planar graph can be colored with four
colors. (The famous four-color theorem.) This means that we can assign a color to each of
the vertices of the graph, from a collection of four different colors, so that no two adjacent
vertices have the same color. However we can do even better for the graph we have just
described.
Proof: (of the Art-Gallery Theorem:) Consider any 3-coloring of the vertices of the polygon.
At least one color occurs at most bn/3c time. (Otherwise we immediately get there are
Work Space and Configuration Space: The environment in which the robot operates is called
its work space, which consists of a set of obstacles that the robot is not allowed to intersect.
We assume that the work space is static, that is, the obstacles do not move. We also assume
that a complete geometric description of the work space is available to us.
For our purposes, a robot will be modeled by two main elements. The first is a configuration,
which is a finite sequence of values that fully specifies the position of the robot. The sec-
ond element is the robot’s geometric shape description (relative to some default placement).
Combined, these two elements fully define the robot’s exact position and shape in space.
For example, suppose that the robot is a triangle that can translate and rotate in the plane
(see Fig. 173). Its configuration may be described by the (x, y) coordinates of some reference
point for the robot, and an angle θ that describes its orientation. Its geometric information
would include its shape (say at some canonical position), given, say, as a simple polygon.
Given its geometric description and a configuration (x, y, θ), this uniquely determines the
exact position R(x, y, θ) of this robot in the plane. Thus, the position of the robot can be
identified with a point in the robot’s configuration space.
R(2, 3, 45◦)
R(0, 0, 0)
A more complex example would be an articulated arm consisting of a set of links, connected
to one another by a set of rotating joints. The configuration of such a robot might consist
of a vector of joint angles. The geometric description would probably consist of a geometric
representation of the links. Given a sequence of joint angles, the exact shape of the robot could
be derived by combining this configuration information with its geometric description. For
example, a typical 3-dimensional industrial robot has six joints, and hence its configuration
can be thought of as a point in a 6-dimensional space. Why six? Generally, there are three
degrees of freedom needed to specify a location the (x, y, z) coordinates of its location in
(a) (b)
The problem of computing a collision-free path for the robot can be reduced to computing
a path in the robot’s configuration space. To distinguish between these, we use the term
work space to denote the (standard Euclidean) space where the robot and obstacles reside
(see Fig. 174(a)), and the configuration space to denote to the space in which each point
corresponds to the robot’s configuration (see Fig. 174(b)). Planning the motion of the robot
reduces to computing a path in configuration space.
A configuration that results in the robot to intersecting with one or more of the obstacles is
called a forbidden configuration. The set of all forbidden configurations is denoted Cforb (R, S).
All other placements are called free configurations, and the set of these configurations is
denoted Cfree (R, S), or free space.
Now consider the motion planning problem in robotics. Given a robot R, an work space S, and
initial configuration s and final configuration t (both points in the robot’s free configuration
space), determine (if possible) a way to move the robot from one configuration to the other
without intersecting any of the obstacles. This reduces to the problem of determining whether
there is a path from s to t that lies entirely within the robot’s free configuration space. Thus,
we map the task of computing a robot’s motion to the problem of finding a path for a single
point through a collection of obstacles.
Configuration spaces are typically higher dimensional spaces, and can be bounded by curved
surfaces (especially when rotational elements are involved). Perhaps the simplest case to
visualize is that of translating a convex polygonal robot in the plane amidst a collection
of polygonal obstacles. In this cased both the work space and configuration space are two
dimensional. Consider a reference point placed in the center of the robot. The process of
mapping to configuration space involves replacing the robot with a single point (its reference
point) and “growing” the obstacles by a compensating amount. These grown obstacles are
called configuration obstacles (or C-obstacles for short). See Fig. 174(b).
This approach while very general, ignores many important practical issues. It assumes that
we have complete knowledge of the robot’s environment and have perfect knowledge and
control of its placement. As stated we place no requirements on the nature of the path, but
Planning the Motion of a Point Robot: As mentioned above, we can reduce complex motion
planning problems to the problem of planning the motion of a point in free configuration
space. First we will consider the question of how to plan the motion of a point amidst a set
of obstacles, and then we will consider the question of how to construct configuration spaces.
Let us start with a very simple case in which the configuration space is 2-dimensional and the
objects are simple polygons, possibly with holes (see Fig. 175(a)). To determine whether there
is a path from one point s to another point t of free configuration space, we can subdivide
free space into simple convex regions. In the plane, we already know of one way to do this by
computing a trapezoidal map. We construct a trapezoidal map for all of the line segments
bounding the obstacles, then throw away any trapezoids that lie in the forbidden space (see
Fig. 175(b)). We also assume that we have a point location data structure for the trapezoidal
map.
s s
t t
(a) (b)
Next, we create a planar graph, called a road map, based on this subdivision. To do this we
create a vertex in the center of each trapezoid and a vertex at the midpoint of each vertical
edge. We create edges joining each center vertex to the vertices on its (at most four) edges.
Now to answer the motion planning problem, we assume we are given the start point s and
destination point t. We locate the trapezoids containing these two points, and connect them
to the corresponding center vertices. We can join them by a straight line segment, because
the cells of the subdivision are convex. Then we determine whether there is a path in the
road map graph between these two vertices, say by breadth-first search. Note that this will
not necessarily produce the shortest path, but if there is a path from one position to the
other, it will find it.
C(P )
P ⊕Q
P
P p
p+q
q
Q
R
(a) (b)
Given R and P , how do we compute the configuration obstacle C(P )? To do this, we first
introduce the notion of a Minkowski sum. Let us think of points in the plane as vectors.
Given any two sets P and Q in the plane, define their Minkowski sum to be the set of all
pairwise sums of points taken from each set (see Fig. 176(b)), that is,
P ⊕ Q = {p + q : p ∈ P, q ∈ Q}.
Also, define −S = {−p : p ∈ S}. (In in the plane −S is just the 360◦ rotation of S about the
origin, but this does not hold in higher dimensions.) We introduce the shorthand notation
R ⊕ p to denote R ⊕ {p}. Observe that the translate of R by vector p is R(p) = R ⊕ p. The
relevance of Minkowski sums to C-obstacles is given in the following claim.
C(P ) P ⊕ (−R)
P p P p
q q
r R
−R
R −r
(a) (b)
It is an easy matter to compute −R in linear time (by simply negating all of its vertices) the
problem of computing the C-obstacle C(P ) reduces to the problem of computing a Minkowski
sum of two convex polygons. We’ll show next that this can be done in O(m + n) time, where
m is the number of vertices in R and n is the number of vertices in P .
Note that the above proof made no use of the convexity of R or P . It works for any shapes
and in any dimension. However, computation of the Minkowski sums is most efficient for
convex polygons.
Computing the Minkowski Sum of Convex Polygons: Let’s consider how to compute P ⊕R
for two convex polygons P and R, having m and n vertices, respectively. The algorithm is
based on the following observation. Given a vector u, We say that a point p is extreme in
direction u if it maximizes the dot product p · u (equivalently, a support line perpendicular to
u passes through p with the outward normal u). The following observation is easy to prove
by the linearity of the dot product.
Observation: Given two polygons P and R, the set of extreme points of P ⊕ R in direction
u is the set of sums of points p and r that are extreme in direction u for P and R,
respectively.
then these edges will be combined into one edge, which is as long as their sum.) Thus we
have the following.
Claim: Given two convex polygons, P and R, with n and m edges respectively, their Min-
kowski sum P ⊕ R can be computed in O(n + m) time, and consist of at most n + m
edges.
Complexity of Minkowski Sums: We have shown that free space for a translating robot is the
complement of a union of C-obstacles C(P )i , each of which is a Minkowski sum of the form
Pi ⊕ R, where Pi ranges over all the obstacles in the environment. If Pi and R are polygons,
then the resulting region will be a union of polygons. How complex might this union be, that
is, how many edges and vertices might it have?
To begin with, let’s see just how bad things might be. Suppose you are given a robot R
with m sides and a set of work-space obstacle P with n sides. How many sides might the
Minkowski sum P ⊕R have in the worst case? O(n+m)? O(nm), even more? The complexity
generally depends on what special properties if any P and R have.
Nonconvex Robot and Nonconvex Obstacles: Suppose that both R and P are (possibly non-
convex) simple polygons. Let m be the number of sides of R and n be the number of sides of
P . How many sides might there be in the Minkowski sum P ⊕ R in the worst case? We can
derive a quick upper bound as follows. First observe that if we triangulate P , we can break
it into the union of at most n − 2 triangles. That is:
n−2
[ m−2
[
P = Ti and R = Sj .
i=1 j=1
It follows that
[ m−2
n−2 [
P ⊕R= (Ti ⊕ Sj ).
i=1 j=1
Thus, the Minkowski sum is the union of O(nm) polygons, each of constant complexity. Thus,
there are O(nm) sides in all of these polygons. The arrangement of all of these line segments
can have at most O(n2 m2 ) intersection points (if each side intersects with each other), and
hence this is an upper bound on the number of vertices in the final result.
Could the complexity really be this high? Yes it could. Consider the two polygons in
Fig. 179(a). Suppose that P and R have m and n “teeth”, respectively. For each of in-
dependent choice of two teeth of P (one from the top and one from the side), and two gaps
(a) (b)
You might protest that this example is not fair. While it is true that there are many compo-
nents in the Minkowski sum, motion planning takes place within a single connected component
of free space, and therefore the quantity that is really of interest is the (worst-case) combi-
natorial complexity of any single connected component of free space. (In the example above,
all the components were of constant complexity.) This quantity is complicated to bound for
general shapes, but later we will show that it can be bounded for convex shapes.
As a final observation, notice that the upper bound holds even if P (and R for that matter)
is not a single simple polygon, but any union of n triangles.
Convex Robot and Nonconvex Obstacles: We have seen that the worst-case complexity of
the Minkowski sum might range from O(n + m) to as high as O(n2 m2 ), which is quite a gap.
Let us consider an intermediate but realistic situation. Suppose that we assume that P is an
arbitrary n-sided simple polygon, and R is a convex m-sided polygon. Typically m is much
smaller than n. What is the combinatorial complexity of P ⊕ R in the worst case? As before
we can observe that P can be decomposed into the union of n − 2 triangles Ti , implying that
n−2
[
P ⊕R= (Ti ⊕ R).
i=1
Each Minkowski sum in the union is of complexity m + 3. So the question is how many sides
might there be in the union of O(n) convex polygons each with O(m) sides? We could derive
a bound on this quantity, but it will give a rather poor bound on the worst-case complexity.
To see why, consider the limiting case of m = 3. We have the union of n convex objects,
each of complexity O(1). This could have complexity as high as Ω(n2 ), as seen by generating
a criss-crossing pattern of very skinny triangles. But, if you try to construct such a counter
example, you won’t be able to do it.
Theorem: Let R be a convex m-gon and P and simple n-gon, then the Minkowski sum
P ⊕ R has total complexity O(nm).
Is O(nm) an attainable bound? The idea is to go back to our analogy of “scraping” R around
the boundary of P . Can we arrange P such that most of the edges of R scrape over most of
the n vertices of P ? Suppose that R is a regular convex polygon with m sides, and that P
has a comb-like structure where the teeth of the comb are separated by a distance at least
as large as the diameter of R (see Fig. 180(a)). In this case R will have many sides scrape
across each of the pointy ends of the teeth, implying that the final Minkowski sum will have
total complexity Ω(nm) (see Fig. 180(b)).
R P P ⊕R
(a) (b)
The Union of Pseudodisks: Consider a translating robot given as an m-sided convex polygon
and a collection of polygonal obstacles having a total of n vertices. We may assume that the
polygonal obstacles have been triangulated into at most n triangles, and so, without any loss
of generality, let us consider an instance of an m-sided robot translating among a set of n
triangles. As argued earlier, each C-obstacle has O(3 +m) = O(m) sides, for a total of O(nm)
line segments. A naive analysis suggests that this many line segments might generate as many
as O(n2 m2 ) intersections, and so the complexity of the free space can be no larger. However,
we assert that the complexity of the space will be much smaller, in fact its complexity will
be O(nm).
oi \ oj
oj \ oi
To show that O(nm) is an upper bound, we need some way of extracting the special geometric
structure of the union of Minkowski sums. Recall that we are computing the union of Ti ⊕ R,
where the Ti ’s have disjoint interiors. A set of convex objects {o1 , . . . , on } is called a collection
Lemma 1: Given a set convex objects T1 , . . . , Tn with disjoint interiors, and convex R, the
set
{Ti ⊕ R | 1 ≤ i ≤ n}
is a collection of pseudodisks (see Fig. 182).
Ti Ti ⊕ R
(a) (b)
Proof: Consider two polygons T1 and T2 with disjoint interiors. We want to show that T1 ⊕R
and T2 ⊕ R do not have a crossing intersection. Given any directional unit vector u,
the most extreme point of R in direction u is the point r ∈ R that maximizes the dot
product (u·r). (Recall that we treat the “points” of the polygons as if they were vectors.)
The point of T1 ⊕ R that is most extreme in direction u is the sum of the points t and
r that are most extreme for T1 and R, respectively.
Given two convex polygons T1 and T2 with disjoint interiors, they define two outer tan-
gents, as shown in the figure below. Let u1 and u2 be the outward pointing perpendicular
vectors for these tangents. Because these polygons do not intersect, it follows easily that
as the directional vector rotates from u1 to u2 , T1 will be the more extreme polygon,
and from u2 to u1 T2 will be the more extreme (see Fig. 183).
u2
u2
T2 extreme
T2
T1
T1 extreme u1
u1
(a) (b)
p1 = r + t1 p2 = r + t2 .
Since p1 is on the convex hull, it follows that t1 is more extreme than t2 in direction u1 ,
that is, T1 is more extreme than T2 in direction u1 . By applying this same argument, we
find that T1 is more extreme than T2 in directions u1 and u3 , but that T2 is more extreme
than T1 in directions u2 and u4 . But this is impossible, since from the observation
above, there can be at most one alternation in extreme points for nonintersecting convex
polygons (see Fig. 184).
u3 u2
T1 extreme T2 extreme
u3 u2
T2 ⊕ R
T1 ⊕ R
u u1
T2 extreme 4 T1 extreme
u4
u1
(a) (b)
Lemma 2: Given a collection of polygonal pseudodisks, with a total of n vertices, the com-
plexity of their union is O(n).
Proof: This is a rather cute combinatorial lemma. We are given some collection of polygonal
pseudodisks, and told that altogether they have n vertices. We claim that their entire
union has complexity O(n). (Recall that in general the union of n convex polygons
can have complexity O(n2 ), by criss-crossing.) The proof is based on a clever charging
scheme. Each vertex in the union will be charged to a vertex among the original pseu-
dodisks, such that no vertex is charged more than twice. This will imply that the total
complexity is at most 2n.
There are two types of vertices that may appear on the boundary. The first are vertices
from the original polygons that appear on the union. There can be at most n such
vertices, and each is charged to itself. The more troublesome vertices are those that
arise when two edges of two pseudodisks intersect each other. Suppose that two edges
e1 and e2 of pseudodisks P1 and P2 intersect along the union. Follow edge e1 into the
interior of the pseudodisk e2 . Two things might happen. First, we might hit the endpoint
v of this e1 before leaving the interior P2 . In this case, charge the intersection to v (see
Fig. 185(a)). Note that v can be assessed at most two such charges, one from either
incident edge. If e1 passes all the way through P2 before coming to the endpoint, then
try to do the same with edge e2 . Again, if it hits its endpoint before coming out of P1 ,
then charge to this endpoint (see Fig. 185(b)).
But what do we do if both e1 shoots straight through P2 and e2 shoots straight through
P1 ? Now we have no vertex to charge. This is okay, because the pseudodisk property
implies that this cannot happen. If both edges shoot completely through, then the two
polygons must have a crossing intersection (see Fig. 185(c)).
Recall that in our application of this lemma, we have n C-obstacles, each of which has at
most m + 3 vertices, for a total input complexity of O(nm). Since they are all pseudodisks,
it follows from Lemma 2 that the total complexity of the free space is O(nm).
The question is, why does this work? To see why, we need to establish the connection between
the triangles of the Delaunay triangulation and the faces of the convex hull of transformed
points. In particular, recall that
Delaunay condition: Three points p, q, r ∈ P form a Delaunay triangle if and only no other
point of P lies within the circumcircle of the triangle defined by these points.
Convex hull condition: Three points p↑ , q ↑ , r↑ ∈ P ↑ form a face of the convex hull of P ↑
if and only if no other point of P lies below the plane passing through p↑ , q ↑ , and r↑ .
Clearly, the connection we need to establish is between the emptiness of circumcircles in the
plane and the emptiness of lower halfspaces in 3-space. To do this, we will prove the following.
Lemma: Consider four distinct points p, q, r, and s in the plane, and let p↑ , q ↑ , r↑ , and s↑
denote their respective vertical projections onto Ψ, z = x2 + y 2 . The point s lies within
the circumcircle of 4pqr if and only if s↑ lies beneath the plane passing through p↑ , q ↑ ,
and r↑ .
Theorem: Given a set of points P in the plane (assuming no four are cocircular), and given
three points p, q, r ∈ P , the triangle 4pqr is a triangle of the Delaunay triangulation of
P if and only if triangle 4p↑ q ↑ r↑ is a face of the lower convex hull of the lifted set P ↑ .
From the definition of Delaunay triangulations we know that 4pqr is in the Delaunay trian-
gulation if and only if there is no point s ∈ P that lies within the circumcircle of pqr. From
the previous lemma this is equivalent to saying that there is no point s↑ that lies in the lower
convex hull of P ↑ , which is equivalent to saying that 4p↑ q ↑ r↑ is a face of the lower convex
hull. This completes the proof.
r↑ q ↑
p↑
s↑
s r
p q
Aside: Incircle revisited: By the way, we now have a geometric interpretation of the incircle
test, which we presented earlier for Delaunay triangulations. Whether the point s lies above
or below the (oriented) plane determined by points p, q, and r is determined by an orientation
test. The incircle test can be seen as applying this orientation test to the lifted points
This leads to the incircle test, which we presented earlier. Up to a change in sign (which
comes from the fact that we have moved to homogeneous column from the first column to
the last), we have
px py p2x + p2y 1
qx qy qx2 + qy2 1
orient(p↑ , q ↑ , r↑ , s↑ ) = inCircle(p, q, r, s) = sign det
rx ry rx2 + ry2 1 .
sx sy s2x + s2y 1
Voronoi Diagrams and Upper Envelopes: Next, let us consider the relationship between Voronoi
diagrams and envelopes. We know that Voronoi diagrams and Delaunay triangulations are
dual geometric structures. We have also seen (informally) that there is a dual relationship
between points and lines in the plane, and in general, between points and planes in 3-space.
From this latter connection we argued that the problems of computing convex hulls of point
sets and computing the intersection of halfspaces are somehow “dual” to one another. It
turns out that these two notions of duality, are (not surprisingly) interrelated. In particular,
in the same way that the Delaunay triangulation of points in the plane can be transformed
to computing a convex hull in 3-space, the Voronoi diagram of points in the plane can be
transformed into computing the upper envelope of a set of planes in 3-space.
Here is how we do this. For each point p = (a, b) in the plane, recall from Eq. (9) that the
tangent plane to Ψ passing through the lifted point p↑ is
z = 2ax + 2by − (a2 + b2 ).
Define h(p) to be this plane. Consider an arbitrary point q = (qx , qy ) in the plane. Its vertical
projection onto Ψ is (qx , qy , qz ), where qz = qx2 + qy2 ). Because Ψ is convex, h(p) passes below
Ψ (except at its contact point p↑ ). The vertical distance from q ↑ to the plane h(p) is
qz − (2aqx + 2bqy − (a2 + b2 )) = (qx2 + qy2 ) − (2aqx + 2bqy − (a2 + b2 ))
= (qx2 − 2aqx + a2 ) + (qy2 − 2bqy + b2 ) = kqpk2 .
In summary, the vertical distance between q ↑ and h(p) is just the squared distance from q to
p (see Fig. 188(a)).
Now, consider a point set P = {p1 , . . . , pn } and an arbitrary point q in the plane. From the
above observation, we have the following lemma.
kqpk2
q p q p1 p2 p3 p4
kqpk
(a) (b)
Fig. 188: The Voronoi diagram and the upper hull of tangent planes.
Lemma: Given a set of points P in the plane, let H(P ) = {h(p) : p ∈ P }. For any point q
in the plane, a vertical ray directed downwards from q ↑ intersects the planes of H(P ) in
the same order as the distances of the points of P from q (see Fig. 188(b)).
Consider the upper envelope U (P ) of H(P ). This is an unbounded convex polytope (whose
vertical projection covers the entire x, y-plane). If we label every point of this polytope with
the associated point of p whose plane h(p) defines this face, it follows from the above lemma
that p is the closest point of P to every point in the vertical projection of this face onto the
plane. As a consequence, we have the following equivalence between the Voronoi diagram of
P and U (P ) (see Fig. 189).
Theorem: Given a set of points P in the plane, let U (P ) denote the upper envelope of the
tangent hyperplanes passing through each point p↑ for p ∈ P . Then the Voronoi diagram
of P is equal to the vertical projection onto the (x, y)-plane of the boundary complex of
U (P ) (see Fig. 189).
Ψ Ψ
↑ ↑ ↑ ↑
p1 p4 p1 p4
↑ ↑ ↑ ↑
p2 p3 p2 p3
p1 p2 p3 p4 p1 p2 p3 p4
(1, 2) (2, 1) (3, 2) (4, 3)
(2, 3) (3, 4)
(a) (b)
(a) (b)
Range Spaces: Given a set P of n points in Rd , its power set, denoted 2P , is the set of all subsets
of P , including P and the empty set. The power set has 2n elements. If we constrain ourselves
to subsets formed by some geometric property (e.g., the subsets of P lying within a circular
disk, a halfplane, or a rectangle), this severely limits the types of subsets can can be formed.
We can characterize such geometric set systems abstractly as follows. A range space is defined
to be a pair (X, R), where X is an arbitrary set (which might be finite or infinite) and R is a
subset of the power set of X. We will usually apply range spaces to finite point sets. Given
a set P ⊆ X, define the restriction (sometimes called the projection) of R to P as
R|P = {P ∩ Q | Q ∈ R}.
Fig. 192: A 4-point set and the range space of axis-parallel rectangles. Note that sets {1, 4} and
{1, 2, 4} cannot be generated.
Measures, Samples, and Nets: When dealing with range spaces over very large point sets, it
is often desirable to approximate the set with a much smaller sample of the set that does a
good job of representing the set. What does it mean for a sample to be “good”? The concept
of a range space provides one way of making this precise.
Given a range space (P, R), where P is finite, and given a range Q ∈ R, we define Q’s measure
to be the fraction of points of P that it contains, that is
|Q ∩ P |
µ(Q) = .
|P |
Given a subset S ⊆ P (which we want to think of as being our sample, so that |S| |P |) it
provides an estimate on the measure of a range. Define18
|Q ∩ S|
µ
b(Q) = .
|S|
A set S is a good sample of P if the estimate is close to the actual measure. That is, we
would like to select S so that for all Q ∈ R, µ
b(Q) ≈ µ(Q).
There are two common ways of characterizing good sample sets: ε-samples and ε-nets. Given
a range space (P, R) and any ε > 0, a subset S ⊆ P is an ε-sample if for any range Q ∈ R
we have
|µ(Q) − µb(Q)| ≤ ε.
For example, suppose that ε = 0.1 and Q encloses 60% of the points of P (µ(Q) = 0.6) then
Q should enclose a fraction of 60 ± 10% (50–70%) of the points of S (see Fig. 193(b)). If this
is true for every possible choice of Q, then S is a 0.1-sample for P .
While ε-samples intuitively correspond a desirable standard for good samples, it is often the
case that we are can be satisfied with something weaker. Suppose that rather than achieving
a good estimate, we merely want good representation in the sense that any group of the
18
Since the estimate depends on the choice of S, we should write this as µ
bS (Q). Since S will usually be clear, we
will omit it.
µ(Q) = 15
25 = 0.6
µ 5 = 0.5
b(Q) = 10
(a) (b) (c)
population that is sufficiently large should contribute at least one member to the sample.
This suggests a slightly weaker criterion for a good sample. Given a range space (P, R) and
any ε > 0, a subset S ⊆ P is an ε-net if for any range Q ∈ R, if µ(Q) ≥ ε then Q contains at
least one point of S. For example, if ε = 0.2 and |P | = 25, then any range Q that contains
at least 0.2 · 25 = 5 points of P must contain at least one point of the ε-net (see Fig. 193(c)).
Observe that if S is an ε-sample, then it is surely an ε-net. The reason that ε-nets are of
interest is that they are usually much smaller than ε-samples, and so it is more economical
to use ε-nets whenever they are applicable.
VC Dimension: The constraint of using geometric shapes of constant complexity to define range
spaces is very limiting. Suppose that we are given a set P of n points in the plane and
R consists of axis parallel rectangles. How large might R|P be? If we take any axis-parallel
rectangle that encloses some subset of P , and we shrink it as much as possible without altering
the points contained within, we see that such a rectangle is generally determined by at most
four points of P , that is, the points that lie on the rectangle’s top, bottom, left, and right
sides. (It might be fewer if a point lies in the corner of the range.) It is easy to see, therefore,
that, for this particular range space, we have |R|P | = O(n4 ). How would this size be affected
if we were to use different shapes, say circular disks, triangles, or squares?
There is a very general method of characterizing such range spaces, and remarkably, the
definition makes no mention of geometry at all! This is the notion of VC-dimension, which is
short for Vapnik-Chervonenkis dimension.19 Given an arbitrary range space (X, R) and finite
point set P , we say that R shatters P if R|P is equal to the power set of P , that is, we can
form any of the 2|P | subsets of P by taking intersections with the ranges of R. For example,
the point set shown in Fig. 192 is not shattered by the range space of axis-parallel rectangles.
However, the four-element point set P shown in Fig. 194 is shattered by this range space,
because we can form all 24 = 16 subsets of this set.
Definition: The VC-dimension of a range space (X, R), is defined to be the size of the
largest point set that is shattered by the range space.
(a) (b)
Fig. 194: (a) a 4-element point set that is shattered by the range space of axis-parallel rectangles
(showing only the 2-element subsets in the drawing), and (b) the proof that no 5-element point set
is shattered.
d
(a) (b)
Fig. 195: (a) a 3-element point set that is shattered by the range space of Euclidean disks (showing
just the 2-element subsets), and (b) the proof that no 4-element point set is shattered.
For example, in Fig. 194 we have shown that it is possible to shatter a four-element point set
by axis-parallel rectangles. It is not hard to show, however, that no 5-element point set of
R2 can be shattered by this same range space. (We will leave this as an exercise.) Therefore,
the VC-dimension of the range space of 2-dimensional axis-parallel rectangles is four. We will
denote the VC-dimension as dimVC (X, R), or simply dimVC (R) when X is clear.
An important fact about this function is that it satisfies the following recurrence
Φd (n) = Φd (n − 1) + Φd−1 (n − 1).
An intuitive way to justify the recurrence is to fix one element x0 of the n-element set. The
number of sets of size at most d that do not contain x0 is Φd (n − 1) (since the element itself is
not available from the n elements) and the number of sets that do contain x0 is Φd−1 (n − 1)
(since once x0 is removed from each of these sets, we have d − 1 remaining elements to pick
from).
Sauer’s Lemma: If (X, R) is a range space with VC-dimension d and |X| = n, then |R| ≤
Φd (n).
Proof: The proof is by induction on d and n. It is trivially true if d = 0 or n = 0. Fix any
one element x ∈ X. Consider the following two range sets:
Rx = {Q \ {x} : Q ∪ {x} ∈ R and Q \ {x} ∈ R}
R \ {x} = {Q \ {x} : Q ∈ R}
Intuitively, Rx is formed from pairs of ranges from R that are identical except that one
contains x and the other does not. (For example, if x is along the side of some axis-
parallel rectangle, then there is a range that includes x and a slightly smaller one that
does not. We put the range that does not contain x into Rx .) The set R \ {x} is the
result of throwing x entirely out of the point set and considering the remaining ranges.
We assert that |R| = |Rx | + |R \ {x}|. To see why, suppose that we charge each range
of R to its corresponding range in R \ {x}. Every range of R \ {x} receives at least one
charge, but it receives two charges if there exist two ranges that are identical except that
one contains x and one doesn’t. The elements of Rx account for these extra charges.
Now, let us apply induction. Observe that the range space (X \ {x}, Rx ) has VC-
dimension d − 1. In particular, we claim that no set P 0 of size d can be shattered. To
see why, suppose that we were to throw x back into the mix. The pairs of sets of R
that gave rise to the ranges of Rx would then shatter the d + 1 element set P 0 ∪ {x}.
(This is the critical step of the proof, so you should take a little time to convince yourself
of it!) Clearly, the VC-dimension of R \ {x} cannot be larger than the original, so its
VC-dimension is at most d. Since both sets of ranges have one fewer element (n − 1),
by applying the induction hypothesis and our earlier recurrence for Φd (n), we have
|R| = |Rx | + |R \ {x}| ≤ Φd−1 (n − 1) + Φd (n − 1) = Φd (n).
And this completes the proof.
P
Q
(a) (b)
If a range space has VC-dimension d, we will show that there exist ε-samples and ε-nets whose
sizes depend on ε and d alone, independent of the original point set n. This is very important
in geometric approximation algorithms, because it allows us to extract a tiny set from a huge
one, with the knowledge that the tiny set is guaranteed to do a good job of representing the
huge one.
Theorem: (ε-Sample Theorem) Let (X, R) be a range space of VC-dimension d, and let P
be any finite subset of X. There exists a positive constant c (independent of the range
space) such that with probability at least 1 − ϕ any random sample S of P of size at
least
c d 1
d log + log
ε2 ε ϕ
is an ε-sample for (P, R). Assuming that d and ϕ are constants, this is O((1/ε2 ) log(1/ε)).
Theorem: (ε-Net Theorem) Let (X, R) be a range space of VC-dimension d, and let P be
any finite subset of X. There exists a positive constant c (independent of the range
space) such that with probability at least 1 − ϕ any random sample S of P of size at
least
c 1 1
d log + log
ε ε ϕ
is an ε-sample for (P, R). Assuming that d and ϕ are constants, this is O((1/ε) log(1/ε)).
We will not prove these theorems. Both involve fairly standard applications of techniques from
probability theory (particularly the Chernoff bounds), but there are quite a few non-trivial
technical details involved.
(a) (b)
The question of whether there exist k disks centered at the points of T that cover all the
points of P is equivalent to determining whether there exist k points of T such that every
Iterative Reweighting Algorithm: Given P , T , and k, our algorithm will determine whether
there exists a hitting set of size k 0 = ck log k, where c is a suitably chosen constant. To
start, we associate each point of T with a positive integer weight, which initially is 1. When
computing measures, a point p with weight w will be counted w times. For a suitable value
of ε (which depends on k) we compute a weighted ε-net N of size k 0 for T . This means that
any disk of radius δ whose weight is at least ε times the total weight of T must contain at
least one point of N . If N is a hitting set, we output N and we are done. If not, we must
have failed to hit some disk. Double the weights of the points within this disk (thus making
them more likely to be sampled in the future). If we don’t succeed after a sufficient number
of iterations, we declare that no hitting set of size k 0 exists. Here is a detailed description:
∈ ε-net
(a) (b)
Analysis: Before delving into the analysis, let’s see intuitively what the algorithm is doing. Clearly,
if this algorithm terminates, then it has computed a hitting set of size k 0 . We want to
argue that if such a hitting set exists, the algorithm will find it within 2k log(n/k) iterations.
Observe that if an iteration is not successful, then some disk was not hit by our random
sample. Because (by our assumption) the random sample is an ε-net, such a disk cannot
contain more than an ε fraction of the total weight. All the points within this disk have their
Because the function f (x) = 2x is a convex function, it follows from standard combinatorics
(in particular, Jensen’s inequality) that this sum is minimized when all the ti (j)’s are as
nearly equal as possible. We know that at least point must be doubled with each iteration,
and therefore the minimum occurs when ti (j) = i/k, for all j. (We’ll ignore the minor
inconvenience that ti (j) is an integer. It won’t affect the asymptotics.) Therefore:
Wi (H) ≥ k2i/k .
Because H ⊆ T , we know that Wi (H) ≤ Wi . Therefore, we know that the number of iterations
i must satisfy
k2i/k ≤ n · eεi .
Simplifying and recalling that ε = 1/(4k), we obtain
i i i
lg k + ≤ lg n + lg e ≤ lg n + .
k 4k 2k