Permutation

Permutation without recursion

To iterate is human, to recurse is divine.
…but Iteration is "always" (proof that I am wrong;) faster than Recursion.

How to generate a permutation set without recursion:
http://www.geocities.com/permute_it/

Number of permutations for a given input string

With Excel you can use =PERMUTE(A1;A2) to calculate the
total number of unique combinations of a given input string.

A1: 9
A2: 9

result: 362880

...
8    1 2 3 4 5 6 7 8    8 7 6 5 4 3 2 1    5040 * 8 = 40320
9    1 2 3 4 5 6 7 8 9    9 8 7 6 5 4 3 2 1    40320 * 9 = 362880
N    1 2 3 . . . (N - 1) N    N (N - 1) . . . 3 2 1    (N - 1)! * N = N!

http://www.geocities.com/permute_it/03example.html

Permutation Call Stack Visualization

--- Call Trace of Permute ---

                      -: Permute({1,2,3}, [-,-,-], 1, 3)
                   .     .
                .           .
             .                 .
          .                       .
         1: Permute({2,3}, [1,-,-], 2, 3)
        .   .                            .
       .       .                            .
      .           .                          2: Permute({1,3}, [2,-,-], 2, 3)
     .               .                          etc.
    .                   .                      3: Permute({1,2}, [3,-,-], 2, 3)
   .                       .                       etc.
1.1: Permute({3}, [1,2,-], 3, 3)
  . .                              .
  .    .                            1.2: Permute({2}, [1,3,-], 3, 3)
  .       .
1.1.1: Permute({}, [1,2,3], 4, 3)
                .
                   .
                   1.2.1: Permute({}, [1,3,2], 4, 3)

Source: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Recn/Perm/

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License