0

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.

Newbie
  • 361
  • 2
  • 15
  • 33
  • possible duplicate of [Generate list of all possible permutations of a string](http://stackoverflow.com/questions/361/generate-list-of-all-possible-permutations-of-a-string) – Neil Jun 07 '12 at 20:13
  • http://www.codeproject.com/Articles/26050/Permutations-Combinations-and-Variations-using-C-G – Tim Schmelter Jun 07 '12 at 20:14

1 Answers1

3

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

Zzz
  • 2,927
  • 5
  • 36
  • 58