Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top