The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Robert Pratt

Posts: 56
Registered: 12/7/04
Posted: Jul 17, 1996 1:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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


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:

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

Date Subject Author
Read Pairings
Robert Pratt
Read Re: Pairings
Paul A. Rubin

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.