In
discrete geometry, the ham sandwich theorem usually refers to the special case in which each of the sets being divided is a
finite set of
points. Here the relevant measure is the
counting measure, which simply counts the number of points on either side of the hyperplane. In two dimensions, the theorem can be stated as follows: :For a finite set of points in the plane, each colored "red" or "blue", there is a
line that simultaneously bisects the red points and bisects the blue points, that is, the number of red points on either side of the line is equal and the number of blue points on either side of the line is equal. There is an exceptional case when points lie on the line. In this situation, we count each of these points as either being on one side, on the other, or on neither side of the line (possibly depending on the point), i.e. "bisecting" in fact means that each side contains less than half of the total number of points. This exceptional case is actually required for the theorem to hold, of course when the number of red points or the number of blue is odd, but also in specific configurations with even numbers of points, for instance when all the points lie on the same line and the two colors are separated from each other (i.e. colors don't alternate along the line). A situation where the numbers of points on each side cannot match each other is provided by adding an extra point out of the line in the previous configuration. In
computational geometry, this ham sandwich theorem leads to a
computational problem, the
ham sandwich problem. In two dimensions, the problem is this: given a finite set of points in the plane, each colored "red" or "blue", find a ham sandwich cut for them. First, described an algorithm for the special, separated case. Here all red points are on one side of some line and all blue points are on the other side, a situation where there is a unique ham sandwich cut, which Megiddo could find in linear time. Later, gave an algorithm for the general two-dimensional case; the running time of their algorithm is , where the symbol indicates the use of
Big O notation. Finally, found an optimal -time
algorithm. This algorithm was extended to higher dimensions by where the running time is o(n^{d-1}). Given sets of points in
general position in -dimensional space, the algorithm computes a -dimensional hyperplane that has an equal number of points of each of the sets in both of its half-spaces, i.e., a ham-sandwich cut for the given points. If is a part of the input, then no
polynomial time algorithm is expected to exist, as if the points are on a
moment curve, the problem becomes equivalent to
necklace splitting, which is
PPA-complete. A linear-time algorithm that area-bisects two disjoint convex polygons is described by . ==Generalization to algebraic surfaces==