Permuatations [was: Please Help!!Daughter...]
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 2 Dec 2005 20:11:21 -0000
Daniel Dyer wrote:
> http://www.merriampark.com/comb.htm
>
> I stumbled across it myself a few weeks back when looking for some code to
> generate combinations.
Nice algorithm. Does anyone know of something comparatively slick for
generating permutations ?
I like the way that the state of the overall iteration is implicit in the state
of the array ('a' in the code on the website). It's straightforward to modify
the idea so that it generates all combinations with repetitions included, and
even more straightforward to make it generate all permutations with repetitions
included, but I can't think of a comparably small change that would make it do
"normal" permutations where repetitions are not included.
It's pretty easy to generate permutations by recursion, but converting a deeply
recursive algorithm into one suitable for external iteration would take, I
think, a Stack of Iterators -- which seems excessive when the other three
closely related algorithms can be handled so elegantly.
BTW, in case it's not clear (I'm not sure if I'm using the standard
terminology) to illustrate what I mean by permutations/combinations
with/without repetitions. Given the source collection {A B C}, and wanting
sub-collections of length 2, I mean
Combinations: AB AC BA
Permutations: AB AC BA BC CA CB
Combinations with repetition: AA AB AC BB BC CC
Permutations with repetition: AA AB AC BA BB BC CA CB CC
-- chris
.
- Follow-Ups:
- Re: Permuatations [was: Please Help!!Daughter...]
- From: Daniel Dyer
- Re: Permuatations [was: Please Help!!Daughter...]
- From: Roedy Green
- Re: Permuatations [was: Please Help!!Daughter...]
- From: Oliver Wong
- Re: Permuatations [was: Please Help!!Daughter...]
- References:
- Please Help!!Daughter needs help with java code
- From: Miggy23
- Re: Please Help!!Daughter needs help with java code
- From: cbroussard
- Re: Please Help!!Daughter needs help with java code
- From: Daniel Dyer
- Please Help!!Daughter needs help with java code
- Prev by Date: Re: "J" tripwire?
- Next by Date: Re: display 1's and 0's of byte array
- Previous by thread: Re: Please Help!!Daughter needs help with java code
- Next by thread: Re: Permuatations [was: Please Help!!Daughter...]
- Index(es):
Relevant Pages
|
Loading