There's a blog post on Steve Rowe's blog that I've been following, applying graph theory to the Secret Santa tradition:
Secret Santa is NP-completeEugen Buehler proposed a constraint that got me thinking. I couldn't come up with an answer immediately, and the post is interesting as a whole, so I thought I'd extend the audience to C9/Techoff.
The general problem (in English and Mathematician-ese:)
Given a bunch of people
(Given a set of vertices V)
... and a set of rules as to who-can-give-to-whom...
(And a set of allowable edges E... thus creating a graph (G, V, E))
... is there a fast algorithm to print out a list of who should give to whom...
(Find a subgraph S in polynomial time)
... so that...
(where)
THE HAMILTONIAN PROBLEM
a) ... the chain forms a single circle?
(S is a single cycle of degree |V|)
THE PASS-THE-HAT PROBLEM
b) ... everyone gives to someone else?
(every vertex in V has degree 2 in S)
EUGEN'S PROBLEM
c) ... everyone gives to someone else, and no-one gives to the person who gave to them?
(every vertex in V has degree 2 in S,
and there are no two-cycles in S)
THE ANSWERS
a) seems to be "no", unless you can add additional constraints... for example, if every vertex has degree at least |V|/2, then you're fine. If you
do find a polynomial algorithm for this, you're on the short list for a Fields medal!
b) seems to be "yes", by the pass-the-hat algorithm
c) is the interesting bit. Any takers?