Re: ISO proof of permutation enumeration algorithm



On Sat, 30 Jul 2005 03:05:09 +0000 (UTC), kj <socyl@xxxxxxxxxxxxxxxxx>
wrote:

>I'm looking for a proof that the following algorithm indeed enumerates
>all the permutations of a sequence s. I'll attempt to render the
>algorithm in my own home-grown pseudocode (additional explanations
>follow). The important thing to note is that at every iteration
>of the outer loop the algorithm obtains the next permutation by
>transforming the sequence s *in place*. Hence, as the algorithm
>progresses, s "visits" each permutation of its original value.
>(The first iteration just produces the original s.)
>
> m <-- length(s)
> n <-- 0
>
> while (true)
>
> if ( n == 0 )
> print( s )
> n <-- n+1
> continue
> endif
>
> i <-- 1
> p <-- n
> while ( i <= m and p % i == 0 )
> p <-- p / i
> i <-- i + 1
> endwhile
>
> if ( m < i )
> break
> endif
>
> j <-- m - i
> d <-- p % i
>
> s[ j+1 .. m-1 ] <-- reverse( s[ j+1 .. m-1 ] )
> s[ j, d ] <-- s[ d, j ]
>
> print( s )
> n <-- n+1
>
> endwhile
>
>Notes:
>
> 0. <-- denotes assignment; == denotes test of equality; % denotes
> the modulus operation (e.g. 7 % 5 is equal to 2);
> 1. the indexing of s is zero-based
> 2. hence, since m is the length of s, its last element is s[m-1]
> 3. s[ j+1 .. m-1 ] represents the sub-sequence s[j+1],...,s[m-1]
> 4. the expression s[ j+1 .. m-1 ] <-- reverse s[ j+1 .. m-1 ]
> says reverse *in place* the last m-(j+1) elements of s
> 5. the expression s[ j, d ] <-- s[ d, j ] just says "swap s[j]
> and s[d]"
> 6. the continue and break statements in the algorithm instruct
> it to repeat and exit (respectively) the outer while-loop;
>
>If anyone knows how a proof would go, or where I can read a proof,
>please let me know. Also, if anyone knows the name of this algorithm,
>I'd also like to know it. Many thanks in advance.
>
>kj.

You really should do some work here to guide the reader through what
seems to me to be rather unpolished code.

The least you could do is comment the mathematical intent of each
section.

But you should really do more. How about showing what the program
would output for a simple test case. For example, take the identity
permutation on 3 elements and simulate by hand the running of your
program. Show how the permutation s evolves, and for each new s,
indicate the associated values of various program variables.

Working through a few examples, you might actually discover the proof
you seek (provided the algorithm is correct), but in any case, at
least it would show good faith.

quasi
.



Relevant Pages

  • Some PERL code for detecting/displaying "toroidal" trees "invariant under a half-turn
    ... This algorithm will be reviewed by Dr. David Wagner ... Such trees can be termed "invariant" under a half-turn ... not display "the same" oDAG as the first, ... and detects whether this permutation will yield a tree ...
    (sci.math.num-analysis)
  • Re: Challenae question for mathematician
    ... problems relating to permutation groups. ... adjacent books. ... called "bubble sort" - it is a quadratic time algorithm, ... efficient as a sorting method - efficient sorting is O. ...
    (sci.math)
  • Some PERL code for detecting/displaying "toroidal" trees " invariant under a half-tur
    ... This algorithm will be reviewed by Dr. David Wagner ... "oDAGs " invariant under a half-turn. ... Such trees can be termed "invariant" under a half-turn ... and detects whether this permutation will yield a tree ...
    (sci.math)
  • Imperfect random permutation of 2^k elements
    ... given that one has available the Algorithm P of ... from the given random bit sequence real-valued random numbers ... to any other permutation by applying to it a certain permutation ... It may be noted that the dynamically varying S-box of RC4 is ...
    (sci.crypt)
  • Re: permutations and combinations
    ... > Right now I'm using a string, sorting it and passing it repeated into ... In this article he defines a generic algorithm: ... for_each_permutation calls fn for each permutation of last-first items ... The printing functor keeps a simple state which is just the line number. ...
    (comp.lang.cpp)

Quantcast