Can you solve the following mathematical riddle: We define the counterdistance between…
- User
Can you solve the following mathematical riddle: We define the counterdistance between two permutations P1 and P2 and P1 and P2 to be the minimum number of adjacent interchanges to turn P1 into a permutation whose order is the exact opposite of P2. Given m permutations on n elements, what is the minimum possible sum of all pairwise counterdistances ?
- Assistant
First, one shows that for any two permutationsPi,PjP_i,,
and hence if among yourmmmpermutations exactlykkkof them rankaaabeforebbb(and the otherm−km-km−krankbbbbeforeaaa), then thosemmmpermutations contribute
to the total \emph{counter}‑distance “sum” over all(m2)\binom{m}{2}(2m)pairs of permutations. To minimize that for each fixed pair(a,b)(a,b)(a,b)you simply choose
so that
Since there aren(n−1)2\tfrac{n(n-1)}22n(n−1)unordered element‑pairs{a,b}{a,b}{a,b}, the absolute minimum total is
Equivalently, one can write in unified form
- User
Ah that's correct, great. The same problem on circular permutations is much harder, can you come up with good asymptotic lower bound for it (exchanging the first and last element is considered an adjacent exchange, since we're dealing with circular permutations)
- Assistant
- User
but you use the theta notation, is the minimum sum of counterdistances bounded above by nm^2 ?
- Assistant
Yes—nothing more exotic can beat theO(nm2)O(n,m^2)O(nm2)scaling. In fact:
Trivial per‐pair bound.For any two circular permutationsPi,PjP_i,, the circular counterdistance
Trivial per‐pair bound.For any two circular permutationsPi,PjP_i,, the circular counterdistance
since reversing a cyclic interval of always be done in⌊n/2⌋\lfloor (with wrap‑around) swaps.
Summing over all(m2)\binom m2(2m)pairstherefore gives theupperbound
Summing over all(m2)\binom m2(2m)pairstherefore gives theupperbound
Matching lower bound.Our two‑cluster construction of “half” of the permutations equal to a cyclicPPPand the other “half” to its reverse attains
Matching lower bound.Our two‑cluster construction of “half” of the permutations equal to a cyclicPPPand the other “half” to its reverse attains
Putting these together shows
so in particular it is indeed boundedaboveby a constant timesnm2n,m^2nm2.
- User
Suppose two circular permutations are identical, what is their counterdistance ?
- Assistant
IfP1P_1P1andP2P_2P2are the same circular permutationPPP, then you’re asking for the minimum number of (cyclic) adjacent‐swaps needed to turnPPPinto its reverse. One checks that you can pick an “axis” through the cycle so that reversal is exactly the product of all the disjoint swaps of thennnelements in symmetric edge‐pairs. There are exactly⌊n/2⌋\lfloor n/2\rfloor⌊n/2⌋such pairs, and the corresponding adjacent‐transpositions all commute, so you can do them in parallel — giving
In particular:
Ifnnnis even,contdistcirc(P,,P)=\tfrac n2contdistcirc(P,P)=2n.
Ifnnnis odd,contdistcirc(P,,P)=\tfrac{n-1}2contdistcirc(P,P)=2n−1.
Ifnnnis even,contdistcirc(P,,P)=\tfrac n2contdistcirc(P,P)=2n.
Ifnnnis odd,contdistcirc(P,,P)=\tfrac{n-1}2contdistcirc(P,P)=2n−1.
- User
OK, do you think the following reasoning is correct or not? In order to reverse every triplet {a,b,c} of elements in P1, at least one swap will be needed to reverse it. There are n choose 3 such triplets, and a single swap affects (n-2) triplets. Hence the counterdistance of P1 to itself is at least (n choose 3) / (n-2)
- Assistant
- User
But isn't it right that a single swap can corrects the orientation of at most n-2 tripleS
- Assistant
- User
Yes, but your arguments that flips can overlap and undo one another, and that triples might get flipped three, five or more times, support the idea that the number of swaps might be larger, not smaller, than the bound I provided. Since a triple might be flipped several times, it has to be flipped at most once.
- Assistant
- User
OK, but again, I repeat, a swap can flip at most (n-2) triple. Since there are (n choose 3) triple to flip, you would need at least (n choose 3) / (n-2) swaps. In other words, if we write, next to each triple, the list of swaps that affected it, and then we concatenate all these lists in a single list, every distinct swap would never appear more than n-2 times. That's because a swap will never occur twice for the same triple in an optimal sequence of flips, because those two swaps will just cancel each other's effect.
- Assistant
- User
No, every triple does need flipping. Not every pair needs flipping, but every triple does need flipping. if a triple occurs in the order a,b,c in the original permutation, it will occur in the order c,b,a in the reversed permutation, and a,b,c is not equivalent to c,b,a under any rotation.
- Assistant
- User
Your equation n.(n/2)/1 = n/2 is wrong, no ?
- Assistant