posted 7 years ago

hi all ,

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

BACD

BADC

BCAD

BCDA

BDAC

BDCA

AND etc ...... till we reached to N! .

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

BACD

BADC

BCAD

BCDA

BDAC

BDCA

AND etc ...... till we reached to N! .

posted 7 years ago

Not a great recommendation for the SCJP, that.

luck, db
*There are no new questions, but there may be new answers.*

Peter Taucher

Ranch Hand

Posts: 174

posted 7 years ago

hey Darry! ,

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 .

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 .

Campbell Ritchie

Marshal

Posts: 55770

163

posted 7 years ago

@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.

posted 7 years ago

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!.

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!.

posted 7 years ago

Actually, what you just described is exactly what a permutation is. Regardless...

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.

Henry

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.

Henry

Ireneusz Kordal

Ranch Hand

Posts: 423

posted 7 years ago

You can find an overview of various combinatorial algorithms here:

http://cs.utsa.edu/~wagner/knuth/

alaa salameh wrote:yes it's just an algorithm and i need to find an better solution , is that the wrong forum i posted in ???

You can find an overview of various combinatorial algorithms here:

http://cs.utsa.edu/~wagner/knuth/

Campbell Ritchie

Marshal

Posts: 55770

163

posted 7 years ago

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.Ganesh Gowtham wrote:Hi

Please try the below code ...

I hope you don't mind, Rob, Robert and Jesper.

posted 7 years ago

And we have FAQs supporting this policy : LetThemDoTheirOwnHomework and DontBeACodeMill.

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.

And we have FAQs supporting this policy : LetThemDoTheirOwnHomework and DontBeACodeMill.

[My Blog]
*All roads lead to JavaRanch*

posted 7 years ago

HI Campbell Ritchie ,

I thought might helpfull for him ,Since he might have already invested considerable time of this research ...

Correct me if i am wrong ....

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.Ganesh Gowtham wrote:Hi

Please try the below code ...

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 ...

Correct me if i am wrong ....

Thanks, Ganesh Gowtham

http://ganesh.gowtham.googlepages.com

Campbell Ritchie

Marshal

Posts: 55770

163