Faster Algorithms for Finding and Counting Subgraphs

In this paper we study a natural generalization of both {\sc $k$-Path} and {\sc $k$-Tree} problems, namely, the {\sc Subgraph Isomorphism} problem. In the {\sc Subgraph Isomorphism} problem we are given two graphs $F$ and $G$ on $k$ and $n$ vertice…

Authors: Fedor V. Fomin, Daniel Lokshtanov, Venkatesh Raman

Faster Algorithm s for Finding and Counting Subgrap hs Fedor V . Fomin ∗ Daniel Lokshtanov ∗ V enkatesh Raman † B. V . Ragha vendra Rao † Saket Saura bh ∗ Abstract Giv en an input graph G and an integer k , th e k - P A T H prob lem asks whe ther there exists a path of leng th k in G . The co unting version o f the problem , # k - P A T H asks to find the num ber of path s of leng th k in G . Recently , there has be en a lot of work on find ing and cou nting k -sized paths in an in put graph . Th e curre nt fastest (rand omized) algorithm for k - P A T H has b een given by W illiams and it ru ns in time O ∗ (2 k ) [ IPL, 2009 ]. The randomize d algorithm for fin ding a k -path in th e input graph was recen tly generalized by Koutis and W illiams fo r testing whe ther there exists a sub graph in the input graph which is isomorphic to a giv en k -vertex tree [ ICALP , 2009 ]. Bj ¨ orklun d, Husfeldt, Kaski, and K oivisto [ ESA , 2009 ] g av e a determin istic algorith m for # k - P A T H run ning in time and space O ∗ (  n k/ 2  ) o n a n input g raph with n vertices and gav e a po lynom ial space algor ithm run ning in time O ∗ (3 k/ 2  n k/ 2  ) . In this pap er we study a natural ge neralization of bo th k - P A T H and k - T R E E prob lems, namely , the S U B G R A P H I S O M O R P H I S M pr oblem. In the S U B G R A P H I S O M O R P H I S M prob lem we are g iv en two g raphs F an d G on k and n vertices respectively as an input, and th e qu estion is wheth er there exists a subgraph o f G isomor phic to F . W e show that if the treewidth of F is at most t , then th ere is a rand omized algorithm for the S U B G R A P H I S O M O R P H I S M pr oblem runn ing in time O ∗ (2 k n 2 t ) . T o do so, we associate a ne w multiv ariate Homomor phism p olynom ial of degree at most k with the S U B G R A P H I S O M O R P H I S M pr oblem an d construct an arithm etic cir cuit o f size at most n O ( t ) for th is p olynom ial. Using this polyno mial, we also give a deterministic algorith m to count the number of homomo rphisms from F to G that takes n O ( t ) time and uses poly nomial space. For the cou nting version of the S U B G R A P H I S O M O R P H I S M prob lem, wh ere the objective is to c ount the nu mber of distinct subgra phs o f G tha t are isom orphic to F , we g iv e a de terministic algorith m runnin g in time and space O ∗ (  n k/ 2  n 2 p ) or  n k/ 2  n O ( t log k ) . W e also g iv e an algorithm run ning in time O ∗ (2 k  n k/ 2  n 5 p ) and taking space polynomial in n . Here p and t d enote the pathwidth and the treewidth of F , respectiv ely . T hus our work not only improves on known results on S U B G R A P H I S O M O R P H I S M but it also e xtends and generalize most of the known results on k - P AT H and k - T R E E . 1 Introd uction In this p aper w e conside r the classical problem of finding and c ounting a fix ed pattern g raph F on k ver tices in an n -ve rtex host gr aph G , w hen we restrict the treewid th of the pattern graph F by t . More precis ely the pro blems we consider are the S U B G R A P H I S O M O R P H I S M problem an d the # S U B G R A P H I S O M O R P H I S M problem. In the S U B G R A P H I S O M O R P H I S M problem w e are gi ven two graphs F and G on k and n v ertices respe cti vel y as an input, and the question is whether th ere exis ts a subgr aph in G which is isomorph ic to F . In the # S U B G R A P H I S O M O R P H I S M prob lem the objecti ve is to count the number of distinc t subgraphs of G that are isomorphic to F . Recently # S U B G R A P H I S O M O R P H I S M , i n particu lar when F h as bo unded tree width, has fou nd ap plicatio ns in the study of biomolecular network s. W e re fer to Alon et al. [2] and referenc es there in for further details. ∗ Department of Informatics, Univ ersity of Bergen, Norwa y . { fedor.fomin|d aniello|saket } @ii.uib.no . † The Institute of Mathematical Sciences, Chennai, India. { vraman|bvrr } @ims c.res.in . 1 In a seminal paper Alo n et al. [4] introduced the meth od o f C O L O R - C O D I N G for the S U B G R A P H I S O M O R P H I S M problem, when the tree width of the p attern graph is boun ded by t and obtain ed random- ized as well as deterministic algorithms running in time 2 O ( k ) n O ( t ) . T his algorithm was derandomized using k -perfect hash familie s. In particul ar , Alon et al. [4] g a ve a randomized O ∗ (5 . 4 k ) 1 time alg orithm and a determini stic O ∗ ( c k ) time algorithm, where c a large constant, for the k - P A T H probl em, a special case of S U B G R A P H I S O M O R P H I S M where F is a path of length k . Using this a lgorith m for k - P A T H , Alon et al [4 ] also resolve d a conjecture of Papadimitriou and Y annakak is [22] that for k = O (log n ) , the k - P A T H prob lem can be solved in polynomial time. There has been a lot of effo rts in parameterized algori thms to reduce the base of the e xponent of both det erministic as well as the randomized algo rithms for the k - P A T H problem. In the first of s uch attempts, Che n et a l. [11] and Kneis at al. [19] independen tly disco ve red the m ethod of D I V I D E A N D C O L O R and ga ve a rando mized algorith m for k - P A T H running in time O ∗ (4 k ) . Chen et al. [11] also gav e a determinist ic algorithm running in time O ∗ (4 k + o ( k ) ) using an applic ation of un iv ersal sets. While t he best kno wn deterministic algorith m for k - P A T H probl em still runs in time O ∗ (4 k + o ( k ) ) , the base of the expon ent of the randomized algorithm for the k - P A T H pr oblem has seen a drastic improveme nt. Koutis [20] introduced an algebraic approach based on group algebras for k - P A T H and ga ve a nove l rand omized alg orithm runn ing in time O ∗ (2 3 k/ 2 ) = O ∗ (2 . 83 k ) . W illiams [24 ] augment ed the approac h of K outis [20] with more random choices and sev eral other ideas and ga ve the curren t f astest algorith m for k - P A T H running in time O ∗ (2 k ) . The best kno wn algorithms for fi nding a H A M I L T O N P ATH , case k = n for the k - P A T H pro blem, in an n -v ertex graph run O ∗ (2 n ) time and are quite old [6, 14, 15]. An y significa nt improve ment in the run time dependen ce on k giv en by W illiams’ algori thm wo uld imply a faster H A M I L T O N P ATH alg orithm, which has been an op en problem for over forty years . While there has been a lot of work on the k - P A T H proble m, there has been almost no progr ess on other cases of the S U B G R A P H I S O M O R P H I S M problem until this year . Amini et al. [5] introd uced an inclusion-e xclus ion based ap proach in the clas sical C O L O R - C O D I N G and using it ga ve a ran dom- ized 5 . 4 k n O ( t ) time alg orithm and a dete rministic 5 . 4 k + o ( k ) n O ( t ) time alg orithm for the S U B G R A P H I S O M O R P H I S M problem, when F has tree width at most t . K outis and W illiams [21] ge neralize d th eir algebr aic approac h for k - P A T H to k - T R E E , a specia l case of S U B G R A P H I S O M O R P H I S M prob lem where F is a tree on k -vertic es, and o btained a randomized a lgorithm run ning in time O ∗ (2 k ) for k - T R E E . Our first re sult fills this gap and generalizes the results of K outis and W illiams [21] and W illiams [24] for k - T R E E and k - P A T H respecti ve ly , to the case when th e patte rn graph F has tree w idth at most t . More p recisely , we gi ve a randomize d algorithm for t he S U B G R A P H I S O M O R P H I S M problem runnin g in time O ∗ (2 k ( nt ) t ) , when the tree width of F is at most t . In general our approac h follo ws the road map sugge sted by K outis and W illiams [21] and W illiams [24], which is base d on redu cing the problem to checki ng a multilinear term in a specific polynomial of deg ree at m ost k . Our fi rst non-tri vial con trib u- tion is a new pol ynomial of deg ree at most k , namel y the Homomorphism polyno mial, relat ing graph homomorph isms and inject iv e g raph ho momorphis ms f or testing whether a graph cont ains a sub graph which is isomorphic to a fix ed gra ph F . W e sho w that i f the tre e width of the pattern graph F is boun ded by t then we c an mak e an arithmetic circ uit of size O ∗ (( nt ) t ) for the Homomorphi sm polynomia l which combine d with a result of W illiams [24] yields our fi rst theorem. In fact, what we hav e is an arithmetic formula and using this w e giv e a determinist ic algor ithm to count homomorphisms from F to G which runs in time O ∗ (( nt ) 2 t ) and takes space polynomial in n , w hen the treewid th of F is t . This is not only crucia l for our polynomial space algor ithm for cou nting subgra phs but als o subs tantiall y impr ov es the space requirement, from k t +1 log n to polynomia l in n and k , of the pre vious algo rithm for counting graph homomorph isms of Diaz et al. [12]. In the second p art of the p aper we consider the probl em of coun ting t he number of pa ttern s ubgrap hs, that is, the #S U B G R A P H I S O M O R P H I S M problem. The algorithm g i ven in [6, 14, 15] fo r find ing a hamil- tonian pat h can in fac t count the number o f hamilto nian paths in the i nput gra ph in time O ∗ (2 n ) . Hence , a natural quest ion is wh ether we can solve the # S U B G R A P H I S O M O R P H I S M probl em in O ∗ ( c k ) time, 1 Throughout this paper O ∗ () notation hides factors polynomial in the instance size n and the parameter k . 2 when the k -verte x graph F is of bou nded tree width or whether we can e ven s olve the # k - P A T H problem in O ∗ ( c k ) time? Flum and Grohe [13] sho wed that the # k - P A T H problem is # W[1] -hard and hence it is very unlikel y that the # k - P A T H problem can be solve d in time f ( k ) n O (1) where f is any arbitrar y functi on of k . In an other ne gati ve r esult, Alon an d Gutner [3] hav e sho w n that on e can no t hope to solve # k - P A T H better than O ( n k / 2 ) using the method of C O L O R - C O D I N G . They sho w thi s by pro ving that any family F of “balanced hash functio ns” fro m { 1 , . . . , n } to { 1 , . . . , k } , must hav e size Ω( n k / 2 ) . On the positi ve sid e, v ery recently V assile vska and W illiams [ 23] studied v ariou s cou nting probl ems and among other results gav e an algorithm for the # k - P A T H problem running in time O ∗ (2 k ( k / 2)!  n k / 2  ) and space polyn omial in n . Bj ¨ orklun d et al. [8 ] introduce d th e method of “meet-in-the-mid dle” and gav e an algo- rithm for th e # k - P A T H problem running in time and space O ∗ (  n k / 2  ) . They also gav e an algorith m for # k - P A T H p roblem running in time O ∗ (3 k / 2  n k / 2  ) and polynomial space, impro ving on the po lynomial space algorithm gi ven in [23]. W e e xtend these resu lts to t he # S U B G R A P H I S O M O R P H I S M pro blem, when the pattern graph F is of bou nded treewidth or pathwidth. And here also graph homomorphisms come into play . By making use of graph homomorph isms w e succeed to extend the applica bility of the meet-in-t he-middle method to much more general structu res than paths. Combined with other tools— inclus ion-e xclusi on, the D I S J O I N T S U M problem, separation property of graph of bounded treewidt h or pathwidt h and the trimmed v arian t of Y ate’ s algorithm pre sented i n [7]—we obtain the fo llo wing re sults. Let F be a k -verte x graph and G be an n -vertex grap h o f pathwidth p and treewidt h t . Then # S U B G R A P H I S O M O R P H I S M is s olv able in times O ∗ (  n k / 2  n 2 p ) an d  n k / 2  n O ( t l og k ) and sp ace O ∗ (  n k / 2  ) . W e also gi ve an algorithm for # S U B G R A P H I S O M O R P H I S M that runs in time O ∗ (2 k  n k / 2  n 3 p t 2 t ) (respecti vely 2 k  n k / 2  n O ( t l og k ) ) and takes polynomial sp ace. Thus ou r work not on ly impr ov es on kno wn resu lts on S U B G R A P H I S O M O R P H I S M of Alon et a l. [4] and Amini et al. [5] bu t it also extend s and generalize most of the kno wn results on k - P A T H and k - T R E E of Bj ¨ orklund et al. [8], K outis and W illiams [21] and W illiams [24]. The main theme of both algorithms, for finding and for counting a fi xed pattern graph F , is to use graph homomorphis ms as the main tool. Counting homomorphi sms between graphs has found ap - plicati ons in va riety of ar eas, includ ing ext remal g raph theory , properti es of graph products, partition functi ons in statistical physics and property tes ting of large graphs. W e refer to the excellen t surv ey of Bor gs et al. [9] for more references on counting homomorph isms. In [5], for the first time, it was used to design ex act and parameteri zed alg orithms. One of the main ad v antages of using graph homomor - phisms is that in spite of their exp ressi ve power , graph homomorphisms between many stru ctures can be counted ef ficiently . S econdl y , it allows us to generalize v ariou s algorith m for co unting su bgraph s with an eas e. W e also combine cou nting homomorphisms w ith the recent adva ncements on computing dif feren t transfor mations efficie ntly on subset lattice. Our determinist ic polynomial space algorithm for counti ng graph homomorphis ms uses arithmetic formula and it appears that this method cou ld be useful in desig ning polyno mial space varia nt of other exact algor ithms. 2 Pr eliminaries Let G be a simple undire cted gra ph w ithout self lo ops and multiple edges. W e denote th e verte x set of G by V ( G ) and the set of edge s by E ( G ) . For a subse t W ⊆ V ( G ) , by G [ W ] we mean the sub graph of G induced by W . W e re fer to Appendix 6.1 for the stand ard definition s of tree w idth, path width and n ice tree decompo sition. Graph Homomorphisms: Give n two graphs F and G , a graph homomorphi sm from F to G is a map f from V ( F ) to V ( G ) , that is f : V ( F ) → V ( G ) , such that if uv ∈ E ( F ) , then f ( u ) f ( v ) ∈ E ( G ) . Furthermor e, w hen the map f is injecti ve, f is called an injectiv e homomorphism . Giv en two graphs F and G , the p roblem of S U B G R A P H I S O M O R P H I S M ask s whether there exists an injecti v e h omomorphis m from F to G . By h om ( F, G ), inj ( F, G ) and sub ( F , G ) we denote the number of homomorphisms from F to G , the numb er of injecti ve homomorphisms from F to G and the number of dis tinct copies of F in 3 G , respec ti vely . W e deno te by aut( F , F ) the number of automorph isms from F to itself, that is bije cti ve homomorph isms. The set H O M ( F , G ) denotes the set of homomorphisms from F to G . Functions on th e Su bset Lattice: For two functions f 1 : D 1 → R 1 and f 2 : D 2 → R 2 such that for e very x ∈ D 1 ∩ D 2 , f 1 ( x ) = f 2 ( x ) we de fine t he gluin g ope ration f 1 ⊕ f 2 to be a function from D 1 ∪ D 2 to R 1 ∪ R 2 such that f 1 ⊕ f 2 ( x ) = f 1 ( x ) if x ∈ D 1 and f 1 ⊕ f 2 ( x ) = f 2 ( x ) otherwise . For a univ erse U of size n , w e consider func tions fro m 2 U (the family of all subsets of U ) to Z . For such a function f : 2 U → Z , the zeta transfo rm of f is a functio n f ζ : 2 U → Z such that f ζ ( S ) = P X ⊆ S f ( X ) . Giv en f , computing f ζ using this equation in a na ¨ ıve mann er take s time O ∗ (3 n ) . Ho wev er , one can do better , and compute the zeta transfo rm in time O ∗ (2 n ) using a classical algorithm of Y ates [25]. In thi s pa per we w ill use a “trimmed” var iant of Y ates’ s al gorithm [7] that works well when the non-z ero entries of f all are located at the bottom of the subs et lattice. In pa rticular , it was sho w n in [7] that if f ( X ) only can be non-zero when | X | ≤ k then f ζ can be computed from f in time O ∗ ( P k i =1  n i  ) . In our algor ithm we will al so use an efficient algorithm for the D I S J O I N T S U M problem, defined as follo ws. Inp ut is two families A and B of subsets of U and two weight functions α : A → Z and β : B → Z . The object iv e is t o calculate A ⊠ B = X A ∈A X B ∈B  α ( A ) β ( B ) if A ∩ B = ∅ 0 if A ∩ B 6 = ∅ Follo wing an algorit hm of Ken nes [16], Bj ¨ orkund et al. [8] ga ve a n algo rithm to compute A ⊠ B in time O ( n ( | ↓ A | + | ↓ B | )) , where ↓ A = { X : ∃ A ∈ A , X ⊆ A } is the down-clos ur e of A . Arithmetic Cir cuits and Formula: An arithmet ic circuit ( or a straight line program) C over a spec ified ring K is a dir ected a cycli c gr aph w ith nodes labeled from { + , ×} ∪ { x 1 , . . . , x n } ∪ K , where X = { x 1 , . . . , x n } are t he input v ariables of C . Nodes with zer o out- degr ee are called o utput no des and th ose with labels from X ∪ K are called input nodes. The Size of an arithmetic circuit is the number of gates in it. The Depth of C is the length of the longe st path between an output node and an input node. A formula is an arithmetic circui t where e very node has ou t-deg ree bound ed by 1 , that is, the underly ing undire cted gr aph is a tree. The nodes in C are sometimes referred to as gates . It is not hard to see that with ev ery output gate g of the circu it C we can as sociate a polynomial f ∈ K [ x 1 , . . . , x n ] . For more details on arithmetic circui ts see [10, 1]. A polynomial f ∈ K [ x 1 , . . . , x n ] is sa id to ha ve a multil inear term if there is a term o f the fo rm c S Q i ∈ S x i with c S 6 = 0 and ∅ 6 = S ⊆ { 1 , . . . , n } in the standard monomial expansio n of f . 3 Algorithm f or Findin g a Su bgraph In this section we gi ve our first result an d sho w that the S U B G R A P H I S O M O R P H I S M problem can b e solv ed in time O ∗ (2 k ( nt ) t ) when th e pattern gr aph F has tree width at most t . The main idea of our algori thm fol lo ws that of Kout is and W illiams [21] and W illiams [24 ] for the k - T R E E p roblem and the k - P A T H proble m, respe cti vel y . Howe ver , we need additio nal ideas for ou r generali zations . Our second result of this sectio n is a polynomial space algorithm to count graph homomorphis ms between F and G when the tree width of F is at most t . First, gi ven t wo graphs F and G , w e will as sociate a pol ynomial P G ( X ) where X = { x v | v ∈ V ( G ) } such that: (a) the de gree of P G ( X ) is k ; (b) there is a one to one corr espond ence be tween the monomials of P G and homomorphis ms between F and G ; and (c) P G contai ns a m ultilin ear m onomial of degre e k if and only if G contains a subgraph isomorph ic to F . The polynomia l we associate with F and G to solve the S U B G R A P H I S O M O R P H I S M problem is giv en by the follo wing. Homomorphis m Polynomial = P G ( x 1 , . . . , x n ) = X Φ ∈ H O M ( F , G ) Y u ∈ V ( F ) x Φ( u ) . W e first sho w that P G is “ef ficiently” computable by an arithmetic circuit. 4 Lemma 1. L et F and G be given two gra phs with | V ( F ) | = k an d | V ( G ) | = n . Then the polynomial P G ( x 1 , . . . , x n ) is computable by an arithmetic cir cuit of size O ∗ (( nt ) t ) w her e t is the tr ee-width of F . Pr oof. Let F , G, k , n and t be as gi v en in the lemma. Let D = ( U, T , r ) be a n ice tree de composit ion of F roote d at r . W e de fine a polynomial f G ( T , τ , U τ , S, ψ ) ∈ Z [ X ] , where • τ is a node in T ; • U τ ⊆ V ( F ) is the vertex sub set associated with τ ; • S be a multi-set (an element can repeat itself) o f size at most t + 1 with elements from the se t V ( G ) ; • ψ : F [ U τ ] → G [ S ] is a mu ltiplici ty respectin g homomorphism between the subgraphs induced by U τ and S resp ecti ve ly; and • X = { x v | v ∈ V ( G ) } is the set of var iables. Let V τ denote the union of vertices contained in t he bags correspond ing to the nodes of s ubtree of T rooted at τ . At a n intuiti ve le vel f G ( T , τ , U τ , S, ψ ) repre sents t he polynomial w hich cont ains su m of monomials of the form Q u ∈ V τ \ U τ x φ ( u ) , w here φ is a homomorphism between F [ V τ ] and G consistent with ψ , that is, φ is an extensi on of ψ to F [ V τ ] . Fo rmally , the polyno mial f G can be defined induct iv ely by going ov er the tree T bottom up as follo ws. Case 1 (base case) : The node τ is a leaf node in T . Since V τ = U τ , there is only one homomorphi sm between F [ V τ ] and G that is an exte nsion of ψ , hence f G ( T , τ , U τ , S, ψ ) = 1 . Case 2: The node τ is a join node . Let τ 1 and τ 2 be the two childr en of τ a nd T 1 and T 2 denote the sub- trees rooted at τ 1 and τ 2 respec ti vely . No te t hat U τ = U τ 1 = U τ 2 and ( V τ 1 ∩ V τ 2 ) \ U τ = ∅ . Hence, any extens ion of ψ to a homomorphi sm betwee n F [ V τ 1 ] and G is independen t of an exte nsion of ψ to a homomorphis m between F [ V τ 2 ] and G . Thus we ha ve, f G ( T , τ , U τ , S, ψ ) = f G ( T 1 , τ 1 , U τ 1 , S, ψ ) f G ( T 2 , τ 2 , S, U τ 2 , ψ ) . (1) Case 3: The node τ is an intr oduce node in T , let τ 1 be the only child of τ , and { u } = U τ \ U τ 1 . Also, let T 1 denote the sub-tree of T rooted at τ 1 . In this ca se any exte nsion of ψ to a ho momorphis m between F [ V τ ] and G is in fa ct an extensi on of ψ | U τ 1 and thus we get f G ( T , τ , U τ , S, ψ ) = f G ( T 1 , τ 1 , U τ 1 , S \ { ψ ( u ) } , ψ | U τ 1 ) . (2) Case 4: The node τ is a fo r ge t no de in T , and τ 1 is the on ly c hild of τ in T . Now , U τ 1 contai ns an ext ra verte x along with U τ . T hus an y e xtens ion of ψ to a homomor phism between F [ V τ ] and G is a direc t sum of an exte nsion of ψ to inclu de u and th at of V τ 1 , where { u } = U τ 1 \ U τ . Define, Y , n v | v ∈ V ( G ) , ∀ w ∈ U τ , w u ∈ E ( F ) = ⇒ ψ ( w ) v ∈ E ( G ) o . For v ∈ Y , let ψ v : U τ 1 → S ∪ { v } be such that ψ v | U τ = ψ an d ψ v ( u ) = v . Then, f G ( T , τ , U τ , S, ψ ) = ( P v ∈ Y  f G ( T 1 , τ 1 , U τ 1 , S ∪ { v } , ψ v ) x v  if Y 6 = ∅ 0 otherwise . (3) Let H O M ( U r , G ) deno te the set of all homomorp hisms between the su bgraph of F induce d by U r and G . In order to consider all homomorphis ms between F and G , w e run through all homomorphisms ψ between F [ U r ] and G , and then compute f G ( T , r, U r , I mag e ( ψ ) , ψ ) multiplied by the monomial corres pondin g to ψ . Now we define , H G ( T , r, U r ) = X ψ ∈ H O M ( U r ,G ) f G ( T , r, U r , S ψ , ψ )  Y u ∈ U r ,v = ψ ( u ) x v  (4) 5 where, w e consider the set S ψ = Image ( ψ ) as a multi set. Now we need to sho w that H G is efficientl y computa ble and P G = H G . W e first sho w that H G is computable by an arithmeti c circ uit of size O ∗ (( nt ) t ) . Claim 1. H G ( T , r, U r ) is a po lynomial of de gr ee k and is computable by an arithmetic cir cuit of size O ∗ (( nt ) t ) . Her e r is the r oot of the tr ee T . Pr oof. In th e abov e de finition of f G , the only place where the degree of the po lynomial increases is at for get nodes of T . The number of fo rg et nod es in T is e xactly k − | U r | . Thus the degree of any f G is k − | U r | and hence the degree of H G is k . From the definitions in Equations (1-4) abov e, H G ( T , r, U r ) can be vie wed as an arithmetic circuit C with X = { x v | v ∈ V ( G ) } as v ariables a nd gates from th e set { + , ×} . Any node of C is l abeled either by a v ariables from U or a function of the for m f G ( T , τ , U τ , S, ψ ) . T he si ze of the cir cuit is bound ed by the number of possible lab elings of the fo rm f G ( T , τ , U τ , S, ψ ) , where T and U τ are fixed. But this is bound ed by | V ( T ) | · n t +1 · ( t + 1) t +1 = ( n t ) t + O (1) = O ∗ (( nt ) t ) . Next we sho w that H G defined abo ve is precis ely P G and satisfies all the desire d properties. Claim 2. L et φ : V ( F ) → V ( G ) . Then φ ∈ H O M ( F , G ) if and only if the monomial Q u ∈ V ( F ) x φ ( u ) has a non-z er o coef ficient in H G ( T , r, U r ) . In othe r word s, we have that H G ( T , r, U r ) = P G ( x 1 , . . . , x n ) = X φ ∈ H O M ( F , G ) Y u ∈ V ( F ) x φ ( u ) . Pr oof. W e fi rst giv e the forward directi on of the proof. Let φ ∈ H O M ( F , G ) and ψ = φ | U r . W e show an e xpansi on of H G ( T , r, U r ) whic h conta ins the monomial Q u ∈ V ( F ) x φ ( u ) . W e first choose the term f G ( T , r, U r , S ψ , ψ ) × Q u ∈ U r x ψ ( u ) . W e expa nd f G ( T , r, U r , S ψ , ψ ) further accordin g to the tree struc- ture of T . W e describe this in a generic w ay . Consider the expans ion of f G ( T ′ , τ , U τ , S, χ ) . If τ is a join node w e recursi ve ly expan d bot h the sub polynomials accord ing to E quation (1). When τ is an i ntroduc e node we use Equat ion (2). In the case when τ is a for get node, we first note that Y 6 = ∅ (this is the same Y as defined in Case 4 ) and a lso th at φ ( u ) ∈ Y , where u ∈ U τ \ U τ 1 . T he la st asse rtion follo ws from the definitio n of Y . Here, we choose the term which contains x φ ( u ) , note that there exists exa ctly one such term and proce ed recurs iv ely . Let M denote the monomial obtained by the abo ve mentioned expa nsion. For any node v ∈ V ( G ) , we ha ve deg M ( x v ) = | φ − 1 ( v ) | , where deg M ( x v ) denotes the de gree of the v ariable x v in th e monomial M . T o see this, in the tree decompositi on D , a node u ∈ V ( F ) en ters the tree through a unique for get node and th is is ex actly wh ere t he v ariable x φ ( u ) is multiplied. Thus we h a ve M = Q u ∈ V ( F ) x φ ( u ) . Note that this expa nsion is uniquely defined for a giv en φ . For the r ev erse directi on, consi der an expansio n ρ o f H G ( T , r, U r ) in to mo nomials a nd let M = Q x d v v be a monomial of ρ , where P d v = k . W e b uild a φ ∈ H O M ( F , G ) using ρ and the structure of T . Let f G ( T , r, U r , S ψ , ψ ) be the first term chosen using E quation (4). Fo r ev ery u ∈ U r let φ ( u ) = ψ ( u ) . Induct iv ely su ppose that w e are at a node τ and let T ′ be the correspond ing sub tree of T . In the case of Equation s (1) an d (2) there is no nee d to do an ything . In the case of Equation (3), where τ is a for get node, with u ∈ U τ 1 \ U τ . If th e expa nsion ρ chooses the term f G ( T 1 , τ 1 , U τ 1 , S ∪ { v } , ψ v ) × x v , then we set φ ( u ) = v . It remains to sho w that the m ap φ : V ( F ) → V ( G ) as built abov e is indeed a homomorphism. W e pro ve this by sho wing that for any edg e uu ′ ∈ E ( F ) we hav e that φ ( u ) φ ( u ′ ) ∈ E ( G ) . If uu ′ is an edge such that bo th u, u ′ ∈ U r then we are done, as by definition φ | U r ∈ H O M ( U r , G ) and thus φ preserv es all the edges between the vertices from U r . So we assume that at least one of the end points of the edge uu ′ is not in U r . By the property of tree decompos ition there is a τ ′ ∈ T such that { u, u ′ } ∈ U τ ′ . No w since at least one of the endpoi nts of uu ′ is not in U r , there is a node on the path between r and τ ′ such that either u or u ′ is fo rg otten. Let τ ′′ be th e first node on th e pat h start ing from τ ′ to r in t he tre e T such 6 that it does not co ntain bo th u and u ′ . Wi thout lo ss of generalit y let u / ∈ U τ ′′ and t hus τ ′′ is a for get no de which forg ets u . At any for get node, since the tar get node v is from the set Y , we hav e that φ preserv es the edge relation ships among the vertices in U τ ′′ and u . N o w from Equation (3), the proper ty of Y and the fact that u ′ ∈ U τ ′′ we ha ve that φ ( u ) φ ( u ′ ) ∈ E ( G ) . No w by setting P G ( X ) = H G ( T , r, U r ) the lemma follo ws which concludes the proof. W e also need the follo wing proposition prov ed by W illiams [24], which tests if a polyn omial of deg ree k has a mu ltilinea r monomial with non -zero coef ficient in time O (2 k s ( n )) where s ( n ) is the size of the arithmet ic circuit . Pro position 1 ([24]) . Let P ( x 1 , . . . , x n ) be a polyno mial of de gr ee at most k , rep r esen ted by an arith- metic cir cuit of size s ( n ) with + gates (o f unbounded fa n-in), × gates (of fan -in tw o), a nd n o scalar multiplic ations. Ther e is a randomize d algorithm that on e very P runs in O (2 k s ( n ) n O (1) ) time, out puts “yes” wit h high pr obabili ty if ther e is a mul tilinea r term in th e sum-pr oduct e xpan sion of P , and al ways outpu ts “no” if ther e is no multilinear term. Lemma 1 and Propositio n 1 togeth er yield our first theo rem. Theor em 1. L et F and G be two graphs on k and n vertices re spective ly and tw ( F ) ≤ t . T hen, ther e is a rand omized algorithm for the S U B G R A P H I S O M O R P H I S M pr oblem that runs in time O ∗ (2 k ( nt ) t ) . Counting H omomorphisms: W e no te th at the polynomial P G can be used to co unt th e nu mber of homomorph isms from F to G . Let h om ( F , G ) de note th e n umber of homomorphis ms from F to G . Then we ha ve , hom ( F , G ) = P G (1 , . . . , 1) . First we make th e follo wing observ ation s: • H G can in fact be computed by an arithmetic formula Φ of size n O ( t ) . In fact the straightfor ward circuit constr uction described above gi ves a formula. • The depth of Φ is bound ed by 1 + depth of T and the depth of T is bou nded by O ( k ) . W e need the follo wing propositio n. Pro position 2 ( Folklo re) . [ ⋆ ] 2 Given a n arit hmetic formula Φ of depth d and size s , Φ can be e valuat ed at (1 , . . . , 1) in time O ( s ) and O ( d ( d + log s )) bits of space . A na ¨ ıve implementa tion of the abov e procedure would require n O ( t ) + O ( d ( d + log s )) bits of space, as we may need to st ore the whole formul a Φ in the memory for an ev aluati on. Here, we giv e an implementati on which reduces the space requiremen t to O ( n (log k + t log n )) bits. The ide a is not to store the entire formula , inst ead to hav e a space ef ficient algorith m t hat giv en h u, i, T i as an input, outpu ts i th child of a node u in Φ . Lemma 2. [ ⋆ ] Given a nice tre e decompositio n of F , and a label h T , τ , U, S, ψ i of a node u in the for- mula Φ the following can be computed in O (( n + k )(log k + t log n )) bits of space and time O ( S iz e (Φ)) : (a) the number of ch ildr en of u in Φ ; and (b) the label of the i th chi ld of u in Φ . W e can implement the algorith m gi ven in Propos ition 2 by using the algorithm of Lemma 2 whene ve r we n eed to access an edge of th e a rithmetic formul a Φ . Note tha t e ve n thou gh e ve ry cal l to the al gorithm of Lemma 2 require s O (( n + k )(log k + t log n )) bits of sp ace, this can be reused amon g dif feren t calls. Thus the total space re quirement is O ( k ( k + t log n ) + n (log k + t log n )) . Also, the o vera ll running time of the e valu ation procedure for Φ will be O ∗ (( nt ) t · S iz e (Φ)) = O ∗ (( nt ) 2 t ) . Hence we hav e the follo wing: 2 Proofs of results labeled with [ ⋆ ] have bee n moved to the ap pendix due to space restrictions. 7 Theor em 2. L et F and G be two grap hs on k and n vertic es r espec tively and tw ( F ) ≤ t . Then, the number of homomorph isms fr om F to G , hom ( F, G ) , can be computed in time O ∗ (( nt ) 2 t ) and O ( k 2 + ( k + n ) t log n ) bits of space . This is a subs tantial impro vemen t on spa ce compared to the O ( k t +1 log n ) bound of [12]. In fac t, our algorithm tak es pol ynomial numbe r of bits, irrespecti ve of the tree width t . Ho we ver the running time of our algorit hm is O ∗ (( nt ) 2 t ) compared to the O ∗ ( k t ) time bound of [12]. 4 Algorithms f or Counting Subgraphs In this section , we gi ve algor ithms for th e # S U B G R A P H I S O M O R P H I S M prob lem, when F has either bound ed tree w idth or pathwidth . 4.1 Counting Subgraphs with Meet in The Middle When | V ( F ) | = k , the pathwidth of F is p and | V ( G ) | = n , then the runni ng time of our algo rithm for # S U B G R A P H I S O M O R P H I S M is O (  n k / 2  n 2 p + O (1) ) . Roughly speaking, our al gorithm decomposes V ( F ) into three parts, the left part L , the right part R , and the separat or S . Then the algorith m guesses the position of S in G , and for each such position counts the number of ways to map L and R into G , such that the mappings can b e glued together at S . T hus our result is a generalizati on of the meet in the middle algori thm for # k - P A T H in an n -verte x graph by B j ¨ orklund et al. [8]. Ho we ver , our algorithm dif fers fro m th at of Bj ¨ orklun d et al . [8] conceptual ly in two important p oints. First, w e count t he number of injecti ve h omomorphi sms from F to G instead o f counting the number of subgraphs o f G that are isomorph ic to F . T o get the number of su bgraph s of G that are isomorphic to F w e simply di vide the number of inje cti ve homomorphi sms from F to G by the number of au tomorphis ms of F . The second dif feren ce is that we gi ve an algorith m tha t gi ven a k -verte x graph F of pathwidth p and an n -verte x graph G computes in time O ∗ (  n k  n p ) the number of injecti ve homomorphisms from F to G [ S ] for e very k -vertex subset S of G . In the # k - P A T H algorit hm of Bj ¨ orklund et al. [8], a simple dynamic progra mming al gorithm to count k -paths in G [ S ] fo r eve ry k -verte x subset S , runnin g in time O ∗ (  n k  ) is presented , ho wev er this alg orithm do es n ot seem to generaliz e to more compli cated patt ern graphs F . Interest ingly , ou r algorithm to compute the number of injecti ve homomorphisms from F to G [ S ] for e very S is instead based on inclusion-e xclu sion and the trimmed var iant of Y ates’ s alg orithm present ed in [7 ]. In order to implement the me et-in-th e-middle approach , we will u se the followin g fact about graphs of bounde d pathwidth. Pro position 3 (Folkl ore) . [ ⋆ ] Let F be a k -verte x graph of path width p . Then ther e exi sts a partitio ning of V ( F ) into V ( F ) = L ⊎ S ⊎ R , such that | S | ≤ p , | L | , | R | ≤ k / 2 and no edg e of F has one endpoin t in L and the other in R . Let V ( F ) = L ⊎ S ⊎ R be a part itionin g of V ( F ) as gi ven by Proposit ion 3, an d let L + = L ∪ S and R + = R ∪ S . For a map g : S → V ( G ) and a set S ′ such that S ⊆ S ′ and a set Q we define hom g ( F [ S ′ ] , G [ Q ]) to be the number of inje cti ve homomorphisms fro m F [ S ′ ] to G [ Q ] coinci ding with g on S . Similarly we let inj g ( F [ S ′ ] , Q ) to be th e number of ho momorphisms from F to G [ Q ] coinci ding wit h g on S . If we gu ess ho w an injecti v e homomorphism maps F [ S ] to G we get inj ( F , G ) = P g inj g ( F , G ) , where the sum is tak en ov er all injec ti ve maps g fr om S to V ( G ) . For a gi ven map g , we define the set of familie s L g = { Q ⊆ V ( G ) : | Q | = | L |} and R g = { Q ⊆ V ( G ) : | Q | = | R |} . The weight of a set Q ∈ L g is defined as α L g ( Q ) = inj g ( F [ L + ] , G [ Q ∪ g ( S )]) and the weight of a set Q ∈ R g is set to α R g ( Q ) = inj g ( F [ R + ] , G [ Q ∪ g ( S )]) . For an y Q 1 ∈ L g and Q 2 ∈ R g such that Q 1 ∩ Q 2 = ∅ , if we take an injecti ve homomorphism h 1 from F [ L + ] to G [ Q 1 ∪ g ( S )] coinciding with g on S and anothe r injecti ve homomorphism h 2 from 8 F [ R + ] to G [ Q 2 ∪ g ( S )] coin ciding with g o n S and glue th em tog ether , w e obtain an injecti ve homo - morphism h 1 ⊕ h 2 from F to G . Furth ermore two homomorp hisms from F to G can only be equal if the y coin cide on all vertices of F . Thus, if Q ′ 1 ∈ L g , Q ′ 2 ∈ R g and h ′ 1 and h ′ 2 are inj ecti ve homo- morphisms fro m F [ L + ] to G [ Q ′ 1 ∪ g ( S )] and fro m F [ R + ] to G [ Q ′ 2 ∪ g ( S )] respect iv ely we hav e that h 1 ⊕ h 2 = h ′ 1 ⊕ h ′ 2 if and only if h ′ 1 = h 1 and h ′ 2 = h 2 . Also, for any injecti ve homomorph ism h from F to G that coi ncides with g on S we can decompo se it into an inject iv e homomorphism h 1 from F [ L + ] to G [ S ∪ Q 1 ] and ano ther in jecti v e homomorp hism h 2 from F [ R + ] to G [ S ∪ Q 2 ] such that Q 1 ∈ L g , Q 2 ∈ R g and Q 1 ∩ Q 2 = ∅ . Then inj g ( F , G ) = L g ⊠ R g and hence inj ( F , G ) = X g L g ⊠ R g (5) Pro position 4 ([8, 16]) . Given two families A and B tog ether wit h weight functi ons α : A → N and β : B → N we can co mpute the disjoint sum A ⊠ B in t ime O ( n ( | ↓ A| + | ↓ B | )) wher e n is th e number of disti nct elements cover ed by the members of A and B . Her e ↓ A = { X : ∃ A ∈ A , X ⊆ A } . W e would like to use Propositi on 4 togeth er with Equation (5 ) in order to compute inj ( F , G ) . Thus, gi ven the mapping g : S → V ( G ) we need to compute L g , R g , α L g and α R g . Listing L g and R g can be done easil y in  n k / 2  +  n k / 2  time, so it remains to compute ef ficiently α L g and α R g . Lemma 3. Let G be an n -vert e x graph , F be a ℓ -ver te x graph of tree w idth t , S ⊆ V ( F ) and g be a functi on fr om S to V ( G ) . Ther e is an algorithm to compute inj g ( F , G [ Q ∪ g ( S )]) for all ℓ − | S | sized subset s Q of V ( G ) \ g ( S ) in time O ∗ (( P ℓ −| S | j =1  n j  ) · n p ) . Pr oof. W e claim that the follo wing inclusion-e xclusion formula hold s for inj g ( F , G [ Q ∪ g ( S )]) . inj g ( F , G [ Q ∪ g ( S )]) = X X ⊆ Q ( − 1) | T |−| X | hom g ( F , G [ X ∪ g ( S )]) (6) T o prov e the corre ctness of Equation (6), we first sh o w that if there is an in jecti ve homomorphism f from F to G [ Q ∪ g ( S )] coinciding with g on S then its co ntrib ution to the sum is exa ctly one. Notice that since | S | + | Q | = | V ( F ) | , all injecti ve homomorp hisms that coincide with g on S only con trib ute when X = Q and thus are count ed ex actly once in the right hand s ide. S ince we are coun ting h omomorphis ms, in th e righ t hand side sum we also count maps which are n ot inj ecti ve . Next we show that if a homomor - phism h fr om F to G [ S ∪ Q ] , which coinci des with g on S , is not an injecti ve homo morphism then its total co ntrib ution to the sum is zero, which will conclu de the correctne ss proof of the equat ion. Observ e that since h is not an injecti ve ho momorphism it m isses some vertice s of Q . Thus h ( V ( F )) ∩ Q = W for some sub set W ⊂ Q . W e now observe that h is c ounted o nly when we are cou nting homomorp hisms from F to G [ X ∪ g ( S )] such that W ⊆ X . T he total contrib ution of h in the sum, taking into accoun t the signs, is | Q | X i = | W |  | Q | − | W | i − | Q |  ( − 1) | Q |− i = | Q |−| W | X i =0  | Q | − | W | i  ( − 1) | Q |−| W |− i = (1 − 1) | Q |−| W | = 0 . Thus, we hav e sho wn that if h is not an injecti ve homo morphism then its contrib ution to the su m is ze ro, and hence Equation (6) hold s. Observ e that since | Q | = ℓ − | S | , we ca n rewri te ( − 1) | Q |−| X | as ( − 1) ℓ −| S |−| X | . Define γ ( X ) = ( − 1) ℓ −| S |−| X | hom g ( F , G [ X ∪ g ( S )]) , then we can re write E quation (6) as follows: inj g ( F , G [ Q ∪ g ( S )]) = γ ζ ( Q ) . W e start by pre-computing a table containing γ ( Q ′ ) for ev ery Q ′ with | Q ′ | ≤ ℓ − | S | . T o do this we need to compute ho m g ( F , G [ Q ′ ∪ g ( S )]) for all subsets Q ′ of V ( G ) \ g ( S ) of s ize a t most ℓ − | S | . There are at most P ℓ −| S | j =1  n j  such subsets, and for each subset Q ′ we can compute 9 hom g ( F , G [ Q ′ ∪ g ( S )]) , and h ence also α ( Q ′ ) using t he dynamic programming algori thm of Diaz et al. [12] in time O ∗ ( n p ) . N o w , to compute γ ζ ( Q ) for all Q ⊆ V ( G ) \ g ( S ) of size ℓ − | S | we apply the algor ithm fo r the trimmed zeta transfor m (A L G O R I T H M Z ) from [7]. This algorit hm run s in time O ∗ ( P ℓ −| S | j =1  n j  ) . Thus the total running time of the algorith m is then O ∗ (( P ℓ −| S | j =1  n j  ) · n p ) . This conclu des the proof. W e are no w in position to prov e the main theorem of this section. Theor em 3. Let G be an n -verte x graph and F be a k -verte x graph of pathwidth p . Then we can solve the # S U B G R A P H I S O M O R P H I S M pr oble m in time O ∗ (  n k / 2  n 2 p ) and space O ∗ (  n k / 2  ) . Pr oof. W e apply Prop osition 4 togethe r with Equation (5) in order to compute inj ( F , G ) . In particu lar , for e very mappi ng g : S → V ( G ) w e list L g and R g and compute α L g and α R g using the algorithm from Lemma 3. Finally , to compute L g ⊠ R g we apply Propositio n 4. The sum in Equation (5) runs ov er  n p  p ! ≤ n p dif feren t cho ices for g . For each g , lis ting L g and co mputing α L g , and li sting R g and co mputing α R g , takes O ∗ (  n k / 2 −| S |  n p ) an d O ∗ (  n k / 2  n p ) ti me respec ti vely . Finally , computing L g ⊠ R g tak es ti me O ∗ (  n k / 2  ) . T hus the t otal running time for th e algori thm to compute inj ( F , G ) is O ∗ (  n k / 2  n 2 p ) . T o compute the number of occurrences of F as a subgr aph in G , we use the basic fact that the number of occ urrence s of F in G is in j ( F , G ) / aut ( F ) [5]. Since aut ( F ) = inj ( F , F ) we can comp ute aut ( F ) using the al gorithm for compu ting inj ( F , G ) in time O ∗ (  k k / 2  n 2 p ) = O ∗ (2 k n 2 p ) . This con cludes the proof of the theore m. 4.2 Polynomial Sp ace Algorithm In this secti on we giv e a polyn omial space varian t of our algorithm presented in the pre vious section. Our proof is similar to the one described by Bj ¨ orklund et al.[8] for the # k - P A T H problem. W e will also need the follo wing propos ition which gi ves a rela tionsh ip between inj ( F , G ) and h om ( F , G ). Pro position 5 ([5]) . Let F and G be two graph s with | V ( G ) | = | V ( F ) | . Then inj( F, G ) = X W ⊆ V ( G ) ( − 1) | W | hom( F, G [ V ( G ) \ W ]) = X W ⊆ V ( G ) ( − 1) | V |−| W | hom( F , G [ W ]) . Theor em 4. Let G be an n -verte x graph and F be a k -verte x graph of pathwidth p . Then we can solve the # S U B G R A P H I S O M O R P H I S M pr oble m in time O ∗ (  n k / 2  2 k n 3 p t 2 t ) and polynomial space. Pr oof. By Equa tion (5) we k no w th at inj ( F, G ) = P g L g ⊠ R g . W e first sho w ho w to compute L g ⊠ R g for a fixed map g : S → V ( G ) . F or bre vity , we use the Ivers on Bracket notation: [ P ] = 1 if P is true, and [ P ] = 0 if P is fal se. L g ⊠ R g = X M ∈L g X N ∈R g [ M ∩ N = ∅ ] α L g ( M ) β R g ( N ) = X M ∈L g X N ∈R g X { X ⊆ V ( G ) , | X |≤ k / 2 } ( − 1) | X | [ X ⊆ M ∩ N ] α L g ( M ) β R g ( N ) = X { X ⊆ V ( G ) , | X |≤ k / 2 } ( − 1) | X | X M ∈L g X N ∈R g [ X ⊆ M ]][ X ⊆ N ] α L g ( M ) β R g ( N ) = X { X ⊆ V ( G ) , | X |≤ k / 2 } ( − 1) | X |  X M ∈L g ,M ⊇ X α L g ( M )  X N ∈R g ,N ⊇ X β R g ( N )  = k / 2 X i =1 X { X ⊆ V ( G ) , | X | = i } ( − 1) i  X M ∈L g ,M ⊇ X α L g ( M )  X N ∈R g ,N ⊇ X β R g ( N )  (7) 10 For e very M ∈ L g , by Equation (6), w e kno w that the follo w ing inclusion-e xclusion formula holds for α L g ( M ) . α L g ( M ) = inj g ( F [ L + ] , G [ M ∪ g ( S )]) = X M ′ ⊆ M ( − 1) | M |−| M ′ | hom g ( F [ L + ] , G [ M ′ ∪ g ( S )]) W e can co mpute hom g ( F [ L + ] , G [ M ′ ∪ g ( S )]) in O ∗ (( nt ) 2 p ) time and polynomial space usin g a v ariant of T heorem 2. For details please see Appendix 6.5. Hence, using this we can compute α L g ( M ) in time O ∗ (2 | M | ( nt ) 2 p ) . Similarly we can compute α R g ( N ) in time O ∗ (2 | N | ( nt ) 2 p ) fo r ev ery N ∈ R g . Now using Equation (7) we can bound the runnin g time to compute L g ⊠ R g as follo ws: k / 2 X i =1  n i  n − i | L | − i  O ∗ (2 | L | ( nt ) 2 p ) +  n i  n − i | R | − i  O ∗ (2 | R | ( nt ) 2 p )  ≤ k / 2 X i =1  2 k / 2  n | L |  O ∗ (2 | L | ( nt ) 2 p ) + 2 k / 2  n | R |  O ∗ (2 | R | ( nt ) 2 p )  ≤ k / 2 X i =1  n k / 2  O ∗ (2 k ( nt ) 2 p ) +  n k / 2  O ∗ (2 k ( nt ) 2 p )  = k  n k / 2  O ∗ (2 k ( nt ) 2 p ) . This implies t hat the time ta ken to compu te inj ( F , G ) = P g L g ⊠ R g is O ∗ (2 k  n k / 2  n 3 p t 2 t ) , as the t otal number of ch oices for g is up per bounded by  n p  p ! ≤ n p . F inally , to compute the number of occurrence s of F in G , we use th e basic fa ct that the numbe r of occurre nces o f F in G is inj ( F, G ) / aut ( F ) [5] as in the proof of Theorem 3. W e can compute aut ( F ) = inj ( F , F ) , using the polynomial space algorith m gi ven by Proposition 5 fo r comp uting inj ( F, G ) and Theo rem 2, in time P k i =1  k i  O ∗ (( k p ) 2 p ) = O ∗ (2 k k 4 p ) and space polyno mial in k . This con cludes the proof of the theorem. Theorems 3 and 4 can ea sily be general ized to han dle the ca se w hen F has tree width at most t by observ ing that if t w ( F ) ≤ t then p w ( F ) ≤ ( t + 1) log ( k − 1) [18] and that Theore m 2 works for gr aphs of boun ded treewidt h. 5 Conclusion In this pape r we considered the S U B G R A P H I S O M O R P H I S M problem and the # S U B G R A P H I S O M O R - P H I S M problem and gav e the best known algo rithms, in terms of time and space requirements, for these proble ms when the pa ttern grap h F is restricte d to graphs of bounded tree width or pathwidth . Count- ing graph homomorph isms serv ed as a main tool for all our algorithms. W e combine d coun ting graph homomorph isms w ith v ariou s other recently de velo ped tools in parameteri zed and exact algorith ms like meet-in-mid dle, tri mmed va riant of Y ates’ s al gorithm, the D I S J O I N T S U M problem and algebra ic circui ts and formula s to obtain our algorithms. W e co nclude with an intriguin g op en problem about a special case of the S U B G R A P H I S O M O R P H I S M proble m. Can we solve the S U B G R A P H I S O M O R P H I S M probl em in time O ∗ ( c n ) , c a fixed c onstan t, w hen the maximum deg ree of F is 3 ? Acknowledgements. W e thank Mik ko Koi visto for point ing us to an error i n th e pre vious ve rsion of this manuscri pt and for usef ul discussions . Refer ences [1] E. Allender . Arithmet ic circ uits a nd counting c omplex ity class es. In J. Krajicek, editor , Complexit y of Compu tations and Pr oofs , Quadern i di Matematic a V ol. 1 3, pages 33 –72. Seconda Uni vers ita di 11 Napoli, 2004. An earlier version appeared in the C omple xity Theory Column, S IGA CT News 28 , 4 (Dec. 1997 ) pp. 2-15. [2] N. Alon, P . Dao , I. Haj irasoul iha, F . Hormozdiari, and S. C. Sahin alp. Biomolecular netw ork motif counti ng and discov ery by color coding. In ISMB , pages 241–249 , 2008. [3] N. Alon a nd S. Gutner . Balanced hash ing, color cod ing and a pproxima te counting. Electr onic Colloqui um on Computational Complexi ty (E CCC) , 16(1 2), 2009. [4] N. Alon, R. Y uster , and U. Zwick. Color -coding. J. ACM , 42(4) :844–8 56, 19 95. [5] O. Amini, F . V . Fomin, and S. Saurabh. Counti ng subgraphs via ho momorphis ms. In ICA LP (1) , v olume 5555 of Lectur e Notes in Computer Scien ce , pages 71–82, 2009. [6] R. Bellman. Dynamic progr amming tre atment of the trav elling sales man problem. J . ACM , 9(1):6 1–63, 1962. [7] A. B j ¨ orklund, T . Husfeldt, P . Kaski, and M. Koi visto. Trimmed m oebius in version and graphs of bound ed deg ree. In ST ACS , pages 85–96 , 2008. [8] A. Bj ¨ orklun d, T . Husfeldt, P . Kaski, and M. K oivist o. Counti ng paths and packi ngs in halves. CoRR , abs/090 4.3093, to appear in ES A09, 200 9. [9] C. Bor gs, J. Chaye s, L. Lov ´ asz, V . T . S ´ os, and K. V eszter gombi. Counting gra ph homomorphi sms. In T opics in di scr ete mathematics , volu me 26 of Algorithms Comb in. , pag es 315 –371. Spri nger , Berlin, 2006. [10] P . B ¨ urg isser , M. Clau sen, and M. Shokro llahi. Alg ebr aic Complex ity Theory . Springer -V erlag, 1997. [11] J. Ch en, S. Lu, S.-H. Sze, and F . Zhang. Impro ved algorithms fo r pa th, matching, and packing proble ms. In SODA , pag es 298–307 , 2007. [12] J. D´ ıa z, M. J. Sern a, and D. M . T hilik os. Coun ting h-color ings of partial k-trees. Theor . C omput. Sci. , 281(1 -2):291 –309, 2002. [13] J. Flum and M. Grohe. The parameteriz ed c omple xity of count ing problems. SIAM J. Comput. , 33(4): 892–92 2, 20 04. [14] M. Held and R. M. Karp. A dynamic progra mming ap proach to sequen cing problems. J ournal of the Society for Indust rial and Applied M athemati cs , 10(1):196– 210, 1962. [15] R. M. Karp. Dynamic programming meets the principle of inclusion and exclusio n. Inf . Pr ocess. Lett. , 1(2):49 –51, 1982. [16] R. Kenne s. Comp utation al aspe cts o f the mo ebius transform of a gra ph. IEEE T ransacti ons on System, Man, and Cyberne tics , 22:20 1–223, 1991. [17] N. G. Kin nersle y . T he vert ex separation number o f a grap h eq uals its p ath-width . Inf. Pr ocess. Lett. , 42(6):3 45–350 , 1992. [18] T . Kloks . T r eewidt h, C omputati ons a nd Appr oximations , v olume 842 of Lectur e Notes in C omputer Scienc e . S pringe r , 1994. [19] J. Kneis, D . M ¨ olle, S. R ichter , and P . Rossmanith. Di vide- and-col or . In WG , v olume 4271 of Lectur e N otes in Computer Scienc e , pages 58–67, 2006. 12 [20] I. Kout is. Faster algebraic algorithms for path and packing problems. In ICALP (1) , volume 5125 of Lectur e Notes in Computer Science , pages 575–586, 2008. [21] I. Kout is and R. W illiams. Limits and applic ations of group algebras for parameterized problems. In ICALP , 2009 , T o appear . [22] C. H. Papadimitrio u a nd M. Y annakakis . On limited nondetermini sm and the complex ity of the V -C dimen sion. J. Comput . Syst. Sci. , 53(2):16 1–170, 1996. [23] V . V assile vska and R. W illiams. Findin g, minimizin g, and co unting weigh ted subg raphs. In ST OC , pages 455–46 4, 2009. [24] R. W illiams. Finding paths of length k in O ∗ (2 k ) time. Inf. Pr ocess. Lett. , 109(6):31 5–318 , 2009 . [25] F . Y ates. The desig n and analysis of factoria l expe riments. T echnic al C ommunicati on , 35, 1937. 13 6 A ppendix 6.1 T reewidth , Pathwidth and Nice T ree-Decomp osition A tr ee dec ompositio n of a (undirect ed) graph G is a pa ir ( U, T ) w here T is a tree whose v ertic es we will call nodes and U = ( { U i | i ∈ V ( T ) } ) is a collection of subsets of V ( G ) such that 1. S i ∈ V ( T ) U i = V ( G ) , 2. for each edge v w ∈ E ( G ) , there is an i ∈ V ( T ) such that v , w ∈ U i , and 3. for each v ∈ V ( G ) the set of nodes { i | v ∈ U i } forms a subtree of T . The U i ’ s are called bags. T he width of a tree decomposition ( { U i | i ∈ V ( T ) } , T ) equals max i ∈ V ( T ) {| U i |− 1 } . T he tr eewidth of a grap h G is the minimum width ov er all tree decompositio ns of G . W e use notat ion t w ( G ) to deno te the tree width of a graph G . W hen in the definitio n of the tr ee width, we restric t our - selv es to p ath, we g et the notion of pathwidth of a graph and de note it by p w ( G ) . W e also need a notion of nice tree de compositi on for our algorithm. A ni ce tree decompositi on of a graph G is a tu ple ( U, T , r ) , where T is a tree root ed at r and ( U, T ) is a tree decompo sition of G with the follo wing properties: 1. T is a bina ry tree. 2. If a node τ ∈ T has two children , say τ 1 and τ 2 , and U τ = U τ 1 = U τ 2 then it is called join node . 3. If a node τ has one child τ 1 , | U τ | = | U τ 1 | + 1 and U τ 1 ⊆ U τ then it is called intr oduce node . 4. If a node τ has one child τ 1 , | U τ 1 | = | U τ | + 1 and U τ ⊆ U τ 1 then it is called for get node . 5. If a node τ is a leaf node of T then it is called base node . Giv en a tree-decomp osition of widt h t , one can obtain a nice tree-decompo sition of width t in linea r time. 6.2 Pr oof of Proposition 2 Pr oof. Starting with the roo t node of Φ we do a depth -first ev aluati on. At any i nstance we need to store the labels of nod es along a pa th unde r explo ration which will req uire O ( d log s ) spa ce. W e also need to store the partial ev aluations along the path under explorati on. Sinc e output of a depth d formula with x 1 = 1 , . . . , x n = 1 as inputs can be stored u sing most d bit s, we would require O ( d ) bits per node in the path. Hence O ( d 2 ) bi ts are required for th e whole pa th. Hence the to tal spac e required is O ( d ( d + log s )) . 6.3 Pr oof of Lemma 2 Pr oof. Give n an i nput gate u o f Φ with the label h T , τ , U, S , ψ i , we c an desc ribe the algori thm as follo w s: 1. Check if U = U τ and ψ is indeed a homomorp hism between F [ U τ ] and G [ S ] else F A IL. 2. If τ is a leaf node then set count = 0 and return. 3. If τ is a join no de then the node h T , τ , U, S, ψ i has two children in Φ (see equ ation 1) hence set count = 2 . If i ≤ 2 , then return the label of the i th child accordi ng the canoni cal ordering. 4. If τ is an introduce node and τ 1 is the only child of τ in T , then set count = 1 and if i = 1 then return h T , τ 1 , U τ 1 , S \ { ψ ( u ) } , ψ | U τ 1 i else F A IL. (See equa tion 2.) 5. If τ is a for get nod e then set count = | Y | . If i ≤ | Y | then return th e i th tuple h T , τ 1 , U τ 1 , S ∪ { v } , ψ v i in the canonical ordering of n h T , τ 1 , U τ 1 , S ∪ { v } , ψ v i o v ∈ Y . (See equ ation 3. ) 14 T ime and space anal ysis: The running time of the algor ithm i s clearly upper bound ed b y S iz e (Φ) = O ∗ (( nt ) t ) . For space, note that we can store T using O ( k t log n ) bits as there are O ( k ) nodes in T , each contain ing a bag of size at most t + 1 . Storing a label of the form h T , τ , U, S, ψ i requir es O (log k + t lo g n + t log n + 2 t log n ) = O (log k + t log n ) man y bits of space. Steps 1-4 of the algori thm ca n be impl emented within th is space b ound. Ho wev er , ste p 5 requires a stor ing of the set R = n h T , τ 1 , U τ 1 , S ∪ { v } , ψ v i o v ∈ Y and then choos ing the i th element in their lex icogra phic orderin g. Ho wev er as | R | = | Y | ≤ | V ( G ) | = n , we can store all these labels i n O ( n (log k + t log n )) bits of space. So, the o ver all space requirement is O (( n + k ) n (log k + t l og n )) bits. 6.4 Pr oof of Proposition 3 Pr oof. The v ertice s of a g raph F of pathwid th p can be or dered as v 1 . . . v k such that fo r an y i ≤ k there is a subset S i ⊆ { v 1 . . . v i } with | S i | ≤ p , such that there are no edges of F with on e endpoin t in { v 1 . . . v i } \ S i and the othe r in { v i +1 , . . . v k } . S uch an orde ring is obtained, for e xample, in [17]. Choose L ′ = { v 1 . . . v ⌈ k/ 2 ⌉ } , S = S ⌈ k/ 2 ⌉ , L = L ′ \ S and R = { v ⌈ k/ 2 ⌉ +1 . . . v k } . Then L , S an d R ha ve the claimed prope rties. 6.5 V a riant of Theor em 2 For the proof of The orem 4, we need a var iant o f T heorem 2. In Theorem 4, we nee d h om g ( F , G [ X ∪ S ]) instea d of hom ( F , G [ X ∪ S ]) . This can be achie ved if we can compute the polynomia l, P g G ( x 1 , . . . , x n ) = X Φ ∈ H O M g ( F, G ) Y u ∈ V ( F ) x Φ( u ) , by an arithmetic for mula o f size n O ( p ) , w here H O M g ( F , G ) is the set of a ll h omomorphis ms from F to G that coincide with the fu nction g : S → V ( G ) , for S ⊆ V ( F ) . W e obtain the desired circu it by modifyin g the cons truction s gi ven in Lemma 1 as follo ws: • the sum in Equation (4) runs ove r H O M g ( F , G [ X ∪ S ]) ; and • in Equation (3) we ensure that the sum is restricted to ψ v ’ s that agree with g on S ⊆ V ( F ) . W ith an argumen t similar to that of Lemma 1 and using the fact that tw ( F ) ≤ p w ( F ) we conclude as follo ws. Lemma 4. Let F and G be given two gra phs with | V ( F ) | = k and | V ( G ) | = n . Let X, S ⊆ V ( G ) and g : V ( F ) → S be any function. Then the poly nomial P g G ( x 1 , . . . , x n ) is comput able by an arithmetic formula of size O ∗ (( np ) 2 p ) w her e p is the pathwidth of F . No w , by applying Propositi on 2 and Lemma 2 we get a polyn omial space algorithm to compute hom g ( F , G [ X ∪ S ]) . 15

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment