The example from Algorithm X’s Wikipedia page is as follows:
Set Image may be NSFW.
Clik here to view.
Set Image may be NSFW.
Clik here to view.
Set Image may be NSFW.
Clik here to view.
Set Image may be NSFW.
Clik here to view.
Set Image may be NSFW.
Clik here to view.
Set Image may be NSFW.
Clik here to view.
Is there a set of sets that covers each column exactly once? In this example, the solution is Image may be NSFW.
Clik here to view., since that yields Image may be NSFW.
Clik here to view. — none left out and none duplicated.
Algorithm X is a recursive back-tracking search; it simply tries one set, prunes down the search space, rolls back if it hits a dead end, tries another set. The secret sauce, however, is the data structure and the concept called Dancing Links (my little write-up here).
Implementation reference: Dancing Links, Knuth. If you want to understand my implementation, this reference is a must-read.
My implementation is in git and below: