# How to group people based on their choices? What algorithms are available?

For example I have eight kids,

A,B,C,D,E,F,G,H


If I ask them to go into groups of two, their choices are

A->B
B->C
C->B
D->B
E->A
F->A
G->H
H->C


How to make sure they get their choices as much as possible?

Or similarly, to get into groups of four:

A->B,C,D
B->A,C,G
C->E,A,D
D->B,E,G
E->F,G,H
F->A,B,C
G->E,F,B
H->F,E,C


I am sure there are many ways to do this. But I just don't know where to start looking for algorithms. What is the mathematical term for such problems?

I'm not sure how easy/how much studied the problem is for grouping people together in groups of $k$ people according to preferences, for $k > 2$. For one thing, there are many ways to define an "optimal solution". Do you want to maximize the number of ordered pairs $(X,Y)$ where $X$ would prefer to be in a group that had $Y$? Or maximize the number of pairs where both $X$ and $Y$ want each other to be in their group? Or maximize the number of $X$ such that $X$ gets everyone they want in their group? Or some weighted combining of these measures? For that matter, you could similarly modify the $k = 2$ case this way too and come up with a different objective than the stable roommates formulation.