0

Assume that the number of variables N and the number of clauses K are equal. Find an algorithm that returns the number of different ways to satisfy the clauses.

I read that SAT is related to Independent Sets.

jas7
  • 2,893
  • 6
  • 23
  • 36
  • Is this homework? – Georg Schölly Jan 29 '17 at 07:50
  • @GeorgSchölly No, it's not homework. I'm learning algorithms to prepare for job interviews. – jas7 Jan 29 '17 at 07:55
  • Does this come under #P (https://en.wikipedia.org/wiki/Sharp-P?) I know you have a restriction that the number of variables is equal to the number of clauses, whereas I would normally expect more clauses than variables. However a problem with few variables could always be padded out by adding clauses such as (X|Y|Z|...) where X,Y,Z... are variables not previously used. – mcdowella Jan 29 '17 at 12:17

1 Answers1

2

A function with N variables has a truth-table with 2^N rows. Each row corresponds to one minterm which can be either a solution or not.

A clause with N variables excludes exactly one of the minterm as part of the solutions. That is the minterm which consists of all inverted variables of the clause.

Provided, the K clauses are all different,

the number of solutions is 2^N - K


Example:

The K=3 clauses with N=3 variables:

 A or  B or  C
!A or  B or  C
 A or  B or !C

The truth-table for three inputs:

A  B  C  output
0  0  0  0         //  excluded by A or B or C
0  0  1  0         //  excluded by A or B or !C
0  1  0  1
0  1  1  1
1  0  0  0         //  excluded by !A or B or C     
1  0  1  1
1  1  0  1
1  1  1  1

Five of the possible eight terms remain true. Thus, the example has 2^3 - 3 = 5 solutions.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54