Can any one help me how to print all permutations of String both iterative and Recursive way? I prefer VB.NET or just pseudo code is fine.
Thanks in advance.
Recursive approach is as follows:
Base case: The permutation of 1 letter is one element.
General case: The permutation of a set of letters is a list each of the letters, concatenated with every permutation of the other letters.
Explanation:
If the set just have one letter then return that letter. permutation(a) -> a
If the set has two letters, for each letter return it and the permutation of the rest of the letters.
permutation(ab) ->
a + permutation(b) -> ab
b + permutation(a) -> ba
For each letter in set return the letter concatenated with perumation of the rest of the set of letters.
permutation(abc) ->
a + permutation(bc) --> abc, acb
b + permutation(ac) --> bac, bca
c + permutation(ab) --> cab, cba