Sample Mid-Term Exam

Problem 1

The PARTITION problem is defined as follows: The input is a list L of numbers. The output is either (A) a partition of L into two sets U and V such that the sum of the elements is U is equal to the sum of the elements in V (and therefore equal to half the sum of the elements in L); or (B) the statement that no such partition exists.

For example, given the input [1, 4, 6, 14, 17, 20] the output could be {1, 4, 6, 20}, {14, 17}, since both partitions add up to 31. Given the input [3, 4, 6, 14, 17, 20] the output would be "FALSE" since no such partition exists. Consider the following solution to this problem using state space search: Let M = the sum of the elements in L.

Problem 2

Show the result of carrying out alpha-beta pruning on the game tree shown below.

Problem 3

Convert the following sentence to CNF:
(P <=> Q) => R.
Answer: Going through the important intermediate steps.
[(P => Q) ^ (Q => P)] => R
~[(~P V Q) ^ (~Q V P)] V R
[(P ^ ~Q) V (Q ^ ~P)] V R.
Finally, one attains four clauses
1. P V ~P V R
2. P V ~Q V R
3  Q V ~P V R
4. Q V ~Q V R.
But clauses (1) and (4) are tautologies (true for all valuations, since they have a literal and its negation) and therefore can be dropped.

Problem 4

Trace the workings of the Davis-Putnam procedure on the set of clauses.
1. ~P V Q V R
2. P V ~Q
3. P V ~R
4. ~P V ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
7. ~A V P.
8. ~A V R.
Step 1: ~A is a pure literal. Set A=FALSE. Delete 7 and 8.

Set S1:

1. ~P V Q V R
2. P V ~Q
3. P V ~R
4. ~P V ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
Step 2: No singleton clauses, no pure literals. Try P=TRUE. Delete clauses 2 and 3, delete ~P from 1 and 4.

Set S2:

1. Q V R
4. ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
Step 3: No singleton clauses, no pure literals. Try Q=TRUE. Delete clause 1, delete ~Q from 4 and 5.

Set S3:

4. S
5. R V ~S
6. ~R V ~S
Step 4: 4 is a singleton clause. Set S=TRUE. Delete clause 4, delete ~S from 5 and 6.
5. R
6. ~R
Step 5: 5 is a singleton clause. Set R=TRUE. Delete clause 5, delete ~R from clause 6.

Step 6: 6 is now the empty clause. Fail. Go back to step 3, set S2. Try Q=FALSE. Delete clauses 4, 5. Delete Q from 1.

Set S4.

1. R
6. ~R V ~S
Step 7: 1 is a singleton clause set R=TRUE. Delete clause 1. Delete ~R from 6.
6. ~S.
Step 8: 6 is a singleton clause. Set S=FALSE. Delete 6.

There are now no clauses left, so succeed. Return the current valuation: A=FALSE, P=TRUE, Q=FALSE, R=TRUE, S=FALSE.

Problem 5

Let G be a directed graph. A Hamiltonian path through G is a path through G that includes every vertex exactly once. For example, in the graph shown below, the path [B,C,F,D,A,E] is a Hamiltonian path.

Suppose that we want to build a compiler that turns a Hamiltonian path problem into a problem of satisfiability, which can then be input to Davis-Putnam. This can be done as follows: Let N be the number of vertices in the graph = the number of vertices in the desired path. For each vertex V and number I between 1 and N, construct a propositional atom V_I, meaning that vertex V is in place I in the target path.

Show how the following three types of constraints can be expressed: