CS 506: Homework #2 |
Problem 1: Use our line segment algorithm to solve the following problem: given a subdivision of the plane with a total of n line segments and given m points, report, for each point, which face (region) of the subdivision contains it. Your algorithm should run in O((m+n)log(m+n)) time. The subdivision is composed of a collection of segments that only intersect other segments (if at all) at their common endpoints. We can treat all of these segments as independent and feed them to our intersection routine. The routine builds a balanced binary tree that, in each vertical stripe, gives us the total vertical ordering of the segments. We can then locate each point that falls within that stripe with respect to the vertical ordering; once we know that it falls immediately above a certain segment, we can look up the two faces associated with that segment (in the DCEL, with the edge and its twin, since we cannot be sure of the direction) and test which of the two is the one in which the point sits. The line segment intersection algorithm takes O(nlogn) time (even if we handle the intersections in the usual way, there are only O(n) of them). Assigning points to their proper strips takes O(mlogn) time by searching or O(n+mlogm) time by sorting and sweeping. Finally, locating each point in the vertical order within a given strip takes O(logn) time per point, or O(mlogn) time in all. Overall, then, we have an algorithm that runs in O(nlogn+mlogn) = O((m+n)logn) time, slightly better than asked for.
Problem 2: The following is not a geometric algorithm, but a good first exercise in analyzing the expected running time of an algorithm. Consider the following algorithm for finding the minimum of a set:
procedure weird-minimum(A)
if |A| == 1 then
return x, the single element of A
else
pick uniformly at random an element of A, call it x
A' = A - {x}
x' = weird-minimum(A')
if x' <= x then
return x'
else
for each element y of A'
test (x <= y)
if false, halt and report error
return x
endif
endif
Set up and solve a recurrence relation describing the expected running time of
this procedure; incidentally, what is its worst-case running time?
The recurrence is simple: if we denote by f(n) the actual time on a set of size n, then we can write
To get the expected value, we need to find E[x'>x]; by linearity of expectations, we can then simply substitute in the recurrence and obtain
Note that this is a true randomized algorithm: we rely on the random choice of x to ensure the expected value, not on the distribution of the data in the input set.
Problem 3: Given a collection of halfplanes, a redundant halfplane is one that does not contribute an edge to the intersection of the halfplanes in the collection. Show that every redundant halfplane contains the intersection of some pair of halfplanes from the collection. A redundant halfplane, by definition, contains the intersection of the collection of halfplanes; also by definition, no point of the intersection lies on boundary of the halfplane. Thus the convex polygon defined by the intersection is contained with the halfplane and does not touch its boundary (other than perhaps in a single point). If the convex polygon is in fact itself a halfplane, then its boundary must be parallel to that of our redundant halfplane, and its intersection with itself is contained within the redundant halfplane. Otherwise let x be the vertex on the polygon closest to the boundary of the redundant halfplane: it is easy to see that the two adjacent edge of the polygon both move away from the boundary of the redundant polygon (otherwise there would be a closer vertex, or, in the case of an unbounded edge, it would cross the boundary and thus not meet the requirement of intersection). The two halfplanes corresponding to these two edges form an intersection wedge that is contained within our redundant halfplane.
| Back to CS 506 home page |