Complexity of the path avoiding forbidden pairs problem revisited JakubKova´cˇ DepartmentofComputerScience,ComeniusUniversity,Mlynska´Dolina, 84248Bratislava,Slovakia Abstract LetG =(V,E)beadirectedacyclicgraphwithtwodistinguishedverticess,t,andletF beasetofforbiddenpairsof 1 vertices. WesaythatapathinG issafe,ifitcontainsatmostonevertexfromeachpair{u,v} ∈ F. GivenG and F, 1 thepathavoidingforbiddenpairs(PAFP)problemistofindasafes–tpathinG. 0 2 We systematically study the complexity of different special cases of the PAFP problem defined by the mutual positionsoffobiddenpairs. Fixonetopologicalordering≺ofvertices;wesaythatpairs{u,v}and{x,y}aredisjoint, c e ifu≺v≺ x≺y,nested,ifu≺ x≺y≺v,andhalving,ifu≺ x≺v≺y. D The PAFP problem is known to be NP-hard in general or if no two pairs are disjoint; we prove that it remains NP-hard even when no two forbidden pairs are nested. On the other hand, if no two pairs are halving, the problem 5 isknowntobesolvableincubictime. WesimplifyandimprovethisresultbyshowinganO(M(n))timealgorithm, 2 whereM(n)isthetimetomultiplytwon×nbooleanmatrices. ] M Keywords: path,forbiddenpairs,NP-hard,dynamicprogramming D . s c 1. Introduction [ 2 LetG =(V,E)beadirectedgraphwithtwodistinguishedverticess,t∈V andletF ⊆V×V beasetofforbidden v pairs of vertices. We say that a path π is safe, if it does not contain any forbidden pair, i.e., π contains at most one 6 vertexfromeachpair{u,v} ∈ F. GivenGandF,thepathavoidingforbiddenpairsproblem(henceforthPAFP)isto 9 findasafe s–tpathinG. Inthispaper,westudythecomplexityofdifferentspecialcasesoftheproblemondirected 9 3 acyclicgraphs. . 1 1.1. Motivation 1 1 ThePAFPproblemwasfirststudiedbyKrauseetal.[1]andSrimaniandSinha[2]motivatedbydesigningtest 1 cases for automatic software testing and validation. We can represent a program as a directed graph where vertices : v representsegmentsofcodeandedgesrepresenttheflowofcontrolfromonecodesegmentintoanother. Thegoalisto i coverthisgraphwith s–tpathscorrespondingtodifferenttestcases. However,notallpathscorrespondtoexecutable X sequencesintheprogram.ThereforeKrauseetal.[1]introducedforbiddenpairswhichidentifythemutuallyexclusive r a codesegmentsandformulatedthePAFPproblem. Unfortunatelly,asshownbyGabowetal.[3],theproblemisNP- hardevenfordirectedacyclicgraphs. Adifferentmotivationcamefrombioinformaticsandtheproblemofpeptidesequencingviatandemmassspec- trometry. Peptidesarepolymerswhichcanbethoughofasstringsovera20characteralphabetofaminoacidsand thesequencingproblemistodeterminetheaminoacidsequenceofagivenpeptide. Tothisend,manycopiesofthe peptidearefragmentedandthemassofthefragmentsismeasured(veryprecisely)bymassspectrometer. Theresult oftheexperimentisamassspectrumwhereeachpeakcorrespondstomassofsomeprefixorsomesuffixoftheamino acidsequence,orisanoise. Thespectrumisthencomparedagainstadatabaseofknownfragmentweights. Emailaddress:[email protected](JakubKova´cˇ) PreprintsubmittedtoDiscreteAppliedMathematics December30,2011 Chenetal.[4]suggestedthefollowingformulationofthepeptidesequencingproblem: Letuscreateaspectrum graphwithtwovertices p ands foreachpeakw withweightsw(p)=w −1andw(s)=W−w +1,whereW isthe i i i i i i i weightofthewholepeptide. Weaddanedgefromxtoyifthedifferencebetweenweightsw(y)−w(x)equalsthetotal massofsomeknownsequenceofaminoacids. Thus,pathsinthisgraphcorrespondtoaminoacidsequences. Paths goingthrough p correspondtow beingaweightofsomeprefixandsimilarly,pathsgoingthrough s correspondto i i i w beingaweightofsomesuffix. (Pathsgoingthroughneither p nors correspondtow beinganoise.) However,w i i i i i cannotbeapreffixweightandasuffixweightatthesametime,so{p,s}willformaforbiddenpairforeachi. Thisis i i averyspecialcaseofthePAFPproblemindirectedacyclicgraphswherealltheforbiddenpairsarenestedandChen etal.[4]showedthatitispolynomiallysolvable. ThePAFPproblemondirectedacyclicgraphsalsoaroseinacompletelydifferentapplicationinbioinformatics– genefindingusingRT-PCRtests[5]. Inthisapplication,wehaveasocalledsplicinggraphwhereverticesrepresent non-overlapping segments of the DNA sequence, length of a vertex is the number of nucleotides in this segment, andedge(u,v)indicatesthatsegmentvimmediatelyfollowssegmentuinsomegenetranscript. Thus, pathsinthis splicinggraphcorrespondtoputativegenes. Theproblemistoidentifythetruegeneswithahelpofinformationfrom RT-PCRexperiments. Without going into biology details, let us define a (simplified) result of an RT-PCR experiment as a triple t = (u,v,(cid:96)),whereu,v∈V aretwoverticesand(cid:96)isthelengthofaproduct. Letπbeapathgoingthroughuandvinthe splicinggraph;ifthelengthoftheu–vsubpathisequalto(cid:96),wesaythatπexplainstestt,otherwise,itisinconsistent withtestt. WecandefineascoreofapathπwithrespecttoasetoftestsT asasumofthescoresofallofitsvertices andedges,plusabonusBforeachexplainedtestfromT,andminusapenaltyPforeachinconsistenttest. Thegene findingwithRT-PCRtestsproblemistofindan s–t pathwiththehighestscoreinthegivensplicinggraphG witha setofRT-PCRtestsT. Notethatifwesetalllengthstoanunattainablevalue,say−1,andwesetahigh(infinite)penaltyPforinconsistent tests,webasicallygetthePAFPproblem. Thus,thePAFPproblemisatthecoreofgenefindingwithRT-PCRtests and the latter problem inherits all NP-hardness results for the PAFP problem. On the positive side, we have shown in our previous work [5] that some polynomial solutions for special cases of the PAFP problem can be extended to pseudo-polynomialalgorithmsforthegenefindingproblem. 1.2. Previousresults AsshownbyGabowetal.[3],thePAFPproblemisNP-hardingeneral,butseveralspecialcasesarepolynomially solvable. Yinnone[6]studiedthePAFPproblemunderskewsymmetryconditionswhereforeachtwoforbiddenpairs {u,u(cid:48)},{v,v(cid:48)} ∈ F, if there is an edge from u to v, there is also an edge from v(cid:48) to u(cid:48). He proved that under such conditions, the problem is polynomially equivalent to finding an augmenting path with respect to a given matching andthuspolynomiallysolvable. Fordirectedacyclicgraphs,wehavealreadymentionedthatthenestedcaseissolvableinpolynomialtime[4];Kol- manandPangra´c[7]wereabletodeviseapolynomialalgorithmifthesetofforbiddenpairshasawell-parenthesized orahalvingstructure(seePreliminaries). Recently,approximabilityandparameterizedcomplexityofthePAFPproblemhavebeenstudied:Weadd1tothe objectivefunctiontodisallowazerocostsolutions–otherwisetheproblemistriviallyinapproximable. Hajiaghayi etal.[8]showedthateventhenthereisaconstantc > 0suchthatminimizing1+thenumberofforbiddenpairson an s–t pathisnotc·n-approximable. Bodlaenderetal.[9]studiedthePAFPproblemonundirectedgraphs. When parameterized by the vertex cover ofG = (V,E), the problem is W[1]-hard (the proof also carries over to directed acyclicgraphs). Ontheotherhand,whenparameterizedbythevertexcoverofH =(V,F)(whereedgesareforbidden pairs), the problem is fixed parameter tractable (FPT), but has no polynomial kernel unless NP ⊆ coNP/poly. The problemisalsoFPTwhenparameterizedbythetreewidthofG∪H. 1.3. Contributionsandroadmap Inthispaper,wesystematicallystudydifferentspecialcasesofthePAFPproblemondirectedacyclicgraphs. In thenextsection,weintroducethedifferentspecialcasesbasedonmutualpositionsofforbiddenpairs. InSection3, weprovethatthePAFPproblemisNP-hardevenifthesetofforbiddenpairshasorderedstructureandinSections4 and 5, we improve upon the results of Chen et al. [4] and Kolman and Pangra´c [7] for the nested, halving, and well-parenthesizedforbiddenpairs. 2 Table1:ComplexityofthePAFPproblemforitsdifferentspecialcases;nandmdenotethenumberofverticesandedgesofG,respectively;O(nω) isthecomplexityofbooleanmatrixmultiplication,ω<2.3727[10,11]. AllowedForbiddenPairs Problem Complexity Example disjoint nested halving generalproblem (cid:88) (cid:88) (cid:88) NP-hard[3] overlappingstructure × (cid:88) (cid:88) NP-hard[7] ordered (cid:88) × (cid:88) NP-hard[new] well-parenthesized (cid:88) (cid:88) × O(n3)[7],O(nω)[new] halving × × (cid:88) O(n5)[7],O(nω+1)[new] nested × (cid:88) × O(nm)[4],O(nω)[new] disjoint (cid:88) × × O(n+m)[trivial] 2. Preliminaries LetG =(V,E)beadirectedacyclicgraphandletF bethesetofforbiddenpairs. AsalreadynoticedbyYinnone [6]andKolmanandPangra´c[7],wemayassumethateveryvertexexceptforsandtbelongstoexactlyoneforbidden pair,i.e.,(cid:83)F =V −{s,t}. Thisissimplybecauseifvertexvdoesnotbelongtoanyforbiddenpair,wecanremoveit andreplaceall2-edgepathsu,v,wbyadirectedge(u,w). Ontheotherhand,ifvbelongstok > 1forbiddenpairs, wecanreplaceitbyadirectedpathoflengthkandmovetheendsofforbiddenpairstodifferentverticesonthispath. Todefinespecialcasesofinterest, wefixonetopologicalorderingofvertices. Wesaythatvertexuisbeforeor precedesv,u≺v,ifuprecedesvinthislinearorder. Letusdenotetheforbiddenpairs{f, f(cid:48)}fori=1,...,k,where i i f ≺ f(cid:48)and f ≺ f ≺···≺ f ,i.e.,weorderthembypositionoftheleftmemberofthepair. i i 1 2 k Werecognizethreepossibletypesofmutualpositionofpairs{u,v}and{x,y}(withoutlossofgenerality,letu≺v, x≺y,andu≺ x): disjoint(u,v≺ x,y;seeFig.1(a)),nested(u≺ x,y≺v;seeFig.1(b)),andhalving(u≺ x≺v≺y; see Fig. 1(c)). All the special cases are obtained by restricting the set of forbidden pairs F to only certain types of mutualpositions(seeTable1). Thisgivesus23 =8cases,fromwhichthese6classesarenon-trivialandinteresting: (a) disjointpairs (b) nestedpairs (c) halvingpairs Figure1:Differentmutualpositionsoftwoforbiddenpairs. 1. generalcase–therearenoconstraintsonthepositionsofpairs; 2. overlappingstructure1–everytwoforbiddenpairsoverlap(theymaybenestedorhalving,butnotdisjoint);as aconsequence, f ≺ f ≺···≺ f ≺ f(cid:48) ≺ f(cid:48) ≺···≺ f(cid:48) forsomepermutationσ; 1 2 k σ(1) σ(2) σ(k) 3. ordered – there may be disjoint and halving pairs, but no two forbidden pairs are nested; as a consequence f ≺ f ≺···≺ f and f(cid:48) ≺ f(cid:48) ≺···≺ f(cid:48); 1 2 k 1 2 k 4. well-parenthesized–theremaybedisjointandnestedpairs,butnotwopairsarehalving;thiscasedeservesits namesinceifwewrite( and) forthei-thpair,wegetawell-parenthesizedsequence; i i 5. halving–everytwopairshalveeachother; f ≺ f ≺···≺ f ≺ f(cid:48) ≺ f(cid:48) ≺···≺ f(cid:48); 1 2 k 1 2 k 6. nested–thereareonlynestedpairsi.e.,theverticesinforbiddenpairsareordered f ≺ f ≺ ... ≺ f ≺ f(cid:48) ≺ 1 2 k k ···≺ f(cid:48) ≺ f(cid:48);thisisaspecialcaseofthewell-parenthesizedcase. 2 1 1notethatthisspecialcaseisreferedtoashalvingstructurebyKolmanandPangra´c[7];wereservetheterm“halving”forsetswhereeverytwo pairshalveeachother 3 ThepreviousworkandourownresultsaresummarizedinTable1. Forcompletenessandasawarm-up,weincludeourownproofofNP-hardnessofthePAFPprobleminthegeneral andoverlappingcase. ThisproofisalsosimplerthantheonegivenbyKolmanandPangra´c[7]. Theorem1. ThePAFPproblemisNP-hard,evenwhenthesetofforbiddenpairshasoverlappingstructure. Proof. By reduction from 3-SAT: Let φ = (cid:86) φ be a formula over m variables x ,...,x , with n clauses φ = 1≤i≤n i 1 m i ((cid:96) ∨(cid:96) ∨(cid:96) ),whereeachliteral(cid:96) iseither x or¬x . WewillconstructgraphG andasetofforbiddenpairs F i,1 i,2 i,3 i,j k k suchthatthereisans–tpathavoidingpairsinF ifandonlyifφissatisfiable. x1 x2 x3 xm ··· ··· s t ··· ··· ¬x1 ¬x2 ¬x3 ··· ¬xm φ1 φ2 φ3 ··· φn Figure2:InputforthePAFPproblemfortheformulaφ1∧φ2∧···∧φn.Alledgesaredirectedfromlefttoright. G consistsoftwoparts: Thefirstpartcontainsavertexforeachvariable x anditsnegation¬x (seeFig.2). A k k path traversing this first part corresponds to a truth assignment of variables where the visited vertices are true. The secondpartcontainsavertexforeachliteral(cid:96) (seeFig.2). Forbiddenpairsconnectingeveryliteralfromthefirst i,j parttoeveryoccurenceofitsnegationinthesecondpartofGwillensurethatwecanonlygothrough“true”vertices. Thusan s–tpathavoidingF existsifandonlyifeveryclauseissatisfied. Sinceeveryforbiddenpairstartsinthefirst partandendsinthesecondpart,allpairsoverlap. 3. Orderedforbiddenpairs In this section, we turn to a seemingly more restricted version of the PAFP problem, allowing only disjoint and halvingforbiddenpairs. Thisspecialcasehasnotbeenstudiedbefore. Theorem2. ThePAFPproblemisNP-hard,evenwhenthesetofforbiddenpairsisordered. Proof. We will prove the claim by reduction from 3-SAT. Let φ be a logical formula over m variables x ,...,x , 1 m whichisaconjunctionofnclausesφ ∧···∧φ ,whereφ = ((cid:96) ∨(cid:96) ∨(cid:96) )andeachliteral(cid:96) iseither x or¬x . 1 n i i,1 i,2 i,3 i,j k k WewillconstructgraphGwithalinearorder≺onitsverticesandanorderedsetofforbiddenpairsF suchthatthere isans–tpathavoidingpairsinF ifandonlyifφissatisfiable. Graph G consists of several blocks B and B of 2m vertices shown in Fig. 3(a), (b). The blocks are connected (cid:96) togetherasoutlinedinFig.3(c).Anyleft-to-rightpaththroughtheblockBnaturallycorrespondstoatruthassignment ofthevariablesand,sinceB hasanisolatedvertex¬(cid:96),apaththroughblockB correspondstoanassignmentwhere (cid:96) (cid:96) (cid:96) is true. A clause gadget consists of three such blocks, each corresponding to one literal. Any s–t path must pass throughoneofthethreeblocks,andthuschooseanassignmentthatsatisfiestheclause. TheforbiddenpairsinF will enforcethattheassignmentofthevariablesisthesameinallblocks. Thisisdonebyaddingaforbiddenpairbetween allliterals(cid:96)(cid:48)intheB -blockswiththeircounterparts¬(cid:96)(cid:48)inthepreviousandthefollowingB-block. (cid:96) TheorderofliteralsinaB-blockis¬x ≺ x ≺¬x ≺···≺ x ,whiletheorderinaB -blockis x ≺¬x ≺ x ≺ 1 1 2 m (cid:96) 1 1 2 ··· ≺ ¬x . Letvi ≺ vi ≺ vi ≺ ··· betheorderofverticesingraphGi. AzippingoperationtakesgraphsG1,G2,G3 m 1 2 3 andproducesanewgraphG1∪G2∪G3withverticesorderedv1 ≺v2 ≺v3 ≺v1 ≺v2 ≺v3 ≺···. Theclausegadgets 1 1 1 2 2 2 areproducedbyzippingthethreeblockscorrespondingtotheirliterals. Ifwedonotallowmultipleforbiddenpairs startingorendinginthesamevertex,wecansubstituteverticesinGforshortpathsasinFig.3(d). Itiseasytocheck thatundersuchlinearorder,notwopairsinF arenested. 4 ¬x1 ¬x2 ¬x3 ··· ¬xm x1 x2 x3 ··· ‘ ··· xm x1 x2 x3 ··· xm ¬x1 ¬x2 ¬x3 ··· ¬‘ ··· ¬xm (a) Block B–verticesofthisgraphcorrespondto (b) BlockB(cid:96)issimilartoaB-block,exceptthattheorderof positive and negative literals; a path through this verticesisdifferentandvertex¬(cid:96)isisolated. Thus,apath blockcorrespondstoatruthassignmentofthevari- throughB(cid:96)correspondstoanassignmentwhere(cid:96)istrue. ables. φ φ φ 1 2 n B B B ‘1,1 ‘2,1 ‘n,1 s B B B B B t ‘1,2 ‘2,2 · · · ‘n,2 B B B ‘1,3 ‘2,3 ‘n,3 (c) ConstructionofGfromtheblocksandzippedblockscorrespondingtotheclauses.Forbiddenpairsenforcethat theassignmentofvariablesisthesameinallblocks. forbiddenpairs xk xk+1 ··· B‘k,1 ··· ¬xk ¬xk+1 ¬xk ¬xk+1 ··· xk xk+1 ··· B‘k,2 ··· ··· xk xk+1 ¬xk ¬xk+1 blockB xk xk+1 ··· B‘k,3 ··· ¬xk ¬xk+1 clauseφk (d) AnenlargedviewofgraphGshowingblockB,thefollowingblocksforclauseφkandthewaythey areconnectedbyforbiddenpairs.Notethatnotwoforbiddenpairsarenested. Figure3:ConstructionofthegraphGfora3-SATformulaφ.Alledgesaredirectedfromlefttoright. 4. Well-parenthesizedforbiddenpairs ThefirstpolynomialalgorithmforthePAFPproblemwithwell-parenthesizedforbiddenpairswasgivenbyKol- manandPangra´c[7]. Theiralgorithmusesthreerulesforreducingtheinputgraph: 1. contractionofavertex–ifvdoesnotappearinanyforbiddenpair,removeitandaddadirectedge(u,w)for everypairofedges(u,v),(v,w); 2. removalofanedge–ifedgee∈ E∩F joinstwoverticesthatmakeupaforbiddenpair,removeefromE; 3. removal of a forbidden pair – if (u,v) ∈ F is a forbidden pair, but there is no path from u to v, remove (u,v) fromF. Thesethreerulesarealternatelyappliedtotheinputgraphuntilweendupwithvertices sandtonly–eitherjoined byanedgeordisconnected–whichisatrivialproblem. AsimpleimplementationofthisapproachgivesanO(n2m)algorithm. Usingfastmatrixmultiplication,thetime complexitycanbereducedtoO(nω+1)≈O(n3.373)andusingadynamicdatastructurefor“findingpathsanddeleting edgesindirectedacyclicgraphs”byItaliano[12],itcanbereducedstilltoO(n3). HerewedescribeourownO(n3)algorithm,itsadvantagesbeingsimplicity,extensibility,andimprovability: The algorithmdoesnotuseanyadvanceddatastructures. Itcanbeeasilyextendedtosolveproblemssuchas • findans–tpathpassingtheminimumnumberofforbiddenpairsor 5 • givenagraphwherealledgeshavescoresandtherearebonusesorpenaltiesforsome(well-parenthesized)pairs ofvertices,findans–tpathwithmaximumscore(thisproblemwasconsideredbyKova´cˇ etal.[5]). Itseemsunlikelythattheseproblemscanbesolvedusingtheformerapproach(becauseofrule2). Furthermore,our algorithm can be improved using the Valiant’s technique and fast matrix multiplication algorithms [13, 14] or the Four-Russianstechnique[15]. Notethatthereductiontomatrixmultiplicationisnotonlyoftheoreticalinterest,since therearefastandpracticalhardware-basedsolutionsformultiplyingtwomatrices[16,17]. Theorem3. ThePAFPproblemwithwell-parenthesizedforbiddenpairscanbesolvedinO(n3)time. Proof. Wemodifytheinputgraphsothatnotwoforbiddenpairsstartorendinthesamevertex. LetP[u,v]betrueif asafeu–vpathexistsandlet J[u,v]betrueifthereisaforbiddenpair(q,v) ∈ F,u ≺ q ≺ v,andthereisasafeu–v pathsuchthatthefirstedgejumpsoverq. ThevaluesofPand J canbefoundbydynamicprogramming: Itiseasytocompute J[u,v](ifwealreadyknow P[w,v]forallu ≺ w (cid:22) v)byinspectingtheneighboursofuandconversely,wecanalsocompute P[u,v]efficiently usingthetable J: Ifnoforbiddenpairendsinvorvertexuis“inside”theforbiddenpair(q,v) ∈ F, wejustsearch theneighboursofvforavertexthatcouldbepenultimateontheu–vpath. Otherwise, let(q,v) ∈ F beaforbidden pairsuchthatu ≺ q ≺ v. Supposethatasafeu–vpathexistsandletwbethelastvertexonthispathbeforeq. Then P[u,w] and J[w,v] are both true. Conversely, if P[u,w] and J[w,v] are true for some w ≺ q, by concatenating the correspondingpaths,wegetasafeu–vpath: Thepathobviouslyavoidsallforbiddenpairsbeforeorafterq(fromthe definitionofP[u,w]andJ[w,v])andtherearenoforbiddenpairshalving(q,v). Thus,P[s,t]canbecomputedincubictimeusingthefollowingtworecurrences: (cid:40) (cid:87) P[w,v] ifu≺qand(q,v)∈ F isaforbiddenpair (1) J[u,v]= (u,w)∈E,q≺w undefined otherwise true ifu=v P[u,v]= (cid:87)(cid:87)falus(cid:22)ew≺v,((Pw[,vu)∈,EwP]∧[u,Jw[w],v]) iiifff((nuqo,,vvfo))ri∈bsiFaddfieosnrabpifdaodirrebenidnpddaesinri,npuvai≺orrq(q≺,vv)∈ F forq≺u ((23)) u(cid:22)w≺q This algorithm can be further improved to O(nω) time by using fast boolean matrix multiplication. The proof is actually simple thanks to the work of Zakov et al. [14] that simplified and generalized the Valiant’s technique [13]. TheyintroduceagenericproblemcalledInsideVectorMultiplicationTemplate(VMT)whichcanbesolvedin subcubictime. AproblemisconsideredanInsideVMTproblemifitfulfillsthefollowingrequirements: 1. Thegoaloftheproblemistocomputeforeveryi, jaseriesofinsidepropertiesβ1 ,β2 ,...,βK. i,j i,j i,j (cid:76) (cid:16) (cid:17) 2. Let 1 ≤ k ≤ K, and let µk be a result of a vector multiplication of the form µk = βk(cid:48) ⊗βk(cid:48)(cid:48) , for i,j i,j q∈(i,j) i,q q,j some1 ≤ k(cid:48),k(cid:48)(cid:48) ≤ K. Assumethatthefollowingvaluesareavailable: µk ,allvaluesβk(cid:48) for1 ≤ k(cid:48) ≤ K and i,j i(cid:48),j(cid:48) (i(cid:48), j(cid:48))(cid:40)(i, j)andallvaluesβk(cid:48) for1≤k(cid:48) <k. Then,βk canbecomputedino(n)time. i,j i,j 3. In the multiplication variant that is used for computing µk , the ⊕ operation is associative, and the domain of i,j elementscontainsazeroelement. Inaddition,thereisamatrixmultiplicationalgorithmforthismultiplication variant,whoserunningtimeM(n)overtwon×nmatricessatisfiesM(n)=o(n3). Theorem 4 (Zakov et al. [14]). For every Inside VMT problem there is an algorithm whose running time is o(n3). Inparticular, let M(n)bethecomplexityofthematrixmultiplicationusedandsupposethatβk canbecomputedin i,j Θ(1) time in item 2 of the definition above. Then the time complexity is Θ(M(n)logn), if M(n) = O(n2logkn); and Θ(M(n)),ifM(n)=Ω(n2+ε)forε>2and4M(n/2)≤d·M(n)forsomed <1andsufficientlylargen. Corollary1. ThePAFPproblemwithwell-parenthesizedforbiddenpairscanbesolvedinO(nω)time,where2<ω< 2.3727istheexponentinthecomplexityofthebooleanmatrixmultiplication. 6 Proof. WeformulateoursolutionfromTheorem3asanInsideVMTproblem. Thegoalistocomputeinsideproper- tiesA,J,α,β,P,P(cid:100)•,andP•(cid:100). Properties J andP correspondtothedynamicprogrammingtablesfromtheproof u,v u,v ofTheorem3,otherpropertiesareauxilliary.PropertyAistheadjacencymatrixofgraphGanditisconstant(A =1 u,v ifandonlyif(u,v)∈ E). Propertiesα,βareusedtostorethepartialresultsfromcases(2)and(3)inthecomputation of P[u,v]. Finally,theauxiliaryproperties P(cid:100)• and P•(cid:100) canbecomputedfrom Pinconstanttimeandaredefinedas follows: P(cid:100)• = P ∧(q≺w) if(q,v)∈ F,elsefalse P•(cid:100) = P ∧(w≺q) if(q,v)∈ F,elsefalse w,v w,v w,v w,v NowwecanrewritethecomputationofJ andP usingbooleanvectormultiplicationasfollows: u,v u,v (cid:87) P[w,v] (cid:32) J =(cid:76) (A ⊗P(cid:100)•) (1’) (u,w)∈E,q≺w u,v w∈(u,v) u,w w,v (cid:87) P[u,w] (cid:32) α =(cid:76) (P ⊗A ) (2’) u(cid:22)w(cid:22)v,(w,v)∈E u,v w∈(u,v) u,w w,v (cid:87) (P[u,w]∧J[w,v]) (cid:32) β =(cid:76) (P•(cid:100) ⊗J ) (3’) u(cid:22)w≺q u,v w∈(u,v) w,v w,v PropertyP canbecomputedfromα andβ inconstanttime. u,v u,v u,v 5. Theothercasesandconcludingremarks NotethattheO(nω)algorithmforwell-parenthesizedforbiddenpairsalsoimprovesupontheresultbyChenetal. [4]forthenestedcase. Itremainsanopenproblemwhetherthereisamoreefficientalgorithmforthenestedcase. AnO(nω+1)timealgorithmforhalvingforbiddenpairsisachievedbyarefinedversionofthealgorithmgivenby KolmanandPangra´c[7].Recallthatinthiscase,theinputgraphGconsistsoftwoparts:alltheforbiddenpairsstartin thefirstpart,andendinthesecondpartinthesameorder. Letusdenotetheverticesinthefirstparts≺ x ≺···≺ x 1 n andverticesinthesecondparty ≺ ··· ≺ y ≺ t,where{x,y}areforbiddenpairs. Wemayassumethatallvertices 1 n i i areaccessiblefromsandthattisaccessiblefromeveryvertex. Ifthereisadirectedgefromstothesecondpartorifthereisanedgefromthefirstparttot,asafes–tpathexists trivially. Otherwise,wereducethehalvingcasetoninstancesofthenestedcase. Therewillbeasafes–tpathinGif andonlyifthereisasafes–t(cid:48)pathinatleastoneoftheproducedinstances. First,removeallthe(x,y )edges,addanewterminalvertext(cid:48),andreversethedirectionofalledgesinthesecond i j part ofG. Note that in this new order, s ≺ x ≺ ··· ≺ x ≺ t ≺ y ≺ ··· ≺ y ≺ t(cid:48), the forbidden pairs are nested. 1 n n 1 The k-th instance is obtained by adding edges (x ,t) and (y ,t(cid:48)) for each edge (x ,y ), so there is a safe s–t path k (cid:96) k (cid:96) s,...,x ,y ,...,tintheoriginalgraphGifandonlyifthereisasafes–t(cid:48)paths,...x ,t,...,y ,t(cid:48)inthenewgraph. k (cid:96) k (cid:96) Itremainsanopenproblemwhetheramoreefficientalgorithmexists. Acknowledgements. The autor would like to thank Bronˇa Brejova´ for many constructive comments. The research of Jakub Kova´cˇ is supported by APVV grant SK-CN-0007-09 Marie Curie Fellowship IRG-231025 to Dr. Bronˇa Brejova´, Come- niusUniversitygrantUK/121/2011,andbyNationalScholarshipProgramme(SAIA),SlovakRepublic. Preliminary versionofthisworkappearedinKova´cˇ etal.[5]. References [1] K.Krause, R.Smith, M.Goodwin, Optimalsoftwaretestplanningthroughautomatednetworkanalysis, in: Proc.1973IEEESymp.on ComputerSoftwareReliability,18–22,1973. [2] P.K.Srimani,B.P.Sinha,Impossiblepairconstrainedtestpathgenerationinaprogram,Inf.Sci.28(2)(1982)87–103. [3] H.N.Gabow,S.N.Maheswari,L.J.Osterweil,OnTwoProblemsintheGenerationofProgramTestPaths,IEEETrans.SoftwareEng.2(3) (1976)227–231. [4] T.Chen,M.-Y.Kao,M.Tepel,J.Rush,G.M.Church,ADynamicProgrammingApproachtoDeNovoPeptideSequencingviaTandem MassSpectrometry,J.Comput.Biol.8(3)(2001)325–337. [5] J.Kova´cˇ,T.Vinaˇr,B.Brejova´,PredictingGeneStructuresfromMultipleRT-PCRTests,in:S.Salzberg,T.Warnow(Eds.),WABI,vol.5724 ofLectureNotesinComputerScience,Springer,ISBN978-3-642-04240-9,181–193,2009. [6] H.Yinnone,OnPathsAvoidingForbiddenPairsofVerticesinaGraph,DiscreteAppl.Math.74(1)(1997)85–92. 7 [7] P.Kolman,O.Pangra´c,Onthecomplexityofpathsavoidingforbiddenpairs,DiscreteAppl.Math.157(13)(2009)2871–2876. [8] M.Hajiaghayi,R.Khandekar,G.Kortsarz,J.Mestre,TheCheckpointProblem,in:M.J.Serna,R.Shaltiel,K.Jansen,J.D.P.Rolim(Eds.), APPROX-RANDOM,vol.6302ofLectureNotesinComputerScience,Springer,ISBN978-3-642-15368-6,219–231,2010. [9] H.L.Bodlaender,B.M.P.Jansen,S.Kratsch,KernelBoundsforPathandCycleProblems,in:Proc.ofthe6thInternationalsymposiumon ParameterizedandExactComputation(IPEC),2011. [10] D.Coppersmith,S.Winograd,MatrixMultiplicationviaArithmeticProgressions,J.Symb.Comput.9(3)(1990)251–280. [11] V.Williams,BreakingtheCoppersmith-Winogradbarrier,2011. [12] G.F.Italiano,FindingPathsandDeletingEdgesinDirectedAcyclicGraphs,Inf.Process.Lett.28(1)(1988)5–11. [13] L.G.Valiant,GeneralContext-FreeRecognitioninLessthanCubicTime,J.Comput.Syst.Sci.10(2)(1975)308–315. [14] S.Zakov,D.Tsur,M.Ziv-Ukelson,ReducingtheworstcaserunningtimesofafamilyofRNAandCFGproblems,usingValiant’sapproach, AlgorithmsMol.Biol.6(1)(2011)20. [15] V.Arlazarov,E.Dinic,M.Kronrod,I.Faradzev,Oneconomicconstructionofthetransitiveclosureofadirectedgraph,in: SovietMath. Dokl.,vol.11,1209–1210,1970. [16] S.Ryoo,C.I.Rodrigues,S.S.Baghsorkhi,S.S.Stone,D.B.Kirk,W.meiW.Hwu,Optimizationprinciplesandapplicationperformance evaluationofamultithreadedGPUusingCUDA,in:S.Chatterjee,M.L.Scott(Eds.),PPOPP,ACM,ISBN978-1-59593-795-7,73–82,2008. [17] V.Volkov,J.Demmel,BenchmarkingGPUstotunedenselinearalgebra,in:SC,IEEE/ACM,ISBN978-1-4244-2835-9,31,2008. 8