i'm coding a c project for an algorithm class and i really need some help! Here's the problem:
I have a set of names like this one N = (James,John,Robert,Mary,Patricia,Linda Barbara) wich are stored in an RB tree. Starting from this set of names a series of couple like those ones are formed:
(James,Mary) (James,Patricia) (John,Linda) (John,Barbara) (Robert,Linda) (Robert,Barbara)
Now i need to merge the elements in a way that i can form n subgroups with the constraint that each pairing is respected and the group has the smallest possible cardinality.
With the couples in the example they will form two groups (James,Mary,Patricia) and (John,Robert,Barbara,Linda).
The task is to return the maximum number of groups formed and the number of males and females in the group with the maximum cardinality.
In this case it would be 2 2 2
I was thinking about building a graph where every name is represented by a vertex and two vertex are in an edge only if they are paired. I can then use an algorithm (like Kruskal) to find the Minimum spanning tree.Is that right?
The problem is that the graph would not be completely connected. I also need to find a way to map the names to the edges of the Graph and vice-versa. Can the edges be indexed by a string?
Every help is really appreciated :) Thanks in advice!