this the example , i have a string contains 4 chars (A,B,C,D). size =4 , now all possibel cimbinations = N! which N = length of the String
i want to find all possible combinations like
ABCD
ABDC
ACBD
ACDB
ADCB
ADBC
the question is algorithmic question it's not about strings ,it's a part of a huge algorithm currently implement it ,i've just simplified the questions to strings so you may understand what do i want ?
i want to find the best solution recursively or not recursive from the public
you dont' need to talk about recommendation in SCJP , i'm currently doing a SCJD FYI .
Hi Peter ,
i want to stor every solution as described in my last post in char array .it's not ABCD . it may be ABCDEFGJKSLDLFD .
the length is variable .
@alaa: No, he was referring to the difference between permutations (*not* combination, by the way) with, and without, repetition. Without repetition you get N!, with repetition you get N^2. The code shown is N^2, "duplicates" referring to the use of a single letter in more than one position.
I mean you can reverse and but the size of each array should be N .
EX: let ABCD the string , ACB will not be accepted the length should be the same length of the original string ,So
it's not permutation , and we will get N!.
alaa salameh wrote:I mean you can reverse and but the size of each array should be N .
EX: let ABCD the string , ACB will not be accepted the length should be the same length of the original string ,So
it's not permutation , and we will get N!.
Actually, what you just described is exactly what a permutation is. Regardless...
alaa salameh wrote:
i want to find the best solution recursively or not recursive from the public
you dont' need to talk about recommendation in SCJP , i'm currently doing a SCJD FYI .
This is pretty much a standard problem for recursion to solve. In fact, what you described is a homework problem for recursion, in many cases.
So... IMHO, recursive is the best solution to this problem.
I may be mistaken, in which case I shall happily restore the code, but I think simply giving an answer like that is not helpful to the original poster. Don't be annoyed, but I have pulled rank and deleted it.
Campbell Ritchie wrote:I may be mistaken, in which case I shall happily restore the code, but I think simply giving an answer like that is not helpful to the original poster. Don't be annoyed, but I have pulled rank and deleted it.
I hope you don't mind, Rob, Robert and Jesper.
I may be mistaken, in which case I shall happily restore the code, but I think simply giving an answer like that is not helpful to the original poster. Don't be annoyed, but I have pulled rank and deleted it.
I hope you don't mind, Rob, Robert and Jesper.
HI Campbell Ritchie ,
I thought might helpfull for him ,Since he might have already invested considerable time of this research ...
I've seen method code when it has been posted and before has been changed to throw new DoHomeWorkException () ,
but i'm telling you it's the same code i posted earlier with some changes from point to string .