Perry Smith

Java Questions & Answers

Archive

Home / Java Q & A Archive Page 4 / Java Q & A Archive / Java Main Page

recursive permutations
Tuesday, 06-Apr-99 08:18:24

203.23.149.162 writes:

how do i write code for a recursive solution to print the permutations of characters in a string assuming no repeated characters.


Responses
Re: recursive permutations
Wednesday, 07-Apr-99 00:00:37

202.54.7.12 writes:

Hi,
i can understand permutations of chars in a string. i might be of help if u could clearly explain 'recursive solutions'...
ganesh


reverse sequence using recursion
Monday, 12-Apr-99 17:27:40

194.158.187.242 writes:

Do you mean reverse sequence with 'permutation', ie change 'abc' into 'cba'?

If you do, you can write a method that says

      the permutation of a string is:
      the permutation of the substring from character 2 onwards (the recursion)
      + the first character.

      e.g. 'abc'
      -> permutated('abc')
      -> permutated('bc') + 'a'
      -> (permutated('c') + 'b') + 'a',
      -> ((permutated('') + 'c') + 'b') + 'a'
      -> '' + 'c' + 'b' + 'a'
      -> 'cba'
Voila. Be carefull to end recursion when there are no chars left.

Henk Jan


reply
Tuesday, 13-Apr-99 01:33:28

202.54.7.8 writes:

Hi,
actually, if u are looking at reversing a string StringBuffer class does it for u..

Ganesh


Home / Java Q & A Archive Page 4 / Java Q & A Archive / Java Main Page