Reputation: 96391
Suppose you need to discover all possible permutations of 'n' distinct characters, say 'a', 'b', 'c'. Can you suggest an algorithm I can use to get this done? Generally speaking, how would you go about it?
Upvotes: 3
Views: 176
Reputation: 86525
Let 'Perms' be the collection of permutations found, and 'Used' be a list of the characters currently selected.
To find permutations of n chars from a set S:
When you've returned from finding permutations of n chars, Perms contains all the possible permutations.
Note, this is all done using sets and lists. There are lighter-weight alternatives, but these structures make the steps more straightforward, so i used them.
Upvotes: 1