wu :: forums
« wu :: forums - Permutations with unique neighbours »

Welcome, Guest. Please Login or Register.
Apr 29th, 2024, 9:38am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Icarus, SMQ, ThudnBlunder, Eigenray, Grimbal, towr, william wu)
   Permutations with unique neighbours
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Permutations with unique neighbours  (Read 3895 times)
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Permutations with unique neighbours  
« on: May 7th, 2012, 9:15am »
Quote Quote Modify Modify

Devise an algorithm for generating a set of permutations of n numbers with the property that every pair of adjacent numbers appears only once.
 
Example: set of permutations for 4 elements:
 
(1 2 3 4), (2 4 1 3)
« Last Edit: May 7th, 2012, 9:16am by Barukh » IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours  
« Reply #1 on: May 7th, 2012, 9:47am »
Quote Quote Modify Modify

Make an undirected graph where each vertex represents one element and all elements are connected by edges; repeatedly extract a path through the all n elements (removing the edges used; which ensures each pair of adjacent numbers occurs only once)
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Re: Permutations with unique neighbours  
« Reply #2 on: May 7th, 2012, 10:13pm »
Quote Quote Modify Modify

Towr, does your algorithm ensure maximum number of permutations?  Wink
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours  
« Reply #3 on: May 7th, 2012, 11:18pm »
Quote Quote Modify Modify

I don't know; possibly. Not by design, but perhaps by serendipity.
 
And another question, can the theoretical maximum number, n/2, always be reached?
« Last Edit: May 7th, 2012, 11:18pm by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Re: Permutations with unique neighbours  
« Reply #4 on: May 7th, 2012, 11:32pm »
Quote Quote Modify Modify

on May 7th, 2012, 11:18pm, towr wrote:
And another question, can the theoretical maximum number always be reached?

I don't posses a proof for this (which automatically implies that I haven't got a way to turn serendipity into a design Smiley).
 
But my intuition tells me "yes".
 
One way to start is to note that any number could be at the permutation boundary exactly once
 
Any takers?
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours  
« Reply #5 on: May 8th, 2012, 12:30am »
Quote Quote Modify Modify

Well, as it is my algorithm definitely doesn't ensure the maximum number of permutations.
For n=6, you might get (1, 2, 3, 4, 5, 6), (4, 1, 3, 5, 2, 6), after which you can't pick a 3rd path through the graph (which does exist for some other choices for the second permutation).
 
[e]Perhaps it might help to add a condition that you have to use the edge(s) between vertices that have the most edges.... Oh, never mind...not sufficient..[/e]
« Last Edit: May 8th, 2012, 12:42am by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
nks
Junior Member
**





   
Email

Gender: male
Posts: 145
Re: Permutations with unique neighbours  
« Reply #6 on: May 12th, 2012, 8:59pm »
Quote Quote Modify Modify


Quote:

Example: set of permutations for 4 elements:  
 
(1 2 3 4), (2 4 1 3)  

 
 As pair inclusive , following combination is also possible . right ?
(1 2 4 3) , (2 1 3 4)
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours  
« Reply #7 on: May 13th, 2012, 1:08am »
Quote Quote Modify Modify

Both those permutations have the pair 1,2 and 3,4
Unless you interpret pair as ordered pair.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
d33p4k
Newbie
*





   


Posts: 12
Re: Permutations with unique neighbours  
« Reply #8 on: May 14th, 2012, 12:54pm »
Quote Quote Modify Modify

How about this,
For a sequence where ai's are at odd position and bi's at even,
a1      b1  a2  b2  a3  b3  a4  b4....
Keeping one subsequence fixed and rotating the other by two places,
an/2-1 b1  an  b2  a1  b3  a2  b4...
The rotation can be done n/4 times.
 
Then, the sequence can be partitioned into two,
a1  a2  a3  a4  ....... an-1/2  b1  b2  b3  b4.....bn-1/2
Since, members in a's and b's were not together in the previous permutation, the same operation can be applied to them individually. This can be done recursively. At, each recursion, the rotation of every group is done together but the number of rotations reduces by half.
 
This can be done,
 
n/4+ n/8+ n/16+... n/2 times.  
 
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours   permutationswithuniquepairs.pdf
« Reply #9 on: May 17th, 2012, 10:59am »
Quote Quote Modify Modify

@d33p4k  
Either I'm not understanding your algorithm correctly, or it doesn't work as advertised.
For 12345678
It gives me
first 12345678
second 52741638
third 13572468, which gives a conflict.
Even if we swap it around to 24681357, I'm not seeing how to get to the fourth permutation.
 


As an improvement to my previous algorithm. I seem to get good results for even n, by taking using the pair that would close the previous permutation in a loop as the middle of the next one, taking the outermost edge the leads to an unused vertex and keeping it symmetric.  
(And for odd n we can stick the last element in the middle.)
 
I've attached an example..
It remains to be proven this would always work.

« Last Edit: May 17th, 2012, 11:49pm by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Permutations with unique neighbours  
« Reply #10 on: May 20th, 2012, 10:50am »
Quote Quote Modify Modify

hidden:

For n even, you can use the permutation
(0, 1, n-1, 2, n-2, ..., n/2-1, n/2+1, n/2)
and increment each value by 1 mod n.
For n=8 it gives
(0 1 7 2 6 3 5 4)
(1 2 0 3 7 4 6 5)
(2 3 1 4 0 5 7 6)
(3 4 2 5 1 6 0 7)
If you put the elements on a circle and draw these permutations, it is obvious what it does and how it works.
 
You have n(n-1)/2 possible pairs.  Each permutation covers (n-1) pairs, so the max is n/2 permutations.
 
For n odd, the maximum is rounded down to (n-1)/2 permutations.  That's the maximum for size n'=(n-1).
So you can just use the solution for (n-1), which is even, and add the extra element at the end.  For n=9 you have an extra element '8' so you get:
(0 1 7 2 6 3 5 4 8)
(1 2 0 3 7 4 6 5 8)
(2 3 1 4 0 5 7 6 8)
(3 4 2 5 1 6 0 7 8)

IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Permutations with unique neighbours  
« Reply #11 on: May 20th, 2012, 12:39pm »
Quote Quote Modify Modify

I wish I'd thought of that.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board