Question

I recently studied the Quickperm algorithm to iteratively generate permutations of a string, and other than this which is not very detailed/explanatory I couldn't find any other sources which explained it more clearly. Also I thought by simply checking whether the values we are swapping are same or not, will handle the cases when there are duplicate characters in the string, however duplicate permutations still arise.

Could anyone point out how to remove duplicates and provide some other source or explain the quickperm algorithm?

Était-ce utile?

La solution

Doesn't seem possible to do it on fly while generating the permutations, in QuickPerm, your best bet is to just keep adding to a set after each fully generated permutation to keep on removing duplicates.

Autres conseils

Use the standard algorithm for enumerating permutations in lexicographic order. QuickPerm, like many clever algorithms, is fragile; it cannot be generalized easily to the case where there are duplicates.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top