Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Pairings
Replies: 1   Last Post: Jul 19, 1996 3:04 AM

 Messages: [ Previous | Next ]
 Robert Pratt Posts: 56 Registered: 12/7/04
Pairings
Posted: Jul 17, 1996 1:41 AM

I want a function that finds, given n, all pairings of Range[n] excluding
{1,2}, {2,3}, {n-2,n-1}, and {n-1,n}. One approach would be to find the
appropriate permutations of Range[n] and then use Map[Partition[#,2],%]&.
For example, I would want specialpairings[4] to return {{{1,3},{2,4}}} and
specialpairings[6] to return {{{1,3},{2,5},{4,6}}, {{1,4},{2,5},{3,6}},
{{1,4},{2,6},{3,5}}, {{1,5},{2,4},{3,6}}, {{1,5},{2,6},{3,4}},
{{1,6},{2,4},{3,5}}, {{1,6},{2,5},{3,4}}}. I have worked out a formula
for the number of special pairings as a function of n, and
Length[specialpairings[8]] should be 57.

The well-known and easily derived formula for the number of pairings of
Range[n] is

numberofpairings[n_]:=n!/((2^(n/2))(n/2)!)

I can show that the number of special pairings is given by

numberofspecialpairings[n_]:=((n^2-8n+19)/((n-1)(n-3))) numberofpairings[n]

Since these formulas are asymptotic to each other as n gets large, it's
completely reasonable to generate all pairings and throw out those which
contain any of the four "bad" pairs {1,2}, {2,3}, {n-2,n-1}, and {n-1,n}.

The following naive method returns the desired results:

specialpairings[n_Integer]:=
Select[Union[
Map[Sort[#] &, Map[Partition[#,2] &, Permutations[Range[n]]],2]],
Intersection[#,{{1,2},{2,3},{n-2,n-1},{n-1,n}}] == {} &]

Of course, this function is VERY slow since there is a LOT of
duplication. I would like to use some sort of backtracking technique to
make the function more efficient. Does anyone have any suggestions?

Rob Pratt
Department of Mathematics
The University of North Carolina at Chapel Hill
CB# 3250, 331 Phillips Hall
Chapel Hill, NC 27599-3250

rpratt@math.unc.edu

Date Subject Author
7/17/96 Robert Pratt
7/19/96 Paul A. Rubin