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:
1. {A1, B2}
2. {A3, B2}
3. {A1, A3, B4, B5}
Now we need to perform filtering. One node can participate only once. For example, if B2
has made a pair with A1
, then 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. And discard sets 1 and sets 2
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?