Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Algorithm for all possible combinations?

1. Algorithm for all possible combinations?

Hi i'm doing a simple translation program built from a a glossary and some statistic from a corpus.
Now i have realized that to get my program to work i need a algorithm that can get all the possible combinations from a N*M array.

EX:
[1(A1,A2,A3,......,An),2(B1,B2,B3,......,Bn),3(C1,C 2,C3,......,Cn),........N(N1,N2,N3,......,Nn)]

I haven't been able to solve this and would really need some help.

2. Re: Algorithm for all possible combinations?

With a N*M array are there N*M different elements and (N*M)! different combinations?

3. Re: Algorithm for all possible combinations?

Sry if i wasn't clear enough. The first array have a unknown amount of arrays in it and everyone of those arrays have an unknown amount of string in them.

4. Re: Algorithm for all possible combinations?

I don't know how to solve the problem then if all the values are unknown.
All arrays in java are defined with a fixed size. They need not be full, but some how you can determine how many elements they contain.

5. Re: Algorithm for all possible combinations?

I think i explained badly again i need the algorithm to work for any amount of values but i will know how many there are for every iteration. For an example
if i need to translate how are you then every word have a couple of different translations that i get from a glossary so the array will be [(all translations of how),(all translation of are),(all translation of you)] .

6. Re: Algorithm for all possible combinations?

Don't see where the talk of combinations comes from. Here is an example of what I thought combinations could be: Given the letters: A,B,C you would get: ABC, ACB, BAC, BCA, CAB, CBA

Can you give a simple concrete example of what you are looking for?

7. Re: Algorithm for all possible combinations?

ok with just two words the sentence in swedish "jag är" translates correctly in english to "I am" but if you look it up in a glossery every word will have more then one translation so "jag" can be translated to "I" and "ego" and "är" can be translated to "am", "are" and "is" so the array will look like this:
[("i","ego"),("am","are","is")]
the possible combinations are:
I am
I are
I is
ego am
ego are
ego is

Then the program will use some statistic to compare the different sentences and hopefully it will get the right one most of the time.

In this case the word did't have that many translation and it was a short sentence but the problem is of course that this can vary alot.

I hope the example is enough and i really appreciate that you are trying to help me.

8. Re: Algorithm for all possible combinations?

Looks like a recursive method could do that. Pass it the array of arrays and have it extract one from each sub array and build the output string.

9. The Following User Says Thank You to Norm For This Useful Post:

affebaffe (December 3rd, 2012)

10. Re: Algorithm for all possible combinations?

thx it worked perfectly!!!