Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
permuting the elements of an array
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ralph Boland  
View profile  
 More options Jun 23, 12:44 pm
From: Ralph Boland <rpbol...@gmail.com>
Date: Tue, 23 Jun 2009 09:44:45 -0700 (PDT)
Local: Tues, Jun 23 2009 12:44 pm
Subject: permuting the elements of an array
I have an array of objects and I need to generate all permutations.
e.g.  for [1,2,3]   I get:
[1,2,3]
[1,3,2]
[2,1,3]
[2,3,1]
[3,1,2]
[3,2,1]

This problem is actually easy to solve and in fact there is a purely
iterative solution.
However in my case I also need to solve a variant of this problem.
In this variant the array has 2n elements grouped into n groups of two
elements
where each 2 element pair are equal.
For example for array  [1,1,2,2]  I get:
[1,1,2,2]
[1,2,1,2]
[1,2,2,1]
[2,1,1,2]
[2,1,2,1]
[2,2,1,1]

Note that in the first case I get n! permutations whereas in the
second case
I get  (2n)! / 2^n  permutations.  I want to generate the permutations
efficiently.
I particular it is unacceptable to generate the (2n)! combinations and
then
remove the duplicates.   I have come up only with complicated ways of
doing this
but I am hoping someone can post or reference a simpler solution.
A solution that generalizes in various ways would be nice but not
important to my
particular problem.

I will be implementing the final solution in Smalltalk (Squeak) and
eventually in other
languages as part of an implentation of the spine tree decomposition
data structure.
It will be released (in Squeak at least) under the MIT license.

Thanks for any help provided.

Ralph Boland


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miroslav Balaz  
View profile  
 More options Jun 23, 12:55 pm
From: Miroslav Balaz <gpsla...@googlemail.com>
Date: Tue, 23 Jun 2009 18:55:58 +0200
Local: Tues, Jun 23 2009 12:55 pm
Subject: Re: [algogeeks] permuting the elements of an array

It is also so easy, but maybe requires more lines of code

you only need count number of used number for each 1..n
and then...(repeat recursive approach)

ONE LINE SOLUTION IN C++

ok use next permutation from STL, read how it works for other language
and initialize array 11223344, and do while next_permutaion()...
it actualy gives you always next lexicographical permutation of sequence

you can also view source code of it in libraries

2009/6/23 Ralph Boland <rpbol...@gmail.com>


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ajinkya Kale  
View profile  
 More options Jun 23, 1:01 pm
From: Ajinkya Kale <kaleajin...@gmail.com>
Date: Tue, 23 Jun 2009 22:31:07 +0530
Local: Tues, Jun 23 2009 1:01 pm
Subject: Re: [algogeeks] Re: permuting the elements of an array

Yeah c++ STL nextpermutation api will do it .. good solution Miroslav!

On Tue, Jun 23, 2009 at 10:25 PM, Miroslav Balaz <gpsla...@googlemail.com>wrote:

--
Ciao,
Ajinkya

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sandy  
View profile  
 More options Aug 19, 12:17 pm
From: sandy <jainsandee...@gmail.com>
Date: Wed, 19 Aug 2009 09:17:38 -0700 (PDT)
Local: Wed, Aug 19 2009 12:17 pm
Subject: Re: permuting the elements of an array
Please see http://geeksforgeeks.org/?p=767 for well explained C
implementation of the same.

On Jun 23, 10:01 am, Ajinkya Kale <kaleajin...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google