• No results found

Counting unlabelled subtrees of a tree is #P complete

N/A
N/A
Protected

Academic year: 2020

Share "Counting unlabelled subtrees of a tree is #P complete"

Copied!
11
0
0

Loading.... (view fulltext now)

Full text

(1)

Original citation:

Goldberg, Leslie Ann and Jerrum, Mark (1999) Counting unlabelled subtrees of a tree is

#P-complete. University of Warwick. Department of Computer Science. (Computer

Science Research Report). CS-RR-364

Permanent WRAP url:

http://wrap.warwick.ac.uk/61091

Copyright and reuse:

The Warwick Research Archive Portal (WRAP) makes this work by researchers of the

University of Warwick available open access under the following conditions. Copyright ©

and all moral rights to the version of the paper presented here belong to the individual

author(s) and/or other copyright owners. To the extent reasonable and practicable the

material made available in WRAP has been checked for eligibility before being made

available.

Copies of full items can be used for personal research or study, educational, or

not-for-profit purposes without prior permission or charge. Provided that the authors, title and

full bibliographic details are credited, a hyperlink and/or URL is given for the original

metadata page and the content is not changed in any way.

A note on versions:

The version presented in WRAP is the published version or, version of record, and may

be cited as it appears here.For more information, please contact the WRAP Team at:

(2)

is #P-omplete

Leslie Ann Goldberg y

Mark Jerrum

z

November 26, 1999

Abstrat

The problemof ounting unlabelled subtreesof a tree (i.e., subtreesthat aredistint up to isomorphism) is #P-omplete, and hene equivalent in omputationaldiÆultyto evaluating thepermanent ofa 0,1-matrix.

ThisworkwassupportedinpartbytheESPRITWorkingGroup21726\RAND2"andby EPSRCgrantGR/L60982.ResearhReport364,DepartmentofComputerSiene,University ofWarwik,CoventryCV47AL,UK(Nov1999).

y

leslieds.warwik.a.uk, http://www.ds.warwik.a.uk/leslie/, Department ofComputerSiene, UniversityofWarwik,Coventry,CV47AL,UK

z

(3)

Valiant's omplexity lass #P [10℄ stands in relation to ounting problems as NP does to deision problems. A funtion f :

! N is in #P if there is a nondeterministi polynomial-time Turing mahine M suh that the number of aepting omputations of M on input x is f(x), for all x 2

. A ounting problem,i.e., a funtion f :

! N, is said to be #P -hard if every funtion in #Pispolynomial-timeTuringreduibletof;itisompletefor#Pif,inaddition, f 2#P . A#P-ompleteproblemisequivalentinomputationaldiÆultytosuh problemsasountingthe numberofsatisfyingassignmentstoaBooleanformula, or evaluating the permanent of a 0,1-matrix, whih are widely believed to be intratable. Forbakgroundinformationon#P and itsompleteness lass, refer toone of the standard texts, e.g., [3, 8℄.

The main result of the paper|advertised in the abstrat, and stated more formallybelow|is interesting ontwoounts. First,itprovidesarare exampleof a naturalquestion about trees whihis unlikelyto be polynomial-timesolvable. (Twootherexamplesaredeterminingavertexorderingofminimumbandwidth[1, 4℄,ordeterminingthe\harmonioushromatinumber"[2℄.) Seond,itis,asfaras weare aware, the rst intratability resultonerning the ounting of unlabelled strutures.

Some denitions. By rooted tree (T;r) we simply mean a tree T with a distinguishedvertexr,theroot. Anembedding ofatreeT

0

inatreeT isainjetive map fromthe vertex set of T

0

to the vertex set of T suh that ((u);(v))is an edgeof T whenever(u;v) isa edgeof T

0

. SometimesT 0

and T willbe rooted, in whih ase wemay insist that maps the root r

0 ofT

0

tothe root r=(r 0

) of T. Wenowdeneasequene ofproblems leadingtoone ofinterest; wedonotlaim that both the intermediateproblems are partiularlynatural.

Name. #BipartiteMathings.

Instane. Abipartite graphG.

Output. The number of mathings of all sizes inG.

Name. #CommonRootedSubtrees.

Instane. Two rooted trees, (T 1

;r 1

) and (T 2

;r 2

).

Output. The number of distint (up to isomorphism) rooted trees (T;r) suh that (T;r) embeds in (T

1 ;r

1

) and (T 2

;r 2

) with r mapped to r 1

and r 2

, respetively.

Name. #RootedSubtrees.

Instane. Arooted tree, (T;r).

Output. The number of distint (up to isomorphism) rooted trees (T 0

;r 0

) suh that(T

0 ;r

0

)embeds in(T;r) with r 0

(4)

Instane. Atree T.

Output. The number of distint(up to isomorphism)subtrees of T.

Wewilluse eahoftheproblemnamesinanobviouswaytodenoteafuntion frominstanes tooutputs: thus #RootedSubtrees(T;r) denotes the number of distint rooted subtrees of the rooted tree (T;r). Our main result is the following.

Theorem 1 #Subtrees is #P-omplete.

Proof. #BipartiteMathings is the sixth problem on Valiant's original list of #P -omplete problems [10℄. So #P -hardness of #Subtrees follows from Lemmas 2{4 and from the transitivity of polynomial-time Turing reduibility. We will now show that #Subtrees is in #P . Suppose that T is a tree with vertex set V

n = fv

0 ;:::;v

n 1

g. We will order the verties in V n

so that v i

< v j i i < j. For every (labelled) subtree T

0

of T, let V(T 0

) denote the vertex set of T

0

. We willsay that subtree T 00

is larger than subtree T 0

if and only if there isa vertex v

i 2V

n

suh that v i

2V(T 00

), v i

62V(T 0

) and

V(T 0

)\fv i+1

;:::;v n

g=V(T 00

)\fv i+1

;:::;v n

g:

LetT 00

beasubtreeofT. EitherT 00

isthesmallestsubtreeofT initsisomorphism lass orthere isa vertex v

`

2V(T 00

) suhthat the sub-forest F `

of T indued by vertex set

fv i

2V n

jv i

<v `

g[fv i

2V(T 00

)jv i

>v `

g

ontains a tree isomorphi to T 00

. Thus, one an determine whether T 00

is the smallest subtree of T in its isomorphism lass by solving subgraph isomorphism withinputsF

` andT

00

forallv `

2V(T 00

). SineF `

isaforestandT 00

isatree,this an be done in polynomial time [3℄ using the method of Edmonds and Matula. It is now simple to desribe the #P omputation: With input T, eah branh piks a subtree T

00

of T and rejets unless T 00

is the smallest subtree of T inits isomorphismlass.

2 The redutions

Denote by T

the relation \ispolynomial-timeTuring reduible to."

Lemma 2

#BipartiteMathings T

(5)

1

r 1

2

r 2 r

r r r

r

r r r

x

0;0

::: x i;0

::: x n 1;0

y 0;0

::: y j;0

::: y n 1;0

r

r

r r r r

x 0;n

2 +1

x i;n

2 +i+1

x n 1;n

2 +n

y 0;n

2 +n

y j;n

2 +n

y n 1;n

2 +n r

r r

x i;in+j

r y

j;in+j

Figure1: TheskeletonoftreesT 1

andT 2

,illustratingthepresene ofedge(u i

;v j

) inG.

Proof. LetGbeaninstaneof#BipartiteMathingswithvertexsetsfu 0

;:::; u

n 1

g and fv 0

;:::;v n 1

g. From G, we onstrut two rooted trees, (T 1

;r 1

) and (T

2 ;r

2

),eah based ona xed skeleton. The skeleton of T 1

has vertex set

fx i;j

:0in 1 and 0j n 2

+i+1g[fr 1

g;

and edge set

f(x i;j

;x i;j+1

):0in 1and 0j n 2

+ig[f(r 1

;x i;0

):0in 1g:

Informally, the skeleton of T 1

onsists of n paths of dierent lengths emanating from the root r

1

, as illustrated in Figure 1. These n paths orrespond to the n verties fu

i

(6)

2 1 equallength. It has vertex set

fy i;j

:0in 1 and 0j n 2

+ng[fr 2

g;

and edge set

f(y ij

;y i;j+1

):0in 1 and 0j n 2

+n 1g[f(r 2

;y i;0

):0in 1g:

The n paths emanating fromr 2

orrespond to the to the n verties fv i

g of G. ThetreesT

1 andT

2

themselvesarebuiltby addingtotherespetiveskeletons ertainedges enoding the graph G. Speially, for eah edge (u

i ;v

j

) of G, we add an edge from a new vertex to vertex x

i;in+j of T

1

and add an edge from a new vertex tovertex y

j;in+j of T 2 . Let T

denote the set of all nite (unlabelled) rooted trees (T;r) that have leaves at all distanes in the range [n

2 +2;n

2

+n+1℄from the rootr. For any rootedtree (T;r),letT(T;r)denotethe setof all(unlabelled)rootedsubtrees of (T;r). Thus, the quantity #RootedSubtrees(T;r) is just the size of T(T;r). We rst observe that there is a bijetion between the set of mathings (of all sizes) in G and the set T(T

1 ;r

1

)\T(T 2

;r 2

)\T

, and then onlude the proof by showing howtoompute the size of T(T

1 ;r

1

)\T(T 2

;r 2

)\T

usinganorale for#CommonRootedSubtrees.

Consider some tree (T;r) 2T(T 1

;r 1

)\T(T 2

;r 2

)\T

. From the denition of T

we see that T must ontain the entire skeleton of T 1

. In addition, T may ontain up to n additional pendant edges. Any pendant edge must be attahed tothe skeleton ata vertex atdistane in+j+1fromtherootr,where (u

i ;v

j

)2 E(G). Furthermore, if there are pendant edges at distanes in+j +1 andi

0 n+j

0

+1fromtheroottheni6=i 0

and j 6=j 0

. Thus, every suhrootedtree (T;r)maybeinterpretedasamathinginG,andvieversa. Thisisthesoughtfor bijetionbetweentheset ofmathingsinGandthe setT(T

1 ;r

1

)\T(T 2

;r 2

)\T

. To onlude, we just need to show how ompute the size of the latter set using anorale for#CommonRootedSubtrees.

Let Lbe the set of all leaves in (T 1

;r 1

) whose distanes from the root r 1

are intherange [n

2 +2;n

2

+n+1℄. LetU bethe set ofall verties in(T 2

;r 2

)whose distanesfromr

2

are inthe range[n 2

+2;n 2

+n+1℄. Foreahj 2f0;:::;ng, let T

j 1

be the tree formed from(T 1

;r 1

) by adorningevery vertex in Lwith a tuft of n+j edges and letT

j 2

be the tree formed from(T 2

;r 2

)by adorningevery vertex inU with atuftof n+j edges. Bythephrase\adorningavertex v withatuftof tedges"we meanthe following: reatetnew vertiesand addanedge fromeah of these new verties to v." For k 2 f0;:::;ng, let a

k

be the number of rooted trees inT(T

0 1

;r 1

)\T(T 0 2

;r 2

)that have k verties of degreen+1. Clearly,

a n

=jT(T 1

;r 1

)\T(T 2

;r 2

)\T

(7)

n edSubtrees.

We laim (and shall justify presently) that

jT(T j 1

;r 1

)\T(T j 2 ;r 2 )j= n X k=0 a k

(j+1) k

: (1)

Thus, we an use an orale for #CommonRootedSubtrees to evaluate the left-handside of 1 atj =0;:::n; then we an ompute a

n

by Lagrange interpo-lation.

1

It remainsto prove equation (1). Wedene a projetion funtion

:T(T j 1

;r 1

)\T(T j 2

;r 2

)!T(T 0 1

;r 1

)\T(T 0 2

;r 2

)

as follows. For any rooted tree (T;r) in the domain, (T 0

;r) = (T;r) is the maximum r-rooted subtree of (T;r) that has no vertex of degree greater than n+1. To see that T

0

is uniquely dened, onsider an embedding of (T;r) into (T

j 1

;r 1

). Theonlyvertiesofdegreegreaterthann+1arethosewhiharemapped to tufts. Thus, (T

0

;r) is obtained from (T;r) by pruning tufts with more than n pendant edges down to exatly n pendant edges. Notealso that the resulting tree (T

0

;r) an be embedded in both (T 0 1

;r 1

) and (T 0 2

;r 2

), so is indeed well dened.

How large is 1

(T 0

;r)? To every tuft with exatlyn pendant edges we may addany numberof pendant edges,from 0toj. All the tuftsare distinguishable, beausethey are allatdistintdistanesfromthe rootr. Thusallthesepossible augmentations lead to distint trees, and

1 (T

0

;r) = (j+1) k

, where k is the number of verties in (T

0

;r) of degree n+1. Thus, eah of the a k

rooted trees in T(T

0 1

;r 1

)\T(T 0 2

;r 2

) with k verties of degree n+1 are mapped by 1

to (j+1)

k

trees inT(T j 1

;r 1

)\T(T j 2

;r 2

). The lemma follows.

Lemma 3

#CommonRootedSubtrees

T

#RootedSubtrees:

Proof. Suppose that (T 1

;r 1

) and (T 2

;r 2

) onstitute an instane of #Common-RootedSubtrees. Let(T;r)betherootedtreeformedbytakingT

1 andT

2 and adding a new root, r, and edges (r;r

1

) and (r;r 2

). For notational onveniene, introdue the followingquantities:

N 1 = #RootedSubtrees(T 1 ;r 1 ); N 2 = #RootedSubtrees(T 2 ;r 2 ); N = #RootedSubtrees(T;r); and 1

(8)

1 1 2 2

We start by observing that

N =1+N 1

+N 2

C+N 1

N 2

C

2

:

To see this, note that (T;r) has

one distintsubtree inwhihthe degreeof r is0, and

N

1 +N

2

C distint subtrees inwhih the degree of r is1, and

N

1 N

2 C

2

distintsubtrees inwhih the degreeof r is2.

Thus, C(C+1)=2Z, where Z denotes

1+N 1

+N 2

+N 1

N 2

N:

ToomputeC,rst alulateZ usinganoralefor#RootedSubtrees. Then, observe that

C 2

<2Z <(C+1) 2

;

so C is the integer square root of 2Z, whih an be omputed in (logZ) time. NotethatlogZispolynomialinthesizeoftheinput,sine,forexample,N

1

2

n 1

, wheren

1

isthe number of verties in T 1

.

Lemma 4

#RootedSubtrees

T

#Subtrees:

Proof. For any i, an \i-star" is a tree onsisting of one (entre) vertex with degreei and i (outer)verties, eahof whih has degree 1.

Suppose that(T;r)isaninstaneof #RootedSubtrees. Letdenotethe maximum degree of a vertex in T. Let T

0

be the tree formed from T by taking a new ( +3)-star, and identifying one of the outer verties with r. Let T

00 be the tree formed from T by taking a new (+2)-star, and identifying one of the outer verties with r. Let N

0

denote #Subtrees(T 0

) and let N 00

denote #Subtrees(T

00

). Then #RootedSubtrees(T;r) is equal to N 0

N 00

, so it an be omputed using anorale for #Subtrees.

3 Some onsequenes

Following Valiant [10℄, we say that a funtion f :

! N is in FP if it an be omputedby adeterministi polynomial-timeTuring mahine. We say that itis inFP

g

foraproblemg ifitan be omputedby adeterministipolynomial-time Turingmahine whih isequipped with anorale forg. Finally,wesay that itis inFP

A

fora omplexity lass A if there issome g 2A suh that f 2FP g

(9)

Instane. Agraph G.

Output. The numberof distint(up to isomorphism)onneted subgraphs ofG.

Corollary 5 #ConnetedSubgraphs is omplete for FP #P

.

Proof. #ConnetedSubgraphs is FP #P

-hard by Theorem 1. We will show that #ConnetedSubgraphs is in the lass FP

span-P

, whih will be dened shortly. The result willthen followby Toda's theorem [9℄.

We start by dening the relevant omplexity lasses. A funtion f :

!N is in the lass span-P [7℄ if there is a polynomial-time nondeterministi Turing mahine M (withan outputdevie) suh thatthe numberof dierent aepting outputsof M oninput x isf(x), for all x2

. A funtion f :

! N is in #NP if there is a polynomial-time nondeter-ministi Turing mahine M and an an orale A 2 NP suh that the number of aepting omputationsof M

A

oninput x is f(x), forall x2

. The lasses #P ,span-P, and #NP are related [7℄ by

#P span-P#NP :

Thus,

FP #P

FP

span-P

FP

#NP :

As Welsh notes [11, eq. (1.8.6)℄, the identity

FP #P

=FP #NP

: (2)

follows from Toda's theorem [9℄. Thus,

FP #P

=FP span-P

:

(To verify (2) independently, start with Toda's Theorem 4.10, onerning the omplexity lasses PH and PP. Then the required inlusion FP

#NP

FP

#P

followsvia alittlemanipulationinvolvingtheelementaryrelationshipsNPPH and FP

PP =FP

#P .)

We now omplete the proof by showing that #ConnetedSubgraphs is inFP

span-P

. LetN(G;k) denotek! times the number of distint (up to isomor-phism)onneted size-k subgraphs of G. Sine

#ConnetedSubgraphs(G)=

n X

k=1 1 k!

N(G;k);

(10)

abijetion from the vertiesof H to the set fv 1

;:::;v k

g,and

apermutation of v 1

;:::;v k

.

Let H 0

be the graph formed from H by relabelling eah vertex v of H with the label(v). If is anautomorphismofH

0

then (H 0

;) isoutput. Otherwise, the branh rejets. The result now follows from Burnside's Lemma, whih implies that for any given isomorphism lass of k-vertex graphs, the number of graphs inthe isomorphismlass times the number of automorphismsof any member of the lass is equal tok!. (Forexample, see [5℄.)

Let#GraphSubtreesbethe problemof ounting unlabelled subtrees of a graph. Formally, letitbedened asfollows.

Name. #GraphSubtrees

Instane. Agraph G.

Output. The number of distint(up to isomorphism)subtrees of G.

Corollary 6 #GraphSubtrees isomplete for FP #P

.

Proof. This is the same as the proof of Corollary 5, exept that the span-P omputation rejets any subgraph H whih is not a tree. A more diret proof ould be obtained by using a polynomial-timeanonial labelling algorithm for trees suh as the one by Hoproftand Tarjan[6℄.

Referenes

[1℄ G.Blahe, M. Karpinski and J. Wirtgen, On approximation intratability of thebandwidthproblem,EletroniColloquiumonComputationalComplexity, ReportTR98-014, 1998.

[2℄ K.J.EdwardsandC.J.H.MDiarmid,Theomplexityofharmonious olour-ingfor trees, Disrete Applied Mathematis 57 (1995),133{144.

[3℄ M. R. Garey and D. S. Johnson, Computers and Intratability: A Guide to the Theory of NP-Completeness,Freeman, San Franiso, CA,1979.

[4℄ M.R. Garey,R.L. Graham,D. S.Johnson andD. E.Knuth, Complexity re-sultsforbandwidthminimization,SIAM Journalon AppliedMathematis 34 (1978),477{495.

(11)

ACM 21 (1974)549{568.

[7℄ J. Kobler, U. Shoning and J. Toran, On ounting and approximation, Ata Informatia 26 (1989) 363{379.

[8℄ C. H. Papadimitriou,Computational Complexity, Addison-Wesley, 1994.

[9℄ S. Toda, PP is as hard as the polynomial-time hierarhy, SIAM Journal on Computing 20 (1991), 865{877.

[10℄ L.G.Valiant,Theomplexityofenumerationandreliabilityproblems,SIAM Journal on Computing 8 (1979),410{421.

References

Related documents

A-a: Alveolar-arterial difference; ABG: Arterial blood gas; ARDS: Acute respiratory distress syndrome; C a O 2 : Arterial blood oxygen content; C c’ O 2 : End-capillary blood

Further, the current study explored which aspects of Teacher Support (i.e., Instrumental, Emotional, Appraisal, Informational), Classmate Support (i.e., Instrumental,

See Nielsen and Hunter’s (this issue) discussion of “sequential and informational complementarity”. The issue of performance management and evaluation as competing management tools

For the SYM-PART3 problem, low-fitness clusters with only a few solutions are formed on local Pareto sets that exist in between the global Pareto sets, which is caused by the

1993 * Co-Chairman Annual Training Conference, Illinois Chapter I.A.A.I., Urbana, IL * Instructed Arson Awareness at Annual Macon County Fireman's Training. School,

To append data, a client first determines the next available position in the shared log – using a sequencer node as an optimization for avoiding contention with other appending

As a proof of concept, DAGR (Data Analytics for Smart Grids), a prototype solution for PQ monitoring based on IEC 61850-9-2 Sampled Value (SV) stream data was

The studies discussed here show that network relations can lower transaction costs by introducing trust; that they can be a mechanism for effective sanc­ tioning and thereby