Non-Recursive Dancing Links
Non-Recursive Dancing Links
References
[1] Donald E. Knuth. Dancing Links. In Jim Davies, Bill Roscoe, and Jim
Woodcock, editors, Millenial Perspectives in Computer Science, pages 187–
214. Palgrave, Houndmills, Basingstoke, Hampshire, 2000. URL http://
www-cs-faculty.stanford.edu/~knuth/preprints.html.
1
Algorithm 1 Dancing Links recursive search.
1: procedure search(k)
2: if h.right = h then
3: Print solution and return. {Base case for the recursion}
4: c ← choose column()
5: cover(c)
6: foreach r ← c.down, c.down.down, . . . , while r 6= c do
7: Ok ← r {Add r to partial solution}
8: foreach j ← r.right, r.right.right, . . . , while j 6= r do
9: cover(j.column)
10: search(k + 1)
11: foreach j ← r.lef t, r.lef t.lef t, . . . , while j 6= r do
12: uncover(j.column)
13: uncover(c)