what I want to do is to create an algorithm, able to find all the possible bijections between two sets of objects.
A simple example, let’s suppose we have two arrays {1,2,3} {4,5,6}.
The algorithm should give me 3!= 3*2*1 =6 bijections which are the following:
1-4 2-5 3-6 \
1-4 2-6 3-5\
1-5 2-4 3-6\
1-5 2-6 3-4\
1-6 2-5 3-4 \
1-6 2-4 3-5\
Even though it seems simple at first place, I am quite stuck. Is there any standard algorithm in the theory of combinatorics, bijections or permutations to solve this problem?
Thank you in advance.
Christina
You should do it recursively, “choose” one variable from each – and add it to the solution – do it for all possibilities, and narrow your possible choices at each recursive call.
Pseudo code should be something like [assuming |S1| == |S2|]:
Note that it indeed generate
n!possibilities, because for each iteration you have one less element to choose from, resulting in total ofn * (n-1) * ... * 1 = n!possibilities, as expected..