Pairings
- To: mathgroup at smc.vnet.net
- Subject: [mg4434] Pairings
- From: Robert Pratt <rpratt at math.unc.edu>
- Date: Mon, 22 Jul 1996 02:10:24 -0400
- Sender: owner-wri-mathgroup at wolfram.com
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 at math.unc.edu
==== [MESSAGE SEPARATOR] ====