<<

Lecture Counting Problems and P

In this lecture we discuss the complexity of counting problems Instead of just

determining whether a solution to a given problem exists wewillbeinterested

in counting the number of dierent solutions to a given problem Counting

problems are naturally asso ciated with many of the decision problems wehave

already discussed The notion of a witness function formalizes this asso ciation

Denition Let w P where P denotes the power set

of and let x We refer to the elements of w x as witnesses for x

We asso ciate a decision problem A with w

w

A fx j w x g

w

In other words A is the set of strings that have witnesses

w

Example Let x b e an enco ding of a Bo olean formula and y

an enco ding of a truth assignment If

w x ftruth assignments satisfying xg

then

A fsatisable Bo olean formulasg

w

Lecture Counting Problems and P

It is p ossible for a counting problem to be harder than the asso ciated

decision problem In order to characterize the additional diculty of these

problems Valiant prop osed a new class of problems called P His def

inition is essentially equivalent to the following

Denition The class P is the class of witness functions w such that

i there is a p olynomialtime algorithm to determine for a given x and y

whether y w x

k

ii there exists a constant k N such that for all y w x jy j jxj

The constant k can dep end on w

The following theorem relates counting problems in this new class to their

asso ciated decision problems

Theorem The fol lowing relationships hold between witness functions in

P and decision problems in NP

i if w P then A NP

w

ii if A NP then there exists a w P such that A A

w

Proof

i Guess a witness y in p olynomial time using Denition ii and

verify in p olynomial time that y is indeed a witness using Denition

i

ii Let M be a nondeterministic Turing machine accepting A Take w x

to b e the set of accepting computation paths of M on input x

It is interesting to observe how counting problems v and w are related

under the pro cess of reduction For this purp ose we intro duce the notion of

counting reductions and parsimonious reductions

Denition Let

w P

v P

be counting problems A polynomialtime manyone counting reduction from

w to v consists of a pair of p olynomialtime computable functions

N N

Lecture Counting Problems and P

such that

jw xj jv xj

When such a reduction exists we say that w reduces to v

Intuitively if one can easily count the number of witnesses of v y then one

can easily count the number of witnesses of w x

Some reductions preserve the number of solutions to a problem exactly

We call such reductions parsimonious Formally

Denition Acounting reduction is parsimonious if is the identity

function

Example Here are a number of examples of parsimonious and non

parsimonious reductions

Co oks Theorem is parsimonious in the sense that the numb er of satisfy

ing assignments to the Bo olean formula constructed in the pro of of the

theorem corresp onds exactly to the number of accepting computations

of the nondeterministic Turing machine b eing simulated

p

The reduction Clique Vertex Cover as presented in a previous lecture

m

is parsimonious the numb er of cliques of G V E ofsize k is the same

as the number of vertex covers of G V E ofsize n k

p

The reduction CNFSat CNFSat as presented in a previous lecture

m

is not parsimonious but it can easily b e made so

p

The reduction CNFSat Clique as presented in a previous lecture is

m

not parsimonious but again can easily be made so

p

Example Weshowhow the reduction CNFSat Clique can b e made

m

parsimonious Recall that we constructed from a given CNF formula B a graph

G with a vertex for each o ccurrence of a literal in B and edges between oc

currences of literals in dierent clauses if the literals were not complementary

The problem with this construction is that one truth assignment might corre

sp ond to several cliques For example the formula

y x y x

has two satisfying assignments but three cliques

We can remedy this by rst replacing each clause

x y z

Lecture Counting Problems and P

in B by the equivalent subformula

xy z xy z x yz x y z xy z xy z x yz

with seven terms The numb er of satisfying assignments is the same since the

formulas are equivalent Now we construct G with one vertex for each of the

seven terms in each of these subformulas and edges connecting terms xy z and

uv w in dierent clauses if the two terms contain no complementary literals

One can show that there is exactly one clique of size k the numb er of clauses

for each satisfying assignment

As with the NP complete problems we can dene the class of P complete

problems that represent the hardest problems in the class P All the counting

problems we have mentioned so far are P complete

One P complete problem is that of of a matrix

t of an n n matrix is the number of ways to Intuitively the p ermanen

place n ro oks on the matrix so that every ro ok sits on a and no ro ok can

capture another Ocially

Denition Given an n n matrix A not necessarily the permanent

of A is the quantity

n

X Y

perm A A

i i

i

S

n

where the are p ermutations of the set f ng and S is the set of all

n

such p erm utations

The denition of the p ermanent of a matrix is very similar to the denition

of

n

X Y

sign

det A A

i i

i

S

n

The only dierence is that the sign of the p ermutation even or odd is

included in the determinant It is thus quite surprising that the p ermanent

should be P complete since the determinant is computable in p olynomial

time by

That the p ermanent is P complete is even more surprising in light of

its relationship to the bipartite matc hing problem Given a

G U V E with jU j jV j n the p ermanent of the n n bipartite

of G gives the number of p erfect matchings Thus despite

the fact that a p erfect can b e found in p olynomial time counting the

number of them is as hard as counting the number of satisfying assignments

to a Bo olean formula

The sign of a p ermutation of f ng is the numb er mo d of pairs that are out of order

Lecture Counting Problems and P

Theorem Valiant The problem of counting the number of

perfect matchings in a bipartite graph is P complete

Actually this problem is P complete with resp ect to a slightly more

general reducibility than the one dened in Denition We will discuss

this later on

Example Consider the following bipartite graph and its asso ciated

bipartite adjacency matrix

a b c

s s

a

H

H

H

H

H

H s s

b

H

H

H

H

H

H s s

c

This graph has exactly three p erfect matchings corresp onding to the three

p ossible legal ro ok placements

s s s s s s

H H

H H

H H

H H

H H

s s s s s s H H

H

H

H

H

H

s s s s s s H

For nonbipartite directed graphs wemight ask what the p ermanentofthe

adjacency matrix represents Here a legal ro ok placement corresp onds to a

cycle cover or a collection of vertexdisjoint cycles containing all vertices The

permanentthus computes the numb er of cycle covers The picture b elow illus

trates the relationship between cycle covers and p ermutations corresp onding

to nonzero terms in the denition of the p ermanent

Lecture Counting Problems and P

s s

s s s s

Lecture Counting Bipartite Matchings

In this lecture we prove that computing the numb er of p erfect matchings in a

bipartite graph is P complete making it at least as dicult as computing

the number of satisfying truth assignments for a Bo olean expression

We noted last time that the number of perfect matchings in a bipartite

graph with the same number of vertices on each side is equal to the permanent

of its adjacency matrix given by

n

Y X

A p erm A

i i

i

S

n

where S is the set of p ermutations of the set f ng For a general

n

directed graph with n vertices and its n n nonbipartite adjacency matrix

the p ermanent gives the number of cycle covers

Our pro of b egins using the same construction that we used to reduce Vertex

Cover to Hamiltonian Circuit Recall that we constructed a graph H from G

built from a set of widgets one for each edge in G

v

s s

s s

u

Lecture Counting Bipartite Matchings

For each vertex u in G the sides of the widgets corresp onding to u are con

nected endtoend to form a u loop The ends of each u lo op are connected to

each element of a set K of k new vertices as shown here k is the size of the

vertex cover in G we are lo oking for

v v v v

R R s s R s s R s s s s

s s s s s s s s

I AK

u u u u

A

A

A

to vertices in K

from vertices in K

Weshowed in Lecture that H contains a Hamiltonian circuit if and only

if G contains a vertex cover of size k However although every Hamiltonian

circuit in H determines a unique vertex cover in G there are in general many

dierent Hamiltonian circuits giving the same vertex cover How many For

each vertex cover C each Hamiltonian circuit corresp onding to C is deter

mined by the connections b etween K and the lo ops corresp onding to C thus

we are essentially lo oking at the numb er of Hamiltonian circuits in a complete

bipartite graph on two sets of k vertices This number is k k since for

each of the k cyclic orderings of the vertices in one of the sets of the

bipartition there are k ways to insert the vertices in the other set so that the

two sets alternate

Similar thinking leads to the conclusion that there are exactly k cycle

covers in H corresp onding to a given vertex cover C in G This is the number

of ways to select two p erfect matchings in a complete bipartite graph on two

sets of k vertices indep endently one to mo del the edges from K to C and the

other to mo del the edges from C to K

It would be nice if these cycle covers corresp onding to vertex covers in

cluded all p ossible cycle covers in H We could immediately conclude that by

computing the p ermanent of the adjacency matrix for H and dividing byk

we could obtain the number of vertex covers in G Alas life is not quite this

simple in fact we are just warming up to the real task

The problem is that the widgets contain cycles of length two that are

included in cycle covers counted by the p ermanent Such cycle covers do

not corresp ond to any vertex cover Let us dene a cycle cover to be bad

if it contains a cycle of length two good otherwise Go o d cycle covers must

traverse widgets prop erly therefore corresp ond to vertex covers as describ ed

ab ove W e can conclude

Theorem The number of good cycle covers in H is k times the num

ber of vertex covers of G of size k

Lecture Counting Bipartite Matchings

Thus we would like to count only the go o d cycle covers of H Unfortu

nately the p ermanent counts all cycle covers go o d and bad We need to

gure out how to prevent bad covers from contributing to the value of the

permanent of the adjacency matrix This leads us to Valiants Excellent Idea

try to assign weights p ossibly negative to the interior edges of widgets

so that the pro duct of the edge weights in each go o d cycle cover is but the

pro duct of edge weights in each bad cycle cover is The p ermanentwillthen

count the number of go o d cycle covers

Unfortunately the task of trying to assign edge weights by trial and error

quickly leads nowhere Even if we throw in more edgesin fact we might

as well consider the complete graph with selflo opsthe problem of assign

ing weights app ears hop eless This brings us to Valiants Excellent Idea

forget the widget itself and lo ok at its adjacency matrix instead and try to

write down the essential prop erties of the matrix that will give us the desired

behavior

Consider the submatrix of the adjacency matrix of H corresp onding

to one copy W of the widget There are columns of H corresp onding to the

input vertices and of W and rows of H corresp onding to the output

vertices and In a bad cycle cover involving the two cycles of length two

in W no edge coming into or or leaving or is part of the cycle cover

In terms of the asso ciated legal ro ok placement this says that the ro oks in

columns and and ro ws and must lie in the submatrix corresp onding to

W Moreover since there are no edges from vertices or to vertices outside

of W ie all entries in rows and outside of the submatrix W are zero

the ro oks in these rows must lie in the submatrix W This says that there are

exactly ro oks on the submatrix W and they form a legal ro ok placement

on W

When this happ ens the remaining ro oks must lie in the complementary

subgraph W of W ie that subgraph of H obtained by deleting the rows

and columns of W The sum of all terms in the p ermanent corresp onding to

cycle covers containing these two cycles is then given by

p erm W perm W

If we could pickweights so that p erm W then the net contribution of all

these cycles to the calculation of the p ermanent would be

With this insight we pro ceed to write down all the conditions on the

adjacency matrix that guarantee the desired behavior The intrawidget con

nections will be as a complete graph with selflo ops and the edges will be

weighted The interwidget connections will be the same as in H with all

edge weights

Lecture Counting Bipartite Matchings

i i

s s R R

I

s Rs

i i

Let A denote the adjacency matrix of this weighted widget the

weights have yet to be determined Let Ai j denote the submatrix of A

obtained by deleting rows i and columns j

The desired behavior can be summarized as follows

perm A p erm A p erm A

p erm A p erm A perm A

rst line insures that the net contribution to the p ermanent of all legal The

ro ok placements corresp onding to a go o d cycle cover in H is The three

permanents corresp ond to the three acceptable ways of traversing the widget in

a go o d cycle cover two zigzag paths and a pair of straight paths The second

line insures that the net contribution of all legal ro ok placements corresp onding

to a bad cycle cover is For example the equation

p erm A

says that the net contribution to the p ermanent of all cycle covers that have

an edge entering the widget at and leaving and no other connections to

the outside is

We do not need to write down any conditions to rule out dierentnumb ers

of entering and leaving edges these cases are already taken care of by the rules

of ro ok placement Essentiallyinany cycle cover the numb er of edges leaving

a subgraph must equal the number of edges entering it

One can now lo ok for a matrix satisfying these constraints There

are many p ossibilities One such is

A

For instance

p erm A perm

Lecture Counting Bipartite Matchings

and

p erm A p erm

The full adjacency matrix B with submatrices A corresp onding to these

fourno de widgets counts for eachgoodcyclecover in H and for each bad

cycle cover thus its p ermanent is equal to k times the number of vertex

covers in G

We have argued that computing the p ermanent of a matrix containing

elements in f g is P hard but there is still a ways to go The next

step is to note that

n

p erm B p erm B

and this implies that computing the p ermanent of a matrix with elements

in f g is hard for P We now show that this problem reduces to

computing the p ermanents of p olynomially many matrices over f g The

reduction we use here is somewhat weaker than the one wehave b een using in

that it will require several instances of the f g permanent problem to enco de

a given instance of the f g p ermanent problem but the reduction still

has the prop erty that any fast algorithm for the f g problem would give a

fast algorithm for the f g problem

Let B be an n n matrix over f g A b ound on the absolute value

of p erm B is given by the case in which each entry of B is then

n

jp erm B j n

n

It thus suces to compute p erm B mo dulo any N n and from this we

will b e able to recover the value of p erm B

Let p p p be the rst k primes where k is the least number such

k

that

k

Y

n

N p n

i

i

It is not hard to show that k n Moreover since p is m log m

m

see p we can generate the rst k primes in p olynomial time using

the sieve of Eratosthenes Before pro ceeding further we need the following

theorem

Theorem Chinese Remainder Theorem Let m m m

k

Q

k

be pairwise relatively prime positive integers and let m m Let Z

i n

i

Lecture Counting Bipartite Matchings

denote the ring of integers modulo n The ring Z and the direct product of

m

rings

Z Z Z

m m m



k

are isomorphic under the function

f Z Z Z Z

m m m m



k

given by

f x x mo d m x mo d m x mo d m

k

This just says that the numb ers mo d m and the k tuples of numb ers mo d m

i

i k are in onetoone corresp ondence and that arithmetic is preserved

under the map f For example in the following table wehave compared Z

to Z Z

x

x mo d

x mo d

Note that each pair in Z Z o ccurs exactly once This is b ecause and

are relatively prime Arithmetic is preserved as well for example and

corresp ond to the pairs and resp ectively multiplying these

pairwise gives the pair mo d and resp ectively whichoccurs under

and mo d



Also f and f are computable in p olynomial time To compute f x



we just reduce x mo dulo m m To compute f x x we rst

k k

compute for each i k integers s and t such that

Y

sm t m

i j

 j  k

j  i

and take

Y

u t m

i j

 j  k

j  i

The numbers s and t are available as a bypro duct of the Euclidean algorithm

ake For each i j k u modm and u modm i j T

i i i j



f x x x u x u mo d m

k k k

For further details and a pro of of the Chinese Remainder Theorem see pp

Lecture Counting Bipartite Matchings

Using the Chinese Remainder Theorem we can compute p erm B by com

puting p erm B mo d p i k For each i i k we replace all

i

entries in B by p mo dulo p they are the same We then compute

i i

the permanent of this matrix and reduce mo dulo p to get perm B mo d p

i i

The advantage of this is that we have now reduced the problem to that of

computing the p ermanents of matrices with small nonnegative entries only

All that remains is to show how to reduce the computation of the p erma

nent of a matrix over f p g to the problem of computing the p ermanent

of a matrix over f g

Recall the equivalence between the p ermanent of a matrix and the cycle

covers of a directed graph We must reduce the problem of computing the

number of cycle covers of a weighted directed graph with p ositive integral

ts to the problem of computing the number of cycle covers of an un weigh

weighted directed graph This is accomplished by replacing every weighted

edge with a subgraph consisting of several new vertices and edges

The following gure shows this construction for an edge of weight

i

s R

H

H

H

i H

s s s s s R Hj

H

H

H

H i

s HjR



The ab ove pro cess is rep eated for each edge in G The resulting graph G is

unweighted Each cycle cover in G involving edges u v with weights m

i i i



i n is simulated by m m m cycle covers in G each of weight

n



thus the p ermanents are the same Also G can b e constructed in p olynomial

time

that the problem of counting the number of This completes the pro of

p erfect matchings in a bipartite graph equivalently counting the number of

cycle covers in a directed graph is P complete