2

Right now I am working on my implementation of the D.Kuth DLX algorithm/data structure.

I know what is exact cover and how Dancing links works. But I have a question on his paper:

On page 5, he describes the implementation of the algorithm. And there, his "data object x" nodes have "C field" that points to the column object at the head of the relevant column. But I don't fully understand why he needs it and how he uses it? And the same goes for the "C filed" for the "column object".

typedef struct Data{
  struct Data *left, *right, *up, *down;
  struct Column *c;
} Data;

typedef struct Column{
  struct Column *left, *right, *up, *down;
  struct Data *c;
  int size, name;
} Column;
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Soul Bruteflow
  • 115
  • 2
  • 8

1 Answers1

3

The pointer you're talking about points to a header object that's used to indicate how many objects there are in the column (equivalently, how many 1s are in that column of the matrix). This is used so that the algorithm can heuristically determine which column to choose in the "choose a column deterministically" step, since you might want to do something like "choose the column with the fewest entries in it." The C fields make it easy to update the column headers when you splice a row out of the matrix: for each entry that's removed, follow the C pointer to the column header and decrement the counter there; for each entry that's reinserted, follow the C pointer to the column header and increment the counter there.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • What about the "C field" of the "column object"? I didn't found the way he uses it. Does he use it as a head pointer to this column? – Soul Bruteflow Jan 26 '17 at 07:24
  • I don't believe the C field for the header cells is used. It's only relevant for the cells in that column, to easily point back to their column header. Without this direct reference back to the header, you can iterate the up links until you reach the header (implying that there's some other property or type of the header cells themselves so you know when you've iterated the up links far enough to reach the header). If each cell has a link directly back to the column header, that obviously avoids the need iterate the up links to get back to the header. – Kevin Hooke Jan 20 '19 at 18:00