Results 1 to 4 of 4

Math Help - Search (java) algorithm to get all permutations of two sets

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    2

    Search (java) algorithm to get all permutations of two sets

    Assume I have to sets of numbers e.g.:

    setA: 1,2,3,4
    setB: 10,11,12,13,14,15,16

    Now I want to get all permutations where n (e.g.2) numbers are taken from setA and m (e.g.4) numbers are taken from setB.

    Does someone have an efficient algorithm (preferable implemented in Java) which allows to generate all porssible permutations?

    Peter
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Jan 2010
    Posts
    12
    are they non repeating sets? can you reuse numbers in each set?

    ie setA: 1,1,2,3,4 ->1's repeat
    setB: 12,22,34,44
    reusing numbers combination works
    setA: 1,2,3,4
    setB: 10,11,12,13,14,15,16
    how many 2 number combos setA are they
    is this valid (1,2), (1,3)? --> 1 is not removed from avaliable choices are choosen

    Quote Originally Posted by pstein View Post
    Assume I have to sets of numbers e.g.:

    setA: 1,2,3,4
    setB: 10,11,12,13,14,15,16

    Now I want to get all permutations where n (e.g.2) numbers are taken from setA and m (e.g.4) numbers are taken from setB.

    Does someone have an efficient algorithm (preferable implemented in Java) which allows to generate all porssible permutations?

    Peter
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2010
    Posts
    2
    Quote Originally Posted by canyiah View Post
    are they non repeating sets? can you reuse numbers in each set?
    No, numbers cannot be drawn a second time.
    So there are no duplicates.

    So I am looking for all permutation like (for 2 and 4 draws like described above):

    (1,2, 10,11,12,13),
    (1,3, 10,11,12,13),
    (1,2, 10,11,12,14),
    ....
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by pstein View Post
    Assume I have to sets of numbers e.g.:

    setA: 1,2,3,4
    setB: 10,11,12,13,14,15,16

    Now I want to get all permutations where n (e.g.2) numbers are taken from setA and m (e.g.4) numbers are taken from setB.

    Does someone have an efficient algorithm (preferable implemented in Java) which allows to generate all porssible permutations?

    Peter
    You just need a function that will produce all permutations of n+m distinct elements. Then put that inside a loop that generates all the combinations of n distinct elements from set 1 and m distinct elements from set 2. This requires just a simple double loop.

    If you regard 1, .. n+m as the indices into the array of elements of a set A of size n+m (note I am using unity based arrays here) you need only produce permutations of the index array to get your permutations of the set. There is pre-existing code out there somewhere that will produce all the permutations of [1, .. , n+m] in order.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Fast algorithm for calculating permutations
    Posted in the Statistics Forum
    Replies: 1
    Last Post: December 1st 2010, 08:13 PM
  2. Search Algorithm, Numerical Methods
    Posted in the Advanced Applied Math Forum
    Replies: 2
    Last Post: September 6th 2009, 07:41 AM
  3. Algorithm for computing power sets
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: October 18th 2007, 05:59 AM
  4. Inequalities and log base 2 search algorithm problem
    Posted in the Discrete Math Forum
    Replies: 3
    Last Post: August 29th 2007, 01:20 PM
  5. Binary Search Algorithm
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: November 11th 2006, 10:57 PM

Search Tags


/mathhelpforum @mathhelpforum