If we have different objects,
[A1, A2, A3, B1, B2, B3, B4, B5]
Some calculations will be performed to find compatible objects. For example, lets assume following 3 sets were formed and every set contains compatible objects:
Now we need to perform filtering. One node can participate only once. For example, if
B2 has made a pair with
B2 can not participate in any other set. Which means, if we select
set 1, then
set 2 will be deleted because
B2 has already participated. And set 3 will be deleted because A1 has already participated.
Now we need to do filtering such that we maximize number of objects being utilized. If we select
set 1, then we are only utilizing
A1 and B2.
Thus, optimal way would be to select
set 3 which is utilizing 4 objects.
Right now, i have a complex function which goes through list of sets recursively and keeps on adjusting until no changes are made to existing sets. This is not only inefficient, but it might not work in cases where changing sets can cause ripple effect.
I am not looking for coded solution, but just a guidance that is there any graph algorithm which I should study?