Mark Bennett
Mark Bennett

Reputation: 1474

Question about Knuth's "Dancing Links" / DLX algorithm (in Python)

I've been reading quite a bit about the "Exact Cover" problem and Knuth's solution using heavily linked lists. I think I understand about 70% of it, but still confused on how the linked-lists "cover" and "uncover" are supposed to work.

Knuth's paper: https://www.ocf.berkeley.edu/~jchu/publicportal/sudoku/0011047.pdf

What I understand / have coded already:

Where I'm stuck:

Happy to answer/edit to make the question clearer. Since my code is lengthy and a mess, I'm not planning to post it at this time (unless folks really think it would help, but it's linked lists, exactly like Knuth showed, so I think the code would be a distraction.

So, when using Knuth's linked lists (with column headings), how do you "cover" a column, and more importantly, how do you "cover" a ROW??

Thanks, Mark

Upvotes: 1

Views: 619

Answers (1)

David Eisenstat
David Eisenstat

Reputation: 65488

When they say to "cover" a column, I'm a bit confused. Do I delete (unlink) just the column-heading node for that column, from the list of column header nodes? Or do I remove all the nodes in that column?

The latter -- each column must have exactly one incident row belonging to an exact cover, so those nodes cannot be used in the current subtree.

I'm more confused about Rows. When they say to "cover a row"

I couldn't find that text in Knuth's article. Presumably what is meant is that, when you descend in the solution tree by choosing a row to add to the cover, you need to cover all of its incident columns.

Perhaps a cleaner way to put it is that, when you choose a row, you need to remove all other rows at distance 2 in the bipartite graph corresponding to the incidence matrix.

Upvotes: 1

Related Questions