Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Data Structure of Knuth's Dancing Links Algorithm

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.

like image 469
JrL Avatar asked Oct 08 '22 02:10

JrL


1 Answers

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.

like image 88
Don Roby Avatar answered Oct 22 '22 19:10

Don Roby