Lecture 25

Exam review questions:

Prolog

This question is based on an exercise from http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_15.html

One way to represent a graph in Prolog is with a fact for each edge:

edge(1,2).

edge(1,4).

edge(1,3).

edge(2,3).

edge(2,5).

edge(3,4).

edge(3,5).

edge(4,5).

To handle undirected graphs, you can add a rule that says that two vertices are connected if there is an edge between them in either direction:

connected(X,Y) :- edge(X,Y) ; edge(Y,X).

1) Draw a diagram of the undirected graph represented by the rules

above.

2) Write a set of rules for a predicate, clique, that takes a list of vertices and checks whether the vertices

form a clique. For example, in the graph above, clique([1,2,3]) is true and clique([1,3,5]) is no.

P and NP

If there is a deterministic polynomial time decider for some language A, is A in NP?

Let DOUBLE-SAT = { < ϕ > | ϕ is a boolean expression that has at least two satisfying assignments}. Show that DOUBLE-SAT is NP-complete.