The Data Structure of Knuth's Dancing Links Algorithm

2.2k views Asked by At

I am sorry if my question sounds stupid because my data structure understanding is not very good.

I've been reading about Knuth's Dancing Links algorithm and pretty much understand how it basically works. It's mentioned that dancing link's data structure visualization looks like a table with columns and rows, with each cell connected to their above, below, left, and right cells. I've also read that circularly double linked-list is used in this algorithm.

What I want to know is how exactly a double linked-list can be made into such table with columns and rows ?

As i know, most double linked-list has only 2 pointers (up and down), does it mean that i have to make my own custom linked-list which has 4 pointers (up, down, left, and right) ? Or there are other ways ?

Thanks in advance.

1

There are 1 answers

1
Don Roby On BEST ANSWER

The algorithm uses a doubly-linked list for each row and column, not just one list.

This article on using dancing links to solve sudoku has a nice picture.

At least in the code of this article, the rows are indeed represented as left and right pointers and the columns as up and down pointers in the same nodes, more or less as you describe, so the lists are interconnected.