Paired Pointset Traversal

advertisement
Paired Pointset Traversal
Peter Hui1 and Marcus Schaefer2
1
2
Department of Computer Science, DePaul University, Chicago, Illinois 60604
phui@students.depaul.edu
Department of Computer Science, DePaul University, Chicago, Illinois 60604
mschaefer@cti.depaul.edu
Abstract. In the Paired Pointset Traversal problem we ask whether,
given two sets A = {a1 , . . . , an } and B = {b1 , . . . , bn } in the plane,
there is an ordering π of the points such that both aπ(1) , . . . , aπ(n) and
bπ(1) , . . . , bπ(n) are self-avoiding polygonal arcs? We show that Paired
Pointset Traversal is NP-complete. This has consequences for the
complexity of computing the Fréchet distance of two-dimensional surfaces. We also show that the problem can be solved in polynomial time
if the points in A and B are in convex position, and derive some combinatorial estimates on lct(A, B), the length of a longest common traversal
of A and B.
1
Introduction
Suppose we are given two sets of points A = {a1 , . . . , an } and B =
{b1 , . . . , bn } in the plane. How hard is it to determine whether we can
traverse both A and B in the same order such that the resulting polygonal arcs do not self-intersect? Phrased differently, is there a permutation π such that both aπ(1) , . . . , aπ(n) and bπ(1) , . . . , bπ(n) are self-avoiding
polygonal arcs? We call this problem the Paired Pointset Traversal
problem, and call such a permutation a common traversal of A and B.
In Section 2 we show that deciding Paired Pointset Traversal is
NP-complete.
In Section 3 we study a variant of the Paired Pointset Traversal
problem, in which instead of straight lines we allow curves to connect
the points, but restrict the curves to lie within the convex hull of their
pointsets. This version can be solved in polynomial time. If we define
lct(A, B) to be the length of a longest common traversal of A and B, we
√
show that in the convex hull case, lct(A, B) is of order n.
The Paired Pointset Traversal problem is of interest in relation
to a notion from geometry, the Fréchet distance. Intuitively, the Fréchet
distance between two geometric objects is the largest distance between
two points in a simultaneous “smooth” traversal of both objects. For
example, for one-dimensional curves f : [0, 1] → R and g : [0, 1] → R, the
Fréchet distance is
δF (f, g) = inf max d(f (α(s)), g(β(s))),
α,β s∈[0,1]
where α and β range over all continuous and monotone parameterizations
of [0, 1]. The Fréchet distance captures, better than the more familiar
Hausdorff distance does, the notion of similarity in shape.
The Fréchet distance between two polygonal arcs can be found in
polynomial time [1]. However, computing the Fréchet distance between
two two-dimensional objects (even if restricted to the Euclidean plane)
is NP-complete [5]. One possible approach to approximating the Fréchet
distance would be through sampling: selecting pairs of points from the
two objects at random, reordering them so both of them form a polygonal
arc, and then computing the Fréchet distance between the two arcs. This
procedure is still NP-hard, however, since the reordering of the pairs
of points is the same as finding a common traversal of two pointsets.3
This connection with the Fréchet distance makes approximation results
of interest, and we take some initial steps in that direction in Section 3.2.
2
Paired Pointset Traversal
We formally define our problem Paired Pointset Traversal as follows:
INSTANCE: Two planar pointsets A = {a1 , . . . , an }, B = {b1 , . . . , bn }.
QUESTION: Is there a permutation π such that (aπ(1) , aπ(2) , . . . , aπ(n) )
and (bπ(1) , bπ(2) , . . . , bπ(n) ) both form self-avoiding polygonal paths?
Note that we do not prevent the two paths (aπ(1) , aπ(2) , . . . , aπ(n) ) and
(bπ(1) , bπ(2) , . . . , bπ(n) ) from intersecting each other— the only restriction
that we place upon the paths is that neither path may intersect itself. We
refer to such paths as matched self-avoiding paths.
Theorem 1. Paired Pointset Traversal is NP-complete.
Proof. We show NP-hardness by a reduction from the following version
of Hamiltonian Path:
INSTANCE: A plane graph G = (V, E) (that is a graph embedded in
the plane without intersections), and two of its vertices, s and t.
3
This connection was pointed out to us by Binhai Zhu, who also supplied us with the
problem in the first place [10].
QUESTION: Does G contain a Hamiltonian path from s to t.
This problem is well-known to be NP-complete [4], even if we assume
that s and t are on the boundary of the convex hull formed by V (an
assumption we will need later).
Given the plane graph G = (V, E) and two vertices s and t, we construct vertex sets A = {a1 , a2 , . . . , an } and B = {b1 , b2 , . . . , bn } in the
plane such that there is Hamiltonian path from s to t in G if and only
if A and B allow a matched self-avoiding path. This immediately shows
that Paired Pointset Traversal is NP-complete.
Let G = (V, E) be a plane graph with two special vertices s and
t. We start by adding the vertices of V to both A and B. We refer to
these vertex sets as VA and VB , respectively. Then, for each vertex pair
(u, v) 6∈ E, we select a point on the straight line uv and add it to B,
making sure that the point does not lie on any other straight line ab with
a, b ∈ V ; we call the set of these vertices NB . These points will assure that
we cannot traverse B by going directly from u to v for any edge (u, v)
that is absent from E. We then add a corresponding set of vertices, NA
to A. The vertices in NA have the same relative position to each other as
the vertices in NB , but they appear translated significantly beneath the
vertices of VA so as to allow space for another gadget that will be placed
between VA and NA . We also add to NA and NB another set TA and TB ,
which we will specify later in the proof. TA and TB will be necessary to
ensure that a simultaneous traversal is possible.
Finally, we need a third set of vertices to prevent traversals of A that
include edges going back and forth between VA to NA . More precisely, we
will add sets IA and IB such that any pair of matched self-avoiding paths
of A and B will (i) have to start in IA (IB ) and traverse all of IA (IB )
with the exception of a single vertex iA (iB ), then (ii) traverse all of VA
(VB ), (iii) go to iA (iB ), and finally (iv) traverse all of NA (of course the
traversal could be in the reverse order). We will show how to construct
this anti-interference gadget later, and first prove the correctness of the
construction. Figure 1 illustrates the construction up to this point.
Assuming then that the interference gadget works correctly, and we
can choose TA and TB to make a traversal of NA and NB possible, we
can prove the correctness of the construction. First suppose that there is
a Hamiltonian path in G. We can then traverse A and B simultaneously
as follows. Begin with IA − {iA } in A (IB − {iB } in B). Continue to
s, and follow a Hamiltonian path through VA (VB ) to t. From t go to
iA (iB ), and then on to NA (NB ). We will show later how to build NA
and NB such that they can be traversed simultaneously. For the other
A
B
V B , NB
VA
Anti-interference gadget (IA )
IB
NA
Fig. 1. Reduction from Planar Hamiltonian Path.
direction, suppose there is a pair of matched self-avoiding path. Since we
assumed that the anti-interference gadget works in that case, we know
that the paths traverse all of VA (VB ) before they begin traversing NA
(NB ). Furthermore, The vertices in NB ensure that the path through VB
does not use any edges outside of E. Hence, the traversal of VB constitutes
a Hamiltonian path in G, which is what we had to show.
We still owe the reader two details of the construction: how to build
the anti-interference gadget, and how to ensure that NA and NB can be
traversed simultaneously.
Let us first show how to build the anti-interference gadget IA and IB .
Our goal is to arrange the vertices of IA and IB such that all the points
in VA (VB ) get traversed before the points in NA (NB ), or vice versa.
We accomplish this by arranging the vertices of IA in a series of nested
wedges, and the vertices of IB in a line (see Figure 2).
We claim that there is only one simultaneous traversal of IA and IB ,
namely the one shown in the figure: IA must be traversed starting at
a1 , continuing outwards forming a series of nested wedges to ak+1 . If the
claim is true, this means that the anti-interference gadget performs its
function: it separates the traversal of VA from the traversal of NA , and,
furthermore, its vertices do not interfere with the traversals of VA and
NA .
We will establish the claim in several steps. We choose k = 5(|VB | +
|NB |) + 4. Consider the vertices along the line b1 , b2 , . . . , bk−1 . These ver-
s
ak+1
t
ak−1
a1
a2 ak
iA
To NA
To VB , NB
s
t
iB
bk+1
b1
b2
bk−2
bk−1
bk
Fig. 2. Anti-interference gadget for pointsets A (top) and B (bottom), along with their
sole legal traversal.
tices can only be traversed in order, unless a traversal uses a vertex outside of that line. Now there are at most |VB | + |NB | + 3 vertices other
than b1 , b2 , . . . , bk−1 . This means a traversal must contain four neighboring vertices (bi , bi+1 , bi+2 , bi+3 ) (since k is large enough). This, in turn
implies that IA contains a wedge, namely (ai , ai+1 , ai+2 ) if i is odd, or
(ai+1 , ai+2 , ai+3 ) if i is even. The subsequent vertices, ai+3 , . . . , ak−2 (or
ai+4 , . . . , ak−2 as the case might be), are entirely shielded from NA and
VA , which means, since the corresponding b vertices form a line, that they
have to be traversed in order, ending with ak−2 . The arrangement of the
vertices now ensures that ak−1 is the only point that we can connect to
next. Therefore, (bk−2 , bk−1 ) must be present as well.
Now, (bk−2 , bk−1 ) separates bk from VB and NB .
We must now show that from ak−1 , the only possible next vertex is
ak .
1. We cannot proceed from ak−1 to ak+1 , since doing so would result in
a self-intersection in B.
2. We cannot proceed from ak−1 to any vertex in VA , since doing so
would eventually require one of the following next steps:
(a) Moving to ak+1 . From ak+1 we could then only continue on to VA ,
since NA , and iA are shielded from it. From VA we would then
have to continue to iA . At this point, both bk and the vertices of
NB have yet to be visited. We have already proven that we cannot
traverse between bk and NB , so regardless of whether we decide
to visit bk or NB , it will be impossible to visit the other.
(b) Moving to iA . At this point we can continue to either NA or VA ∪
{ak+1 }, but we can no longer traverse both.
3. We cannot proceed from ak−1 to iA , since doing so would make it
impossible to traverse both VA and NA (as above).
This leaves ak as the sole possible next vertex from ak−1 , which in
turn implies that the vertices of IA are traversed as a complete sequence
of nested wedges (since (ak−1 , ak ) separates VA from the wedges.
Finally, we have to show how to wire NA and NB using additional
vertex sets TA and TB such that a simultaneous traversal is possible.
Remember that NB contains vertices chosen to obstruct edges that do
not occur in E. Now once VA and VB (and the anti-interference device)
have been traversed, we need to pick out these vertices. To this end,
we think of the area of VB being separated into polygonal regions by
the complete graph (drawn using straight lines) on the vertices VB . To
each resulting line segment we add four vertices, two on each side of the
line segment. Furthermore, if the line segment contains an obstruction
point, we make sure it is in the middle between the new vertices. Finally,
we add vertices surrounding VA , so we can pick up any region that is not
visible from IA . Figure 3 illustrates the construction. It shows a particular
Hamiltonian path having been chosen (in bold), and, based on that, the
subsequent traversal of NB to pick up all remaining vertices. Since NA
is a translation of NB , and does not interact with VA , any legal traversal
of NB is a legal traversal of NA . Hence, we only need to show that there
is a legal traversal of NB . The Hamiltonian path separates the faces of
the complete graph into a number of connected regions, all of which are
visible from the outside (a path cannot enclose a region). We can therefore
trace a path around the graph, and traverse each connected region we see
in a depth-first manner (not entering a face if it has been entered before).
In this way we can reach all the points of NB .
This completes the construction.
t
u
s
i
b
I
t
B
Fig. 3. A graph containing a Hamiltonian path (in bold) with vertices NB added, along
with its traversal (dotted).
3
The Convex Hull Case
Next, we consider a version of the problem in which we allow arbitrary
curves (rather than straight lines) between points. This change by itself would make the pointset problem trivial: there always is a solution.
However, the situation changes, if we require the curves to be contained
within the convex hull formed by their respective pointsets. In that case,
a simultaneous traversal is not always possible.
If the pointsets contain points (ai , bi ) such that either ai is interior
to the convex hull of A, or bi interior to the convex hull of B (or both),
then we can ignore these points, since they do not affect the existence
of a paired pointset traversal: at least one of ai or bi can be positioned
arbitrarily by distorting the interiors. The only problem these points pose
is finding them; this can be done in time O(n log n) using a standard
convex hull algorithm.
From this point onwards, we assume that the points in A and B are
in convex position; that is, all the points of A and B lie on the boundary
of their convex hulls.
While the initial problem is NP-complete, we show that the convex
hull variant can be solved in linear time using a combination of greedy
choice and dynamic programming.
3.1
Recognition
Let us first concentrate on legal traversals within a single set in convex
position. For example, Figure 4 shows a legal traversal of a set A.
2
1
3
7
4
6
5
Fig. 4. A pointset, A with a legal traversal, (6, 7, 1, 5, 4, 2, 3). We allow arbitrary curves
between points, provided that all curves lie within the convex hull of the respective
pointsets.
Let (v1 , v2 , . . . , vn ) be a clockwise ordering of the vertices of A on the
border of the convex hull. We claim that any legal traversal of all the
vertices in A which starts with v1 can be obtained as follows: beginning
with the sequence (v2 , . . . , vn ) keep removing either the first or the last
vertex from the sequence and add it to the traversal.
Example 1. We start with the clockwise ordering (6, 7, 1, 2, 3, 4, 5) in Figure 4, and continue (7, 1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (2, 3, 4, 5), (2, 3, 4), (2, 3),
(3), (), obtaining the legal traversal (6, 7, 1, 5, 4, 2, 3).
The proof of the claim is easy: if we begin with v1 and then select a
vertex vi other than v2 or vn , we disconnect v2 , . . . , vi−1 from vi+1 , . . . , vn
(both non-empty sets). On the other hand, any traversal obtained in the
fashion described leads to a legal traversal, that is, a self-avoiding path.
The situation becomes more involved if instead of a traversal of one
set, we consider simultaneous traversals of two sets, A and B. If we assume, for the moment, that we know the starting points a1 and b1 of the
traversals in both A and B, then we know that in each set there are at
most two ways of continuing a self-avoiding path. There are three possibilities: if there is no common way to continue the traversals, we have
run into a dead end. If there is exactly one common way to continue
the traversal, we choose that continuation. The only problem arises if
both ways of continuing the current traversal work are legal in both A
and B. The following lemma shows that in that case it does not matter
which choice we make: if we have a choice between two vertices to select,
then choosing one of the vertices will enable us to complete a pair of
self-avoiding paths if and only if choosing the other will as well.
Lemma 1. Let
A = (a1 , a2 , a3 . . . , an ), and
B = (b1 , bπ(2) , bπ(3) , . . . , bπ(n) )
be clockwise orderings of A and B respectively, where π is a permutation of
{2, . . . , n} such that either (i) π(2) = 2 and π(n) = n, or (ii) π(2) = n and
π(n) = 2. Then there is a simultaneous traversal of A and B beginning
with a1 , a2 (b1 , b2 ) if and only if there is one beginning with a1 , an (b1 , bn ).
Proof. We only consider the case π(2) = 2 (the other being symmetric:
take a mirror image of one of A or B). If there is a simultaneous traversal, we can without loss of generality assume that there is one starting
with a1 , a2 and, therefore, b1 , b2 . Follow the traversal, until it chooses
an , bn ; that is, we pick a1 , a2 , . . . , ai , an and b1 , b2 , . . . , bi , bn . But then we
might as well pick a1 , an , a2 , . . . , ai and b1 , bn , b2 , . . . , bi . In both cases
we are left with the same set of remaining vertices: (ai+1 , . . . , an−1 and
(bi+1 , . . . , bn−1 . Hence, if we have a choice of how to continue after picking
a1 (b1 ) it does not matter which choice we select.
t
u
At this point, we can write an algorithm which, given index i and
length l, determines in linear time whether or not a paired self-avoiding
path fragment of length l exists traversing A and B and starting at ai
and bi (see Algorithm A.1 in the appendix). We could then extend this
algorithm by a brute force approach and try each (ai , bi ), 1 ≤ i ≤ n, to
determine whether a complete simultaneous traversal exists in quadratic
time. However, with a slight extension of this algorithm, we can tighten
this bound to make the entire algorithm run in linear time. We do this
by using dynamic programming. We build segments of a path starting at
an arbitrary (ai , bi ), saving the computed path for subsequent attempts
at a different (aj , bj ) in the event that this one fails. In this manner, no
subpath will ever need to be recomputed. The details can be found in
Appendix A.2.
3.2
Optimization
What can we do if Algorithm A.1 determines that A and B do not have
a common pointset traversal? We could try to optimize the length of a
longest common traversal, lct(A, B). We suspect that this problem will
turn out to be NP-complete, hence approximation results would be of
interest. A simple approximation result follows from the following observation:
√
Lemma 2. If A and B are in convex position then lct(A, B) ≥ n.
Proof. Assume the vertices are labelled clockwise as a1 , . . . , an , and the
vertices of b as bπ(1) , . . . , bπ(n) for some permutation π of {1, . . . , n}. Then
a longest monotone subsequence of (π(1), . . . , π(n) will be a common legal
traversal of A and B. An old result of Erdős and Szekeres shows that any
sequence of distinct real numbers contains a monotone subsequence of
√
length at least n [2, 9].
t
u
The lemma allows us to approximate lct(A, B) to within a factor of
by simply predicting it to be n3/4 . We also note that the lemma is
asymptotically optimal:
n1/4
Lemma 3. There are A and B in convex position such that lct(A, B) ≤
√
2 n + 1.
Proof. Consider two sets A and B, each in convex position, and a common
(not necessarily full) traversal. Without loss of generality we can assume
that the vertices of A are labelled a1 , . . . , an in a clockwise ordering, and
the common traversal begins with a1 and b1 . If we consider the sequence of
indexes of this traversal it has the property that it alternatingly increases
and decreases, without ever going beyond any earlier values. That is if i <
j < k, then either ai , aj , ak is monotone, or ak lies between ai and aj . We
call such a sequence a telescope sequence. For example, 1, 3, 13, 11, 9, 5, 8, 7
is a telescope sequence. If we split a telescope sequence into its increasing
and its decreasing parts, it is clear that every telescope sequence of length
m contains a monotone sequence of length at least m/2. Returning to
our traversal, we see that if the traversal has length m, then it contains a
monotone traversal of length at least m/2 whose indices form a monotone
sequence. Hence, if we order B in such a way that it does not have a
√
monotone subsequence of length n + 1 (which is possible, since the
√
result by Erdős and Szekeres is sharp), then lct(A, B) ≤ 2 n + 1.
t
u
The convex case gives us a first break into the general case.
Corollary 1. If A and B are two sets of points chosen uniformly and
independently at random in a circle, then the expected value of lct(A, B)
is at least n1/18 .
Proof. By a result of Raynaud [8, Theorem 4.2] the convex hull of A has an
expected number of n1/3 vertices on its boundary. If we restrict B to the
corresponding vertices, those n1/3 vertices are still uniformly distributed
over the circle, hence their convex hull has an expected number of n1/9
vertices on the boundary. If we restrict A to the corresponding vertices,
we are now in a situation where both A and B are in convex position,
and we can apply Lemma 2 to conclude that we expect lct(A, B) to be
at least n1/18 .
t
u
4
Open Questions
As far as we know this is the first time the common pointset traversal
problem has been formalized and studied, so open questions still abound,
even though the convex hull case seems to be closely tied to results from
geometric Ramsey theory.
In the general case, the most important open problem is the complexity of approximating lct(A, B). The construction in our NP-hardness result is very fragile, and it seems tricky to even extend it to claiming that
approximating lct(A, B) to within an additive constant is still NP-hard.
We did show that lct(A, B) is at least n1/18 for points chosen at random in a circle; the result relied on finding large subsets of points in convex
positions. By a well-known result of Erdös and Szekeres [3, 7] there are
pointsets such that the largest subset of points in convex position is of
order log n. Hence using the same idea √as in the random case, the best
result we can obtain is that lct(A, B) ≥ log log n, which cannot possibly
be anywhere near the truth.
In the convex hull case, the most immediate problem is to settle the
complexity of the optimization problem. However, there are several other
questions that also suggest themselves: how fast can we solve the paired
pointset traversal problem if we allow up to k intersections. Is the resulting
problem NP-complete? If so (and we conjecture that this is the case), how
does the complexity vary with k? More precisely, taking the parameterized
complexity view, can we show that the paired pointset traversal problem
can be solved in time O(nc ) for any fixed k, where c does not depend
on k. A recent, comparable result, of Martin Grohe shows that we can
determine in quadratic time, whether the crossing number of a graph is
at most k (for any fixed k) [6].
Acknowledgment. We would like to thank Binhai Zhu for suggesting
the problem to us, and explaining its application to measuring similarity
of two-dimensional surfaces.
References
1. Helmut Alt and Michael Godau. Measuring the resemblance of polygonal curves.
In Proceedings of the 8th Annual Symposium on Computational Geometry, pages
102–109. ACM Press, 1992.
2. Paul Erdős and George Szekeres. A combinatorial problem in geometry. Compositio
Math., 2:463–470, 1935.
3. Paul Erdős and George Szekeres. On some extremum problems in elementary
geometry. Ann. Univ. Sci. Budapest Eotvos Soc. Math., 3-4:53–62, 1961.
4. M. R. Garey, D. S. Johnson, and R. Endre Tarjan. The planar Hamiltonian circuit
problem is NP-complete. SIAM Journal on Computing, 5(4):704–714, December
1976.
5. Michael Godeau. On the complexity of measuring the similarity between geometric
objects in higher dimensions. PhD thesis, Freie Universität Berlin, 1998.
6. Martin Grohe. Computing crossing numbers in quadratic time. In Proceedings
of the 32nd ACM Symposium on Theory of Computing, pages 231–236, July 6–8
2001.
7. W. Morris and V. Soltan. The Erdős-Szekeres problem on points in convex
position—a survey. Bull. Amer. Math. Soc. (N.S.), 37(4):437–458 (electronic),
2000.
8. Franco P. Preparata and Michael Ian Shamos. Computational geometry. An introduction. Texts and Monographs in Computer Science. Springer-Verlag, New York,
1985.
9. J. Michael Steele. Variations on the monotone subsequence theme of Erdős and
Szekeres. In Discrete probability and algorithms (Minneapolis, MN, 1993), volume 72 of IMA Vol. Math. Appl., pages 111–131. Springer, New York, 1995.
10. Binhai Zhu, 2004. Personal Communication.
A
Convex Hull Algorithms
A.1
Algorithm (given starting points)
Algorithm 1 Linear-time algorithm for deciding if a matched selfavoiding path of length l through A and B exists starting at points ai
and bi
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
P AT H ← λ
CA ← ClockwiseOrdering(A, ai )
CB ← ClockwiseOrdering(B, bi )
while (|P AT H| < l) do
if ((CA [first] = CB [first])OR (CA [first] = CB [last])) then
newV ertex ← CA [first]
add newV ertex to P AT H
delete newV ertex from CA
delete newV ertex from CB
else if ((CA [last] = CB [first])OR (CA [last] = CB [last])) then
newV ertex ← CA [last]
add newV ertex to P AT H
delete newV ertex from CA
delete newV ertex from CB
else
return false {cannot proceed any farther }
end if
end while
return true {both orderings have been consumed}
A.2
Linear-Time Algorithm: Correctness
Consider two clockwise orderings
A = (a1 , a2 , a3 . . . , an ), and
B = (b1 , bπ(2) , bπ(3) , . . . , bπ(n) ).
Without loss of generality, suppose that we choose a1 (b1 ), resulting in
path fragments A1 and B1 , which start with vertices a1 and b1 , respectively. Furthermore, suppose that after exhausting all possible choices,
some vertices remain. That is, we hit a dead end, and we are left with
some remaining sequence
A = (ai , . . . , aj ), and
B = (bm , . . . , bm+j−i )
where i, j, m, and m + j − i are pairwise different. At this point, it is
not necessary to discard the common paths A1 (A2 ) already computed.
Instead, we save the computed fragments A1 and B1 , and restart the
process using the clockwise orderings of the pointset, this time starting
at ai (bi ):
A = (ai , ai+1 , . . . , al ), and
B = (bi , bπ0 (i+1) , . . . , bπ0 (l) )
where l = (i + n − 1) mod n. We obtain a new pair of path fragments A 2
and B2 , which start with vertices ai and bi , respectively. If at some point
we are able to choose a1 (b1 ) as the next vertex, it is no longer necessary to
continue our computation. Rather, we append our precomputed fragment
A1 and B1 to our newly computed fragments A2 and B2 , and continue
our computation. We proceed similarly if we are able to choose ak (bk ).
To show that this such a merge is possible, observe that the two fragments being merged are both self-avoiding, and only share one point,
namely one endpoint from each fragment. As such, merging the two fragments yields another self-avoiding fragment.
If instead, however, it turns out that we have hit a dead end once more,
we again save the computed fragments for possible later reuse, and restart
the entire process with the clockwise orderings of the original pointset,
again starting with one of the endpoints from the remaining sequence,
and merging with any precomputed path fragments as appropriate.
We continue in this manner until either we can no longer continue, in
which case we are left with a set of path fragments collectively containing
all vertices in the pointset, whose endpoints are disjoint, indicating that
there is no valid traversal, or until we have computed a complete path.
Since we save all paths as we compute them, no vertex is ever considered
more than once, and we can determine in linear time whether a valid
traversal exists.
What remains to be shown is that if a legal simultaneous traversal of
the pointsets exists, this algorithm will find it. Observe that the clockwise
orderings of the two pointsets are fixed. Also note that at any point in
the algorithm, the choice of possible vertices is restricted to one of the
remaining endpoints. As such, choosing either of these endpoints can only
serve to expand the current fragment’s path, without fear of invalidating
any fragments attempted later on. Thus the order in which we choose
potential starting vertices is irrelevant; if a legal traversal exists, then by
running the algorithm on an arbitrary vertex, the resulting path fragment
will be a subpath of a legal traversal.
Download