Suppose that S is a set of 2n points in the plane

advertisement
y
b
f
d
2
1
c
a
1
e
0
1
2
3
x
Figure 1
Suppose that p=(a,b) and q=(c,d) are two points in the plane. The Manhattan distance
M(p,q) between p and q is |a-c|+|b-d|. For example, consider the set {1,2,3,4,5,6} in
Figure 1; here M(b,c)=2, M(c,a)=2, M(c,d)=5, m(e,f)=3.
Suppose that S is a set of 2n points in the plane. A matching of S is a pairing of the points
of S, that is, a one-one onto function mate:S  S such that for all p in S, mate(p) != p,
and mate(mate(p)) == p. The Manhattan cost of the matching is
Mcost = 1/2peS M(p,mate(p)).
For example, in Figure 1:
 If the matching is mate(c)=a, mate(b)=f, mate(e)=d, then Mcost = 8.
 If the matching is mate(c)=b, mate(a)=d, mate(e)=f, then Mcost =8.
 If the matching is mate(c)=b, mate(a)=e, mate(f)=d, then Mcost=4; this is the
minimum Manhattan cost matching.
The Manhattan minimum cost matching problem (MCMP) is as follows:
Input: a set S of 2n points
Output: a matching of S with as small a Manhattan cost as possible.
The simple greedy algorithm for MCMP is as follows:
Repeat n times
Choose a pair of points p,q in S such that Mcost(p,q) is a minimum;
Mate(p) := q;
Delete p and q from S;
(a) Show how to implement the simple greedy algorithm as fast as possible. You will
need to refine the algorithm above. Describe the data structures that you use.
(b) Does the simple greedy algorithm give an optimal solution? If so, prove it. If not,
give an example of a set of points S for which the simple greedy algorithm does
not give an optimal solution.
Suppose that S is a set of 3n points in the plane. A triangular matching T of S is a set of
triples of the points of S, such that every point of S is in exactly one triple. For example,
in Figure 1, the set T1={(a,f,d), (b,c,e)} is a triangular matching; the set T2={(ab,c),
(d,f,e)} is another triangular matching
The triangle cost of a triangular matching T is the sum of the areas of the triangles in T.
The Triangular minimum cost matching problem (TCMP) is as follows:
Input: a set S of 3n points
Output: a triangular matching of S with as small a triangle cost as possible.
(c) Compute down the triangle costs of the triangular matchings T1 and T2 above.
(d) Write down a simple greedy algorithm for TCMP. Show how to implement your
simple greedy algorithm as fast as possible. Describe the data structures that you
use.
(e) Does your simple greedy algorithm give an optimal solution? If so, prove it. If
not, give an example of a set of points S for which the simple greedy algorithm
does not give an optimal solution.
Download