previous |
start |
next
To Generate All Permutations
- Generate all permutations that start with 'e' , then
'a' then 't'
- To generate permutations starting with 'e', we need to
find all permutations of "at"
- This is the same problem with simpler inputs.
- Use recursion
- nextPermutaion
method returns one permutation at a time
- PermutationGenerator remembers
it state
- the string we are permuting (word)
- position of the current character (current)
- a PermutationGenerator of the substring (tailGenerator)
- nextPermutation
asks tailGenerator
for its next permutation and returns
word.charAt(current) +
tailGenerator.nextPermutation();
previous |
start |
next