The "Ham Sandwich" Theorem, also known as the Stone-Tukey Theorerom, says that in n-dimensional space, n point sets can be exactly split in half by a single hyperplane.
In 2D, this is called a Ham Sandwich Cut: We are given n red points A, and m blue points B, and we want to compute a single line that simultaneously bisects both sets. (If the cardinality of either set is odd, then the line passes through one of the points of the set.)
That is, no matter where you ham and cheese is, you can make one straight cut and get exactly half of each on each side! (In 3D, you can even have bread.)
We will get back to food later, but to get there we divert briefly to introduce a new concept of duality. It has the same name, but this duality is different that the dual of a graph.
Duality: Let us begin by considering 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. We cannot represent vertical lines in this way, and for now we will just ignore them. Later in the semester we will fix this up.
Why did we subtract b? We'll see later that this is just a convenience. Therefore, in order to describe a line in the plane, you need only give its two coordinates (a, b). In some sense, lines in the plane can be thought of as points in a new plane in which the coordinate axes are labeled (a, b), rather than (x, y). Thus the line y = 7x - 4 corresponds to the point (7, 4) in this new plane. Each point in this new plane of ``lines'' corresponds to a nonvertical line in the original plane. We will call the original (x, y) plane the primal plane and the new (a, b) plane the dual plane.
What is the equation of a line in the dual plane? Since the coordinate system uses a and b, we might write a line in a symmetrical form, for example b = 3a - 5, where the values 3 and 5 could be replaced by any scalar values. Consider a particular point p = (px, py) in the primal plane, and consider the set of all nonvertical lines passing through this point. Any such line must satisfy the equation:
py = a px - b.The images of all these lines in the dual plane is a set of points:
L = {(a,b) | py = a px - b}
= {(a,b) | b = px a - py}
Notice that this set is just the set of points that lie on a line in
the dual (a, b) plane. (And this is why we negated b.) Thus, not only
do lines in the primal plane map to points in the dual plane, but
there is a sense in which a point in the primal plane corresponds to a
line in the dual plane. To make this all more formal, we can define a
function that maps points in the primal plane to lines in the dual
plane, and lines in the primal plane to points in the dual plane. We
denote it using an asterisk *. Thus, given point p =
(px,py) and line e : (y = ax - b) in the primal
plane we define *e and *p to be a point and line respectively in the
dual plane defined by:
*e = (a, b)
*p = {b = px a - py }
We can define the same mapping from dual to primal as well. Duality
has a number of interesting properties, each of which is easy to
verify by substituting the definition and a little algebra.
Figure 35: Dual transformation.
As an example, we can make a connection between the upper convex hull of a set of points and the lower envelope of a set of lines.
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 , is equal to the left to right order of the sequence of lines on the lower (upper) envelope of the dual *P.
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. Observe that a necessary and sufficient condition for a pair of points p(i) p(j) to form an edge on the upper convex hull is that the line e(ij) that passes through both of these points has every other point in P strictly beneath it.
Consider the dual lines *p(i) and *p(j). A necessary and sufficient condition that these lines are adjacent on the lower envelope is that the dual point at which they meet, *e(ij) lies beneath all of the other dual lines in *P . The order reversing condition of duality assures us that the primal condition occurs if and only if the dual condition occurs. Therefore, the sequence of edges on the upper convex hull is identical to the sequence of vertices along the lower envelope. As we move counterclockwise along the upper hull observe that 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 cryptical 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. We will discuss projective geometry later in the semester.
Another interesting question is that of orientation. We know the the orientation of three points is positive if the points have a counterclockwise orientation. What does it mean for three lines to have a positive orientation? (The definition of line orientation is exactly the same, in terms of a determinant of the coefficients of the lines.)
Now back to our sandwich!
The general form of this theorem was proved in 1942 by Stone and Tukey. We are going to start with a simplified version, and make the simplifying assumption that the sets are separated by a line. (This assumption makes the problem much simpler to solve, but the general case can still be solved in O(n2) time using arrangements.)
To make matters even simpler we assume that the points have been translated and rotated so this line is the y axis. Thus all the red points (set A) have positive x coordinates, and hence their dual lines have positive slopes, whereas all the blue points (set B) have negative x coordinates, and hence their dual lines have negative slopes. 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. 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? If we dualize the points using the standard dual transformation: D(a, b) : y = ax - b, then we get 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 -inf 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, 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. 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 (n-1)/2 th level in the arrangement. This is shown as M (A) in the following figure on the left.
Figure 100: Ham sandwich: Dual formulation.
Thus, the set of bisecting lines for set A in dual form consists of a polygonal curve. Because this curve is formed from edges of the dual lines in A, and because all lines in A have positive slope, this curve is monotonically increasing. Similarly, the median for B, M (B), is a polygonal curve which is monotonically decreasing. It follows that A and B must intersect at a unique point. The dual of this point is a line that bisects both sets. We could compute the intersection of these two curves by a simultaneous topological plane sweep of both arrangements. However it turns out that 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 L1and 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.
So Ham Sandwhich cuts are a natural(?) problem whose solution is based upon an arrangment of lines (in the dual plane). Do arrangements of lines have a special structure?? You bet they do...
Arrangements: So far we have studied a few of the most important structures in computational geometry: convex hulls, Voronoi diagrams and Delaunay triangulations. Perhaps, the next most important structure is that of a line arrangement. As with hulls and Voronoi diagrams, it is possible to define arrangements (of d - 1 dimensional hyperplanes) in any dimension, but we will concentrate on the plane. As with Voronoi diagrams, a line arrangement is a polygonal subdivision of the plane. Unlike most of the structures we have seen up to now, a line arrangement is not defined in terms of a set of points, but rather in terms of a set L of lines. However, line arrangements are used mostly for solving problems on point sets. The connection is that the arrangements are typically constructed in the dual plane. We will begin by defining arrangements, discussing their combinatorial properties and how to construct them, and finally discuss applications of arrangements to other problems in computational geometry.
Before discussing algorithms for computing arrangements and applications, we first provide definitions and some important theorems that will be used in the construction. A finite set L of lines in the plane subdivides the plane. The resulting subdivision is called an arrangement, denoted A(L). Arrangements can be defined for curves as well as lines, and can also be defined for (d - 1) dimensional hyperplanes in dimension d. But we will only consider the case of lines in the plane here. In the plane, the arrangement defines a planar graph whose vertices are the points where two or more lines intersect, edges are the intersection free segments (or rays) of the lines, and faces are (possibly unbounded) convex regions containing no line. An example is shown below.
Figure 66: Arrangement of lines.
An arrangement is said to be simple if no three lines intersect at a common point. We will make the usual general position assumptions that no three lines intersect in a single point. This assumption is easy to overcome by some sort of symbolic perturbation.
An arrangement is not formally a planar graph, because it has unbounded edges. We can fix this (topologically) by imagining that a vertex is added at infinity, and all the unbounded edges are attached to this vertex. A somewhat more geometric way to fix this is to imagine that there is a bounding box which is large enough to contain all the vertices, and we tie all the unbounded edges off at this box. Rather than computing the coordinates of this huge box (which is possible in O(n2) time, or, even, (n log n) time), it is possible to treat the sides of the box as existing at infinity, and handle all comparisons symbolically. For example, the lines that intersect the right side of the ``box at infinity'' have slopes between +1 and -1, and the order in which they intersect this side (from top to bottom) is in decreasing order of slope. (If you don't see this right away, think about it!)
The combinatorial complexity of an arrangement is the total number of vertices, edges, and faces in the arrangement. The following shows that all of these quantities are O(n2).
Theorem: Give a set of n lines L in the plane in general position,
(i) the number of vertices in A(L) is (n choose 2)
(ii) the number of edges in A(L) is n2, and
(iii) the number of faces in A(L) is (n choose 2) + n + 1
Proof: The fact that the number of vertices is (n choose 2) is clear from the fact that each pair of lines intersects in a single point. To prove that the number of edges is n2, we use induction. The basis case is trivial (1 line and 1 edge). When we add a new line to an arrangement of n - 1 lines (having (n - 1) 2 edges by the induction hypothesis) we split n - 1 existing edges, thus creating n - 1 new edges, and we add n new edges from the n - 1 intersections with the new line. This gives a total of (n - 1) 2 + (n - 1) + n = n2. The number of faces comes from Euler's formula, v - e + f = 2 (with the little trick that we need to create one extra vertex to attach all the unbounded edges to).
Incremental Construction: Arrangements are used for solving many problems in computational geometry. But in order to use arrangements, we first must be able to construct arrangements. We will present a simple incremental algorithm, which builds an arrangement by adding lines one at a time. Unlike most of the other incremental algorithms we have seen so far, this one will not require randomization. In fact, its asymptotic running time will be the same, O(n 2 ), no matter what order we insert the lines. This is asymptotically optimal, since there this is the size of the arrangement. The algorithm will also require O(n 2 ), since this is the amount of storage needed to store the final result. (Later we will consider the question of whether it is possible to traverse an arrangement without actually building it.) As usual, we will assume that the arrangement is represented in any reasonable data structure for planar graphs, a DCEL for example. Let L = {l1, l2, ... , ln} denote the lines. We will simply add lines one by one to the arrangement. (The order does not matter.) We will show that the i th line can be inserted in O(i) time. If we sum over i, this will give O(n2) total time.
Suppose that the first i - 1 lines have already been added, and consider the effort involved in adding li. Recall our assumption that the arrangement is assumed to lie within a large bounding box. Since each line intersects this box twice, the first i - 1 lines have subdivided the boundary of the box into 2(i - 1) edges. We determine where liintersects the box, and which of these edge it crosses intersects. This will tell us which face of the arrangement lifirst enters.
Next we trace the line through the arrangement, from one face to the next. Whenever we enter a face, the main question is where does the line exit the face? We answer the question by a very simple strategy. We walk along the edges face, say in a counterclockwise direction (recall that a DCEL allows us to do this) and as we visit each edge we ask whether liintersects this edge. When we find the edge through which liexits the face, we jump to the face on the other side of this edge (again the DCEL supports this) and continue the trace. This is illustrated in the figure below.
Once we know the points of entry and exit into each face, the last matter is to update the DCEL by inserting edges for each entry exit pair. This is easy to handle in constant time, by adjusting the appropriate pointers in the DCEL. (Details are left as an exercise.) 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). Hey, what went wrong? Above we said that we would do this in O(i) time. The claim is that the traversal does indeed traverse only O(i) edges, but to understand why, we need to delve more deeply into a concept of a zone of an arrangement.
Figure 67: Traversing an arrangement and zones.
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 l that is not in L, the zone of l in A(l), denoted ZA (l), is the set of faces whose closure intersects l. The figure above illustrates a zone for the line l. For the purposes of the above construction, we are only interested in the edges of the zone that lie below li, 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: (The Zone Theorem) Given an arrangement A(L) of n lines in the plane, and given any line l in the plane, the total number of edges in all the cells of the zone ZA (l) is at most 6n.
Proof: As with most combinatorial proofs, the key is to organize everything so that the counting can be done in an easy way. Note that this is not trivial, because it is easy to see that any one line of L might contribute many segments to the zone of l. The key in the proof is finding a way to add up the edges so that each line appears to induce only a constant number of edges into the zone.
The proof is based on a simple inductive argument. We will first imagine, through a suitable rotation, that l is horizontal, and further that none of the lines of L is horizontal (through an infinitesimal rotation). 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. More formally, since each face is convex, if we split it at its topmost and bottommost vertices, we get two convex chains of edges. The left bounding edges are on the left chain and the right bounding edges are on the right chain. We will show that there are at most 3n lines that bounded faces from the left. (Note that an edge of the zone that crosses l itself contributes only once to the complexity of the zone. In the book's proof they seem to count this edge twice, and hence their bound they get a bound of 4n instead. We will also ignore the edges of the bounding box.)
For the basis case, when n = 1, then there is exactly one left bounding edge in l's zone, and 1 <= 3n. Assume that the hypothesis is true for any set of n - 1 lines. Consider the rightmost line of the arrangement to intersect l. Call this l1. (Selecting this particular line is very important for the proof.) Suppose that we consider the arrangement of the other n - 1 lines. By the induction hypothesis there will be at most 3(n - 1) left bounding edges in the zone for l.
Figure 68: Proof of the Zone Theorem.
Now let us add back ln and see how many more left bounding edges result. Consider the rightmost face of the arrangement of n-1 lines. Note that all of its edges are left bounding edges. Line l1will intersect l within this face. Let ea and eb denote the two edges of this that l1 intersects, one above l and the other below l. The insertion of l1creates a new left bounding edge along l1 itself, and splits the left bounding edges ea and eb into two new left bounding edges for a net increase of three edges. Observe that l1 cannot contribute any other left bounding edges to the zone, because (depending on slope) either the line supporting ea or the line supporting eb blocks l1's visibility from from l. (Note that it might provide right bounding edges, but we are not counting them here.) Thus, the total number of left bounding edges on the zone is at most 3(n - 1) + 3 <= 3n, and hence the total number of edges is at most 6n, as desired.
In the next class we will see how to use line arrangement to solve a collection of other problems...