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