Finding paths of length k in O*(2^k) time

We give a randomized algorithm that determines if a given graph has a simple path of length at least k in O(2^k poly(n,k)) time.

Authors: Ryan Williams

Finding a path of length k in O ∗ (2 k ) time Ry an Williams ∗ Carnegie Mellon Univ ersit y Abstract W e give a r a ndomized alg orithm that determines if a given g raph has a simple path of length at least k in O (2 k · poly( n, k )) time. 1 In tro duction The k -path problem is to determine if a giv en graph con tains a simple path of length at least k , and if so, pr o duce suc h a path. When k is giv en as a p art of the input, the p roblem is w ell- kno wn t o be N P -complete. T he general problem has man y pr actica l applications (cf. [3, 15]). Th e trivial algorithm en umerating all p ossible k -paths in an n -no d e graph uses Θ( n k ) time, so it is only p olynomial for k = O (1). The first algorithm to redu ce the runtime dep endency on k w as giv en by Monien [13] w hose algorithm runs in O ∗ ( k !) time (the O ∗ notation suppr esses p oly( n, k ) factors). Hence the case k ≤ (log n ) / (log log n ) is still p olynomial time s olv able. F or ye ars it w as not kn own if the O (log n )-path problem was in p olynomial time; a breakthrough by Alon, Y uster, and Zw ic k [2] fin ally led to suc h an algo rithm. T hey ga v e a r andomized algorithm ru nning in O ∗ ((2 e ) k ) ≤ O ∗ (5 . 44 k ) time, and a deterministic O ∗ ( c k ) time algorithm, w h ere c is a large constan t. Sin ce it has b een kno wn for many y ears pr ior that when k = n the problem is s olv able in O ∗ (2 k ) time [4, 7, 9], it is natural to ask if there is an algorithm that can matc h this runtime for all v alues of k . It has b een only recen tly th at f aster k -p ath algorithms ha v e app eared in th e literature. In 2006, t w o groups indep end en tly d isco v ered O ∗ (4 k ) randomized algorithms and O ∗ ( c k ) deterministic algo- rithms, with c = 16 [10] and c = 12 . 5 [6]. V ery recently , K outis [11] presen ted a nov el r andomized algorithm for k -path that runs in O ∗ (2 3 k/ 2 ) ≤ O ∗ (2 . 83 k ) time. In this note, w e extend h is result to obtain an O ∗ (2 k ) time algorithm. Koutis sho ws ho w to detect if a graph has a k -su bgraph with an o dd n umber of k -paths in O ∗ (2 k ) time. By augmenti ng h is approac h with more random c hoices and some additional ideas, we can find a k -path in roughly the same runnin g time. As m entioned ab o v e, the b est kno wn algorithms for fi n ding a Hamilton path in an n -no de graph run in O ∗ (2 n ) time and are qu ite old. Therefore an y signifi can t improv emen t in the ru n time dep end ence on k giv en by our algorithm would imply a faster Hamilton p ath algorithm, whic h h as b een an op en problem for o v er fort y y ears. W e do not wish to insist that our algorithm is optimal, but rather that further p rogress w ould en tail a substan tial breakthrough in algorithms for NP -hard problems. ∗ Current address: School of Mathematics, Institute for Advanced Study , Princeton, NJ. Email: ryanw@math .ias.edu . This researc h w as partially supp orted by th e National Science F oundation und er CCR-0122581, while the author was at Carnegie Mellon. 1 2 Preliminaries Most of our notation is standard, ho w ev er we do require some notions from algebra that are not often used in graph algorithms. Let F b e a field and G b e a multiplica tiv e group (its b inary op eration is written as a m ultiplication). T he group alge bra F [ G ] is an algebraic ob j ect that incorp orates prop erties of b oth ob jects, defined as follo ws. Elemen ts of F [ G ] hav e the form X g ∈ G a g g , where eac h a g ∈ F . That is, the elemen ts are f ormal sum s o v er the group elemen ts, w ith co efficien ts from the field. Addition in F [ G ] is defined in a p oin t-wise manner:   X g ∈ G a g g   +   X g ∈ G b g g   = X g ∈ G ( a g + b g ) g . Multiplication has the form of a con v olution:   X g ∈ G a g g   ·   X g ∈ G b g g   = X g ∈ G X h ∈ G a h b h − 1 g ! g . Note the ab o v e d efinition coincides with the one in [11]. The ab o v e op erations define a ring with 0 and 1, where 0 ∈ F [ G ] is the elemen t P g ∈ G a g g suc h that all a g are equal to 0 ∈ F , and 1 ∈ F [ G ] is the multiplicati ve iden tit y 1 ∈ G of the group. In our alg orithm, w e work o v er th e group algebra GF (2 ℓ )[ Z k 2 ], for particular in tegers k , ℓ ≥ 0. Here Z k 2 is th e group of binary k -vec tors, en d o w ed with comp onent wise add ition mo dulo 2 as its op eration. GF (2 ℓ ) is th e unique fi eld on 2 ℓ elemen ts. W e u se W 0 to denote the all-zeros ve ctor (the iden tit y) of Z k 2 . Note that ev ery v ∈ Z k 2 is its o wn inv e rse: v 2 = W 0 . Ev ery element in the algebra has th e f orm P v ∈ Z k 2 a v v , where a v ∈ GF (2 ℓ ). Example The elemen ts of GF (2 2 ) can b e represent ed as the four p olynomials 0 , 1 , x, 1 + x o ve r GF (2 ), where computations are d one mo d u lo x 2 + x + 1 . F or example, x 3 = x · x 2 = x · (1 + x ) = x + x 2 = 1 in GF (2 2 ). Over GF (2 2 )[ Z 3 2 ],     0 0 0   + x   1 0 1     +     0 0 0   +   1 0 1   +   1 1 1     = (1 + x )   1 0 1   +   1 1 1   and o v er F [ Z 3 2 ] in general,   a 1   0 0 0   + a 2   1 0 1     ·   b 1   0 0 0   + b 2   1 0 1   + b 3   1 1 1     = ( a 1 b 1 + a 2 b 2 )   0 0 0   + a 2 b 3   0 1 0   + ( a 1 b 2 + a 2 b 1 )   1 0 1   + a 1 b 3   1 1 1   . 2 3 Algorithm for the k -P ath Problem Fix an u nderlying graph G in the follo wing, with v ertex set { 1 , . . . , n } . Let F b e a fi eld, let A b e the adjacency matrix of G , and let x 1 , . . . , x n b e v ariables. Define a matrix B [ i, j ] = A [ i, j ] x i . Let ~ 1 b e the ro w n -v ector of all 1’s, and ~ x b e the column v ector defin ed by ~ x [ i ] = x i . Define the k -walk p olynomial to b e P k ( x 1 , . . . , x k ) = ~ 1 · B k − 1 · ~ x . Prop osition 1 P k ( x 1 , . . . , x k ) = X i 1 ,...,i k is a walk in G x i 1 · · · x i k . Clearly , there is a k -path in G iff P k ( x 1 , . . . , x n ) conta ins a m ultilinear term. W e give a ran- domized algorithm R with the p rop ert y that: • if P k has a multilinear term, then Pr[ R outpu ts yes ] ≥ 1 / 5, • if P k do es n ot h a v e a multilinear term, then R alwa ys outputs no . In fact, the statemen t we can pr o v e is more general. Theorem 3.1 L et P ( x 1 , . . . , x n ) b e a p olynomia l of de gr e e at most k , r epr esente d by an arithmetic cir cuit of size s ( n ) with + gates (of unb ounde d fan-i n), × gates (of fan-in two), and no sc alar multiplic ations. Ther e is a r andomize d algorithm that on every P runs in O ∗ (2 k s ( n )) time, outputs y es with high pr ob ability if ther e is a multiline ar term in the sum-pr o duct exp ansion of P , and always outputs no if ther e i s no multiline ar term. Remark 1 W e may assume without loss of gener ality that every multiline ar term of P has de g r e e at le ast k , and at le ast one multiline ar term has de gr e e exactly k . If not, let k ′ < k b e the minimum de g r e e of a multiline ar term in P . We c an try al l j = 1 , . . . , k and multiply the final output of the cir cuit for P b y j new variables x n +1 , . . . , x n + j , obtaining a p olyno mial P j , which we fe e d to the r andomize d algorithm. N ote that when j = k − k ′ , our assumption holds. By observin g that P k can b e implemented with a circuit of size O ( k ( m + n )) where m is the n umber of edges in G , the k -path algorithm is obtained. W e b egin the pro of with a description of the algorithm. The basic idea is to substitute r an d om group algebra elements for th e v a riables su c h that all non-m ultilinear terms in P ev aluate to zero and some m ultilinear terms su rviv e. Th en we augmen t the scalar-free multi plication circuit with random s calar multiplicat ions ov er a field large enough that the remaining multilinea r p olynomial ev aluates to nonzero with decen t pr obabilit y . Set F = GF (2 3+log k ). Algorithm Pick n uniform r ando m ve ctors v 1 , . . . , v n fr o m Z k 2 . F or e ach multiplic ation gate g i in the cir cuit for P , pick a uniform r and om w i ∈ F \ { 0 } . Insert a new gate that multiplies the output of g i with w i , and fe e ds the output to those gates that r e ad the output of g i . L et P ′ b e the new p olynomial r epr esente d by this arithmetic cir cuit. 1 Output yes iff P ′ ( W 0 + v 1 , . . . , W 0 + v n ) 6 = 0 . 1 In the eva luation of the k -path polynomial P k , the algorithm corresponds to pic king ra ndom y i,j,c in F for c = 1 , . . . , k − 1, i, j = 1 , . . . , n , letting B c [ i, j ] = y i,j,c B [ i, j ], t hen ev aluating P ′ k ( x 1 , . . . , x n ) = ~ 1 · B k − 1 · · · B 1 · ~ x on the appropriate vectors. 3 Run time Let u s describ e one wa y to implemen t the algorithm efficientl y . The only non-trivial step is the final p olynomial ev aluatio n. By defin ition, the ev aluat ion of P ′ ( W 0 + v 1 , . . . , W 0 + v n ) tak es O ( s ( n )) arithmetic op erations. Ho w ev er, since ev aluat ion tak es place o v er F [ Z k 2 ], we need to account for the cost of arithmetic in the group algebra. Elemen ts in F [ Z k 2 ] can b e natur ally in terpreted as v ectors in F 2 k . Ad dition of these v ectors (as elements in F [ Z k 2 ]) can b e d one in O (2 k log | F | ) time with a comp onent- wise sum. Multiplicati on of v ectors u and v o v er the group algebra can b e done in O ( k 2 k log 2 | F | ) time by a F ast F ourier T rans form styl e algorithm, as we n ow describ e. F or simp licit y , let ℓ = 3 + log 2 k . R ep resen t elemen ts of F = GF (2 ℓ ) as univ ariat e p olynomials o v er GF (2) of degree at most ℓ in the us u al wa y , so the ent ries of u and v are degree- ℓ p olynomials. Ov er the ring C [ x ], multiply u and v with the matrix H k for the d iscr ete F ourier transf orm on Z k 2 (also called the W alsh-Hadamard transform) in O ( k 2 k M ( ℓ )) time (cf. [12]) wh ere M ( d ) is the runtime for computing the pr o d uct of t w o degree- d univ ariate p olynomials o v er GF (2). Sin ce ℓ is small, it suffices to use the b ound M ( ℓ ) ≤ O ( ℓ 2 ). T ak e the p oin t wise pro d uct of the t wo resulting v ectors obtaining a v ector w , and multiply w with H k (note H − 1 k = H k , so this is the inv erse of the trans f orm). The resulting v ector x conta ins 2 k p olynomials of degree at most 2 ℓ . Reduce eac h p olynomial mo du lo an irred ucible degree- ℓ p olynomial o v er GF (2), in O (2 k M ( ℓ )) time. (F or a discussion of ho w to obtain irreducible p olynomials, cf. [16].) This has the effec t of mapping our results in C [ x ] bac k do wn to GF (2 ℓ ). Ove rall, the ev aluation of P ′ tak es at most O ∗ (2 k s ( n )) time. W e note that wh ile the ab o v e computation naiv ely needs Ω (2 k ) space, detecting if P ′ ev aluates to zero can b e done in O (p oly( n, k )) space us in g (for example) the rep r esen tation-theoreti c tec hnique of Koutis [11]. F or the sak e of brevit y , we will not concern ourselv es with this issue. Correctness The cru cial observ ation of K outis [11 ] is that, for an y v i ∈ Z k 2 , ( W 0 + v i ) 2 = W 2 0 + 2 v i + v 2 i = W 0 + 0 + W 0 = 0 mod 2 . Therefore all squares in P v anish in P ′ ( W 0 + v 1 , . . . , W 0 + v n ), sin ce F has c haracteristic 2. It follo ws that if P ( x 1 , . . . , x n ) do es not ha v e a multilinear term, then P ′ ( W 0 + v 1 , . . . , W 0 + v n ) = 0 o v er F [ Z k 2 ], regardless of the choic e of v i . In the remainin g paragraphs, w e pro v e that if th e sum-pr o duct expansion of P ( x 1 , . . . , x n ) has a m ultilinear term, then P ′ ( W 0 + v 1 , . . . , W 0 + v n ) 6 = 0 with pr obabilit y at least 1 / 5, ov er the random c hoices of w i ’s and v i ’s. By Remark 1, w e may assume that ev ery multili near term in the sum-pro d uct expansion of P has the form c · x i 1 · · · x i k ′ where k ′ ≥ k and c ∈ Z . F or eac h such term, there is a corresp ondin g collection of m ultilinear terms in P ′ , eac h of th e form w 1 · · · w k ′ − 1 k ′ Y j = 1 ( W 0 + v i j ) , where the sequence w 1 , . . . , w k ′ − 1 is d istinct f or every term in th e co llection (as the sequences of m ultiplication ga tes g 1 , . . . , g k ′ − 1 are distinct). No te th ese terms do not ha v e leading co efficien ts, since there are no scalar multiplic ations in the arithmetic circuit. Consider a monomial Q i j = 1 ( W 0 + v j ) in the p olynomial (disregarding the w i ’s for the momen t). Koutis [11] p ro v ed that if the i ve ctors v 1 , . . . , v i are linearly dep endent , this monomial v anish es mo dulo 2. W e observ e that his p ro of works ov e r an y field of characte ristic t w o. 4 Prop osition 2 (Koutis) If v 1 , . . . , v i ∈ Z k 2 ar e line a rly dep end ent over GF (2) , then Q i j = 1 ( W 0 + v j ) = 0 in F [ Z k 2 ] . Pro of. If v 1 , . . . , v i are linearly d ep endent, there is a n onempt y sub s et T of the vec tors that s um to th e all-zeros vec tor. In F [ Z k 2 ], this is equiv alen t to Y j ∈ T v j = W 0 . Let S ⊆ T b e arbitrary . Multiplying b oth sides b y Q j ∈ ( S ∆ T ) v j , Y j ∈ S v j = Y j ∈ ( S ∆ T ) v j . Therefore Q j ∈ T ( W 0 + v j ) = P S ⊆ T  Q j ∈ S v j  = 0 mo d 2, since eac h pro du ct app ears t wice in the sum. Hence Q i j = 1 ( W 0 + v j ) = 0 o ve r F [ Z k 2 ], since F is c haracteristic 2. ✷ Therefore linearly dep endent vecto rs lead to a cancellation of terms. On the other hand, when v 1 , . . . , v i are linearly indep endent, Q i j = 1 ( W 0 + v j ) is just the sum ov er all v ectors in the span of v 1 , . . . , v i , since eac h v ector in the span is of the form Q j ∈ S v j for some S ⊆ [ i ], and there is a unique wa y to generate eac h vect or in the sp an . Prop osition 3 If v 1 , . . . , v k ∈ Z k 2 ar e line arly indep endent over GF (2) , then Q k j = 1 ( W 0 + v j ) = P v ∈ Z k 2 v . By Pr op ositions 2 and 3, and the fact that any k ′ > k vecto rs are linearly dep end en t, P ′ ( W 0 + v 1 , . . . , W 0 + v n ) ev a luates to either 0, or c P v ∈ Z k 2 v for some c ∈ F . The fi n al piece of our argum ent sho ws that if P has a multilinea r term, then c 6 = 0 with probabilit y at least 1 / 5. The v ectors v ℓ 1 , . . . , v ℓ k c hosen for th e v ariables in a m ultilinear term of P are linearly indep en- den t with probabilit y at least 1 / 4, b ecause the probabilit y that a random k × k matrix o v er GF (2) has f ull rank is at least 0 . 28 ≥ 1 / 4 (cf. [5], Lemma 6.3. 1). Hence in P ′ ( W 0 + v 1 , . . . , W 0 + v n ), there is at least one multilinea r term in P corresp ond ing to a set of k linearly in dep endent ve ctors, with probabilit y at least 1 / 4. Let S b e th e set of those multilinea r terms in P w hic h corresp ond to k linearly ind ep endent v ectors in P ′ ( W 0 + v 1 , . . . , W 0 + v n ). Th en the ab o v e co efficien t c = P i c i for some c i ∈ F corresp onding to the i th multilinear term in S . Conditioned on S 6 = ∅ , w e claim that P i c i = 0 with probabilit y at most 1 / 2 3 . Eac h co efficien t c i comes f rom a s u m of pro ducts of k − 1 elemen ts w i, 1 , . . . , w i,k − 1 corresp onding to some m ultiplication gates g i, 1 , . . . , g i,k − 1 in the circuit. (In the k - path case, note that eac h c i is a su m of pro du cts of the form y i 1 ,i 2 , 1 y i 2 ,i 3 , 2 · · · y i k − 1 ,i k ,k − 1 .) Constru ing the w i ’s as v aria bles, the sum Q ( w 1 , . . . , w s ( n ) ) = P i c i is a de g r e e- k p oly nomial over F in th e v a riables. Ass u ming S 6 = ∅ , Q is not id en tically zero. (Note eac h monomial in Q has coefficient 1.) By the Sc hw artz-Zipp el Lemm a [14], the algorithm’s r an d om assignmen t to the v a riables of Q resu lts in an ev aluat ion of 0 ∈ F with p r obabilit y at most k / | F | = 1 / 2 3 . Since S 6 = ∅ with probabilit y at least 1 / 4, the o ve rall probabilit y of success is at least 1 / 4 · (1 − 1 / 2 3 ) > 1 / 5. 5 Constructing a P ath The algorithm R merely detects if a graph has a k -path. W e note that an O ∗ (2 k ) algorithm pro ducing a k -p ath (when it exists) is easy to obtain; let us briefly outline one p ossible algo rithm of this kind . F or an arbitrary no de v i , w e remo v e v i from the graph and run the k -path detection algorithm for O (log n ) trials, u s ing new rand om bits for eac h trial. If th e algorithm outputs y es in some trial, w e recursive ly call our algo rithm on the graph with v i remo v ed, returning the k -path that it return s. Otherw ise, we add v i bac k to the graph and mo v e to the next candid ate no de v i +1 , noting that s uc h a mo v e o ccurs at most k times (with h igh probabilit y). Hence we can b ound th e r un time with the r ecur rence T ( n ) ≤ O ∗ (2 k · k log n ) + T ( n − 1) , whic h is O ∗ (2 k ). The o v erall probabilit y of error can b e b oun ded b y a constan t less than 1, since the probabilit y that all O (log n ) trials r esult in error is inv ersely p olynomial in n . 4 Conclusion W e end with tw o inte resting op en questions. W e conjecture th at b oth can b e answ ered affirmativ ely . • Let G b e a graph with arb itrary costs on its edges. Th e Shor t Cheap Tour problem is to find a path of length at least k wh ere the total sum of costs on the edges is minimized. This problem is fi xed-parameter tractable, in fact: Theorem 4.1 S hor t Cheap Tour c an b e solve d in O ∗ (4 k ) time by a r andomize d algorithm that suc c e e ds with high pr ob ability. W e omit th e p ro of here; our algorithm is a simple extension of th e divide-and-color approac h for solving k -path [10]. Can Shor t Chea p Tour b e solv ed in O ∗ (2 k ) time? The algorithm of this p ap er do es not app ear to extend to wei ght ed graphs. • Is there a deterministic algorithm for k -p ath with the same runtime co mplexit y as our al- gorithm? Th is question was also raised by Koutis [11], h o w ev er our algorithm lo oks more difficult to derand omize. Our argumen t r elies on the fact that p olynomial identit y testing is in RP , and it is kno wn that a p olytime d erandomization of this w ould imp ly strong circuit lo w er b ounds [8]. 5 Ac kno wledgeme n ts I am very grateful to Yiannis Koutis for sharing an early preprint of his pap er, and f or s ev eral v a luable d iscussions on h is w ork. I also thank Andreas Bj¨ orklund and the anonymous referees for useful commen ts. References [1] Alfred V. Aho, John E. Hop croft, and Jeffrey D. Ullman. The design and analysis of c o mputer algorithms. Ad dison-W esley , 1974. 6 [2] Noga Alon, Raph ael Y u ster, and Uri Zw ic k. C olor-coding. J. ACM 42(4):844– 856, 1995. [3] Da vid L. Applegate, Rob ert E. Bixb y , V asek Ch v´ atal, and William J . Co ok. The tr aveling salesman pr oblem: a c omp utational study. Princeton Unive rsity P ress, 2007. [4] Ric hard Bellman. Dynamic programming tr eatment of the trav e lling salesman p roblem. J. ACM 9(1):6 1–63, 1962. [5] Man uel Blum and Sampath Kannan. Designing p rograms that c hec k their wo rk. J. ACM 42(1): 269–291 , 1995. [6] Jianer C h en, S ong jian Lu, Sing-Hoi Sze, and F engh ui Zhang. Imp ro v ed alg orithms for path, matc hing, and pac king pr oblems. In Pr o c e e dings of ACM-SIAM Symp osium on Discr ete Algo- rithms (SO DA) , 298–307, 2007. [7] Mic hael Held and Ric hard M. Karp. A d y n amic programming app r oac h to sequencing prob- lems. Journal of the So cie ty for Industrial and Applie d Mathematics 10(1):19 6–210, 1962. [8] Russell Imp agliazz o and V alentine K abanets. Derandomizing p olynomial iden tit y tests means pro ving circuit lo w er b oun ds. Computational Complexity 13(1-2 ):1–46, 2004. [9] Ric hard M. Karp. Dyn amic programming meets the prin ciple of inclusion and exclusion. Op- er a tions R ese ar ch L etters 1(2):49– 51, 1982. [10] J oac him Kneis, Daniel M¨ olle , Stefan R ich ter, and Peter Rossmanith. Divide-and-color. In Pr o c e e dings of the International Workshop on Gr ap h-The or etic Conc ep ts in Computer Scienc e (WG) , Springer L NCS 4271, 58–67, 2006. [11] Ioann is Koutis. F aster algebraic algorithms for path and pac king problems. In Pr o c e e dings of the Internat ional Col lo quium on Autom ata, L an guages and Pr o gr amming (ICA LP) , S pringer LNCS 5125, 575–586, 2008. [12] Davi d K. Maslen and Daniel N. Ro ckmo re. Generalized FFTs – a sur vey of some recen t resu lts. Pr o c e e dings of the DIMACS Workshop on Gr oups and Computation , 1995. [13] Bur khard Monien. Ho w to find long paths efficient ly . Anna ls of Discr ete M athematics 25:239 – 254, 1985 . [14] Ra jeev Mot w ani and P r abhak a r Ragha v an. R and omize d algorithms. Cam bridge Univ ersit y Press, 1995 . [15] J acob Scott, T rey Idek er, R ichard M. Karp , and Rod ed Sharan. Efficien t algorithms for d e- tecting signaling p ath w a ys in protein in teraction netw orks. Journal of Computational Biolo gy 13(2): 133–144 , 2006. [16] Victor Shoup . F ast constru ction of ir reducible p olynomials o v er finite fields. Journal of Sym- b o lic Computation 17(5):371 –391, 1994. 7

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment