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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Algorithm for all possible combinations?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Algorithm for all possible combinations?

    With a N*M array are there N*M different elements and (N*M)! different combinations?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    affebaffe (December 3rd, 2012)

  10. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Algorithm for all possible combinations?

    thx it worked perfectly!!!

Similar Threads

  1. Scheduling algorithm
    By thesasantos in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 10th, 2012, 09:47 AM
  2. all i need is algorithm
    By coder.freak in forum Paid Java Projects
    Replies: 3
    Last Post: April 6th, 2011, 11:11 AM
  3. [SOLVED] Algorithm Help
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2010, 04:12 PM
  4. algorithm
    By AmmrO in forum Algorithms & Recursion
    Replies: 13
    Last Post: September 24th, 2009, 09:18 PM
  5. All possible combinations of a 1D array
    By Gabriel in forum Collections and Generics
    Replies: 2
    Last Post: August 11th, 2009, 10:35 PM