to methodically listing permuations and combinations by hand?
There usually is little difference in the algorithm but I wonder about its purpose.
I am trying to implement an algorithm that finds all the anagrams (permutations) of a string of letters.
My thinking: Do it by alphabetical order.
So abc, acb, bac, bca, cab, cba
1. Sort strings by alphabetical order.
2. Swap other 2 letters in each string in the case of n = 3.
I am trying to find an algorithm.
Here is what I though of:
In the case of abc:
1. Fix first letter. Swap the second two letters.
2. Swap first two elements. Fix first element. Now swap second two letters.
3. Swap first and last elements. Fix first element. Now swap second two letters.