HackerPapers

arXiv:cs/0011047cs.DS

Dancing links

Donald E. Knuth

Abstract

The author presents two tricks to accelerate depth-first search algorithms for a class of combinatorial puzzle problems, such as tiling a tray by a fixed set of polyominoes. The first trick is to implement each assumption of the search with reversible local operations on doubly linked lists. By this trick, every step of the search affects the data incrementally. The second trick is to add a ghost square that represents the identity of each polyomino. Thus puts the rule that each polyomino be used once on the same footing as the rule that each square be covered once. The coding simplifies to a more abstract form which is equivalent to 0-1 integer programming. More significantly for the total computation time, the search can naturally switch between placing a fixed polyomino or covering a fixed square at different stages, according to a combined heuristic. Finally the author reports excellent performance for his algorithm for some familiar puzzles. These include tiling a hexagon by 19 hexiamonds and the N queens problem for N up to 18.

arXiv comments
Abstract added by Greg Kuperberg
Journal reference
Millenial Perspectives in Computer Science, 2000, 187--214
DOI
Subjects
cs.DSData Structures and Algorithms

On Hacker News

Linked by 13 identifiable commenters in 15 comments across 15 threads, from Feb 2013 to Sep 2026. Found in 4 HN submissions from May 2009 to Jul 2021. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments15 threads

    • Reinventing the wheel is not always to be avoided. Finding an interesting wheel and trying to build your own equivalent can be an excellent way to improve your skills as a programmer [1]. "Feed it to SAT solver" is a super useful technique every seasoned programmer should have…

      csenseView on HNParent context

  1. Simple Sudoku Solvers 1 comment
    • > I implemented branching and backtracking The solvers they describe are indeed based on depth-first search and backtracking; in Python, the backtracking part involves some copying: for v in cands: new_board = [row[:] for row in board] new_board[i][j] = v solved =…

      ventanaView on HNParent context

    • Indeed it is, and Donald Knuth spends a substantial part of the latest volume (4B) of The Art of Computer Programming on solving exact cover problems like this using Dancing Links! He presented an earlier version of the algorithm in this legendary article [1], but as good as…

      OskarSView on HNParent context

    • Neat! Now implement a solver using Knuth's famous Dancing Links algorithm [1]. [1] https://arxiv.org/abs/cs/0011047

      csenseView on HNParent context

  2. In defense of linked lists 1 comment
    • Donald Knuth's Dancing Links paper is a beautiful exploration of the power of linked lists. He uses a table with doubly linked lists (for rows and cols) to solve omino tiling. The linked lists allow for an elegant unpicking of rows (and re-attaching when backtracking) The…

      sprawldView on HNParent context

    • Knuth's Dancing Links is originally from 2001, and was first published to book form in Fasicle 6 (2019). Dancing Links seems to have outstanding performance for a generic cover problem, even on modern cache heavy processors. It seems like the static layout of the links benefits…

      dragontamerView on HNParent context

    • > certain algorithms are more intuitive if implemented imperatively. FWIW, "Dancing Links" is a wonderful technique that would be worse than pointless in an immutable language. https://arxiv.org/pdf/cs/0011047.pdf

      carapaceView on HNParent context

    • On a related note, Knuth has a cool algorithm to solve exact coverage problems like sudoku (similar logic as Norvig's DFS but implemented very differently). It's more work to code it than Norvig's but worth it for the education:) (and it solves faster) Here's the paper…

      pgeView on HNParent context

    • Dancing Links (Knuth's paper: https://arxiv.org/pdf/cs/0011047.pdf ) > In computer science, dancing links is the technique suggested by Donald Knuth to efficiently implement his Algorithm X. Algorithm X is a recursive, nondeterministic, depth-first, backtracking algorithm that…

      carapaceView on HNParent context

    • I found Knuth’s “Dancing Links” paper [1] very well written and a somewhat easy read (I had to reread certain parts a couple times). I had to write a sudoku solver for one of my classes and I read that dancing links and algorithm x was one way to do it [2]. I then read some…

      johnsonjoView on HNParent context

    • Interestingly, when I run this through an old Dancing Links [1] based solver I wrote a while back for solving general puzzles, it solves the first one in 0.04 seconds, uses 65 columns, 242 rows, does 181510 de-queues, and finds a unique solution. The same solver on the hard…

      ChrisLomontView on HNParent context

    • Dancing Links - Donald Knuth - http://arxiv.org/abs/cs/0011047 Lots of fun and is a weekender, but you can expand it to solve anything from sudoku to all kinds of tiling problems. David Goodger's webpage, http://puzzler.sourceforge.net/, solves all sorts of polyform puzzles…

      relaunchedView on HNParent context

    • http://oeis.org/A000170 hints that there is no such algorithm: "Strong conjecture : there is a constant c around 2.54 such that a(n) is asymptotic to n!/c^n" That would imply that a(n) grows faster than polynomial. That, in turn, would mean that merely counting the number of…

      SomeoneView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.