3

The famous algorithm for exact cover problem is given by Donald Knuth called Knuth's Algorithm X.

Input: List of subsets of a Universal sets
Output: All the possible disjoint subset whose union is Universal set

Suppose the input is {ab, ac, cd, c, d, a, b}. Is it possible to make the Knuth's Algorithm X such that it will give output according to some predefined block size. For example if {2, 2} is the block size set, it will give output: {ab, cd}, if {2,1,1} is the block size set, it will give output: {ab, c, d}, {ac, b, d} and {cd, b, a}.

NARAYAN CHANGDER
  • 315
  • 3
  • 12
  • I think that the best is to create your own algorithm, you generate all set that respect the predefined block size then you delete those whose union is not Universal set – AnotherGeek Jul 12 '16 at 12:25

1 Answers1

3

You can (optionally) start with removing all subsets from your input list that does not have size in set of block sizes.

The original Knuth's Algorithm X can be altered with the set of block sizes (for example {2, 1, 1}) as a restriction using extensions in bold as follows:

  1. If A is empty and set of block sizes is empty, the problem is solved; terminate successfully.
  2. Otherwise choose a column, c (deterministically).
  3. Choose a row, r, such that A[r, c] = 1 and number of 1s in row r is in the set of block sizes (nondeterministically).
  4. Include r in the partial solution
  5. Remove number of 1s in row r from set of block sizes
  6. For each j such that A[r, j] = 1, Delete column j from matrix A; For each i such that A[i, j] = 1, Delete row i from matrix A.
  7. Repeat this algorithm recursively on the reduced matrix A and reduced set of block sizes.
  • 1
    Thanks I did not think about it. The problem I was facing for block sizes {2,1,1} is it gives all the solution with sizes {2,1,1} but also it gives solution of block sizes {2,2},{1,1,1,1}. I will check this. Hope it will work. Thank you for this solution. I was thinking about the solution using Knuth X but failed. I will check Knuth X according to your way. – NARAYAN CHANGDER Jul 12 '16 at 12:52