Advanced Recursive Techniques: Permutations |
The code presented on page 555, determines and displays the permutations of a String (StringBuffer). The tree can be used to help unravel the recursive magic of the code. String permutations are displayed to the screen when the base case is achieved, equivalent to the bottom level (leaves) of the tree below.
Task. A string that contains n characters generates n! permutations. For each character that repeats m times, the number of unique permutations (combinations) is reduced by a factor of m!. Confirm this result by modifying PermutationsTest to maintain an LinkedList of unique permutations (instead of printing them out) in aphabetic order.