
please wait
|
|
|
|
|
|
The function should generate 6 sets of numbers |
|
|
If you store the permutations, however, you must have a O(n*n!) computational and memory footprint proportional to n*n!. |
|
|
generateAllPermutations
, however you substitute the line
|
|
int i=d[nextIndex];
.
|
|
So my argument is: with a linked list you don't really store all permutations in an array with constant access time. |
I'm not sure if I properly understood - Are you claiming you can unfold any arbitrary permutation, given only the: 1. original sequence 2. index of the permutation to get in O(n)? So that you could write a code like this: 1 2 for (int i = 0; i < n!; ++i) cout << permutation(collection, i); and make it print all the permutations? |
for (int i=0; i<NumPermutations; i++) { base.getFactorialNumberSystem(i, shorterNotation);//this operation is O(n) theVector=theInitialVector;//so is this one generateOnePermutationFromIndices(theVector, shorterNotation);//and so is this one printVector(theVector); } |
|
|
D. E. Knuth, The Art of Computer Programming |