EmailEmailResearchsupportedbyaStanfordSchoolofEngineeringHooverFellowshipNSFGrantCCF1417238andBSFGrantBSF2012338EmailyResearchsupportedbyBSFgrantno2012338andbytheTheIsraeliCentersof ID: 448200
Download Pdf The PPT/PDF document "ListingTrianglesAndreasBjorklund1?,Rasm..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
ListingTrianglesAndreasBjorklund1?,RasmusPagh2??,VirginiaVassilevskaWilliams3???,andUriZwick4y1DepartmentofComputerScience,LundUniversity,Sweden.2ITUniversityofCopenhagen,Denmark.3ComputerScienceDepartment,StanfordUniversity,USA.4BlavatnikSchoolofComputerScience,TelAvivUniversity,Israel.Abstract.Wepresentnewalgorithmsforlistingtrianglesindenseandsparsegraphs.Therunningtimeofouralgorithmfordensegraphsis~(n!n3(! 1)=(5 !)t2(3 !)=(5 !)),andtherunningtimeofthealgo-rithmforsparsegraphsis~(m2!=(!+1)m3(! 1)=(!+1)t(3 !)=(!+1)),wherenisthenumberofvertices,misthenumberofedges,tisthenumberoftrianglestobelisted,and!2:373istheexponentoffastmatrixmultiplication.Withthecurrentboundon!,therunningtimesofouralgorithmsare~(n2:373n1:568t0:478)and~(m1:408m1:222t0:186),respectively.Werstobtainrandomizedalgorithmswiththedesiredrun-ningtimesandthenderandomizethemusingsparserecoverytechniques.If!=2,therunningtimesofthealgorithmsbecome~(n2nt2=3)and~(m4=3mt1=3),respectively.Inparticular,if!=2,ouralgorithmlistsmtrianglesin~(m4=3)time.Patrascu(STOC2010)showedthat(m4=3 o(1))timeisrequiredforlistingmtriangles,unlessthereexistsubquadraticalgorithmsfor3SUM.Weshowthatunlessonecansolvequadraticequationsystemsoveraniteeldsignicantlyfasterthanthebruteforcealgorithm,ourtrianglelistingruntimeboundsaretightassuming!=2,alsoforgraphswithmoretriangles.1IntroductionAlgorithmicproblemsconcerningthesetoftrianglesinagraphhaverecentlyreceivedmuchattention,duetoapplicationsinvariouskindsofgraphanalysissuchasthestudyofsocialprocesses[8],communitydetection[5],anddensesubgraphmining[26].Manyoftheseproblemsrequirethelistingofalltrianglesinagraph|see[24,6,4]foranumberofexamples.Weconsidersimple,directedorundirectedgraphswithnverticesandmedges.Adensegraphmaycontain(n3)triangles,sointermsofntheworst-case ?E-mail:.??E-mail:.???ResearchsupportedbyaStanfordSchoolofEngineeringHooverFellowship,NSFGrantCCF-1417238andBSFGrantBSF:2012338.E-mail:yResearchsupportedbyBSFgrantno.2012338andbytheTheIsraeliCentersofRe-searchExcellence(I-CORE)program,(CenterNo.4/11).E-mail:. complexityofthetrivialcubictimealgorithmisoptimal.However,mostgraphsofinterestarenotdense.In1978ItaiandRodeh[13]obtainedanalgorithmforlistingalltrianglesinOm3=2,whichisalwaysanimprovementoverthenaveOn3algorithm.Theiralgorithmisoptimalasagraphwithmedgesmaycontain\nm3=2triangles.Inthispaperweconsideroutputsensitivealgorithmsfortrianglelisting,whichrunasymptoticallyfasterwhenthenumbertoftrianglesissmall,withnoadditionalassumptionsontheinputgraph.(Forexample,wedonotconsiderrunningtimeboundsintermsofgraphparameterssuchasarboricity.)Ourapproachistocombineknowntechniquesforcountingthenumberoftriangles,usingfastmatrixmultiplication,withalgebraicandcombinatorialtechniquesthatallowustocomputetheactualtriangles.Weinitiallyobtainrandomizedalgorithmswhichwethenderandomizeusingsparserecoverytechniques.Sinceourfocusisonconstantsintheexponentsofrunningtime,weuse~O()notationtosuppressmultiplicativefactorsofsizeno(1).Fordensegraphs,ouralgorithmrunsin~On!+n3(! 1)=(5 !)t2(3 !)=(5 !)time,where!2:373istheexponentofsquarematrixmultiplication[27,18].Forsparsegraphs,ouralgorithmrunsin~Om2!=(!+1)+m3(! 1)=(!+1)t(3 !)=(!+1)time.Undertheassumption!=2algorithmsrunin~On3and~Om3=2algorithmsforeverypossiblevalueoft.Ourdenseandsparsealgorithmsareinter-dependent.Thedensealgorithmperformsasparsifyingstepsandcallsthedensealgorithm,whilethesparsealgorithmperformsadensifyingstepandcallsthedensealgorithm.Patrascu[23]hasshownthatlistingmtrianglesinagraphwithmedgesrequirestime\nm4=3 ",forevery"-0.8;䀀0,unlessthereexistsanalgorithmfor3SUMrunninginOn2 time,forsome-0.8;䀀0.Ouralgorithmlistsmtrian-glesin~Om2!=(!+1)time.Withthecurrentbound!2:373,ouralgorithmlistsmtrianglesinOm1:408.Interestingly,if!=2,therunningtimebecomes~Om4=3,essentiallymatchingtheconditionallowerboundofPatrascu[23].Signicantimprovementsoftheexponentsinourresultsarethereforeunlikely.ThebestpreviouslyavailablealgorithmsfortrianglelistingthatweareawareofaretheOm3=2algorithmofItaiandRodeh[13],fromwhichitisalsoeasytoobtainan~On!+min(n3;nt;t3=2)algorithm,andanOt1 !=3n!-timealgorithmthatfollowsfromareductionbyWilliamsandWilliams[28,CorollaryG.1]fromtrianglelistingtotriangledetection.Therunningtimesobtainedbyouralgorithmsimproveuponbothoftheaforementionedpriorresultsforallvaluesoft.1.1RelatedworkFigure1comparestheresultsdescribedabove,focusingonworst-casetimecom-plexity.Forcompletenesswenowdescribesomeotherrelatedworkthatisnotdirectlycomparabletoourresults.Quiteabitofworkhasbeendoneontrianglelistingalgorithmsthatperformwellonreal-lifegraphs.ThepaperofSchankandWagner[24]containsagood2 Reference Timebounds If!=2 ItaiandRodeh[13] ~n!+min(n3;nt;t3=2)m3=2 ~n2+min(nt;t3=2) WilliamsandWilliams[28] ~n!t1 !=3 ~n2t1=3 Patrascu[23] ~(min(m4=3;n2;t4=3)) Thispaper ~n!n3(! 1) 5 !t2(3 !) 5 !~m2! !+1m3(! 1) !+1t3 ! !+1 ~n2nt2=3~m4=3mt1=3 Fig.1.Upperand(conditional)lowerboundsforlistingttrianglesinagraphofnverticesandmedges.Theresultsarestatedintermsoftheexponent!ofsquarematrixmultiplication,whichisknowntobebelow2:373[27].Allboundsholdareforworst-casegraphsandholdforeverychoiceofn;m;t1.Therightmostcolumnhighlightstheupperboundsthatwouldresultif!=2.ThelowerboundbyPatrascumarkedbyreliesontheassumptionthat3SUMrequires~(n2)time.overviewofvariousalgorithmswithOm3=2worst-caserunningtime,andin-vestigateshowwellthesealgorithmsperformongraphsfromvariousapplicationareas,oftenrunningmuchfasterthantheworst-caseanalysiswouldsuggest.Onealgorithmthatisoftenabletobeattheworst-caseboundisbasedonenu-meratingasetof2-pathswherethedegreeofthemiddlevertexisnolargerthanthedegreesofthestartandendvertices(thisisasimpliedversionofnode-iterator-corefrom[24]).Recently,Berryetal.[4]gaveatheoreticalexplanationwhytrianglelistingisfastformostgraphs,evenforgraphswithaskeweddegreedistribution,bystudyingaclassofrandomgraphs.Recentlymanyauthorshavestudiedtrianglecountingandlistingalgorithmsformassivegraphs,usingeitherexternalmemory[10,20]ortheMapReduceframeworkfordistributedcomputation[1].However,forworst-casegraphsthesealgorithmsalluse\n(m3=2)time,evenwhenthenumberoftrianglesiszero.Asmentionedabove,Patrascu[23]showedalinkbetweentrianglelistingandthetimecomplexityof3SUM.JafargholiandViola[14]furtherinvestigatedthisconnection,showingthatsurprisingalgorithmsfor3SUMwouldleadtosurprisingalgorithmsfortrianglelisting.Alon,Yuster,andZwick[2]showhowtoecientlydetectthepresenceofsmallsubgraphsinsparsegraphs.FortrianglestheyachieveatimeboundofOm2!=(!+1),andthealgorithmevenallowscountingthenumberoftriangles.Thealgorithmconsistsofadensicationstepthatenumeratesall2-paths(i.e.,pathswithtwoedges)throughverticeswithdegreeatmost,foraparameter.Inthiswayalltrianglesthatcontainavertexofdegreeatmostarefound.Thenumberoftriangleswithinthesetofverticesofdegreelargerthanisfoundbysquaringtheadjacencymatrix,whichforeverypairofverticesgives3 thenumberof2-pathsthatconnectthem.Summingoveralledgeswegetthenumberoftrianglesmultipliedby3.Manyauthorshavegivenecientalgorithmsforapproximatelycountingthenumberoftrianglesinagraph,seee.g.[16]anditsreferences.Mostofthesederiveanestimatorbysomekindofsamplingfollowedbyanexacttrianglecountingalgorithm.1.2OurcontributionsOurcentralcontributionisarandomizedalgorithmthatlists(withhighproba-bility)alltrianglesinagraphbyalternatingtwoprocedures:{Densifying:Eliminateverticesoflowdegreesbyenumeratingall2-pathsgoingthroughthem,and{Sparsiying:Eliminateedgesthatarepartoffewtrianglesbyreportingallsuchtrianglesusingsparsesignalrecoverytechniques.Wecanderandomizethealgorithmatacostofafactorno(1)intherunningtimebyusingknownexplicitconstructionsfromthesparsesignalrecoverylit-erature.Let!denotetheexponentofsquarematrixmultiplication.Insection3weshow:Theorem1Thereexistsadeterministicalgorithmthatlistsallttrianglesinagraphofnverticesintime~On!+n3(! 1)=(5 !)t2(3 !)=(5 !).Withthebound!2:373[27]wegetatimeboundofOn2:373+n1:568t0:478.Insection3wealsoderivethefollowingtheorem:Theorem2Thereexistsadeterministicalgorithmthatlistsallttrianglesinagraphofmedgesintime~Om2!=(!+1)+m3(! 1)=(!+1)t(3 !)=(!+1).Usingtheboundon!asaboveweget:Om1:408+m1:222t0:186.Inparticular,listingmtrianglesinagraphofmedgescanbedoneintimeOm1:408.Wenotethatif!=2thetimecomplexityforlistingmtrianglesreducesto~Om4=3,meetingtheconditionallowerboundof[23]basedonhardnessof3SUM.Insection6weshowthatunlessanotherseeminglydicultproblemhasfasteralgorithms,namelyquadraticsystemsofequations(QES),ourtworuntimeboundsaretightalsoforgraphswithmoretriangles.QESisdenedasfollows.LetFbeaniteeldandjFjitsnumberofelements.AquadraticequationsystemoverFlisasetofkquadraticequationsinlvariablesoverF.ItiseasytoseethatQESisNP-complete,asforinstanceNAESATeasilyreducestoitwithoneequationperclausealreadyoverF=GF(2),anditisapolynomialtimetasktoverifyapurportedsolution.QESisawell-studiedproblem.TheassumptionthatQESisintractableevenonaveragehasbeenusedtodesignseveralimportantcryptosystems(e.g.[17,21]).AfasteralgorithmforQESwouldhelpattackthese.Somealgorithmsthatworkwellinpracticehavebeendesigned(seee.g.[15,7]),thoughintheworst4 case,thesedonotimproveovertheexhaustivesearchjFjlpoly(l;k)timealgo-rithm.Itisabigopenproblemwhetheronecanobtainasubstantialimprove-ment(oftheformjFj(1 ")lforsome"0)overexhaustivesearchforQES.Weshowthatifonecouldimproveuponourtrianglelistingalgorithms(and!=2),thenQESdoesindeedhavefasteralgorithmsoveranyF.Theorem3Supposethatforsome10,20with1+20,thereexistsanalgorithmthatlistsallttrianglesinanm-edgegraphinO(m1 1t(1 2)=3)timeorinann-vertexgraphinO(n1 1t(1 2)2=3)time.Then,foranyniteeldF,thereexistsanjFj(1 )lpoly(l;k)timealgorithmfor0thatsolvesl-variatequadraticequationsystemswithkequationsoverFl.ThehardnessofQESwasrstusedasanassumptiontobaselowerboundsonbyVassilevskaandWilliams[25]whoshowedthatafastenoughalgorithmfordeterminingwhetheranundirectedgraphwithedgeweightsfromsomeeldFhasak-cliqueoftotalweight0(overF)wouldimplyafasterthanexhaustivesearchalgorithmforQES.Inspirit,theproofofTheorem??issimilartotheproofin[25].2ListinglighttrianglesLetbeaparameter.Wesaythatanedgeis-light,orjustlight,ifitpar-ticipatesinatmosttriangles,otherwise,itissaidtobe-heavy.Atriangleis-lightifatleastoneoftheedgesparticipatinginitislight,otherwiseitis-heavy.Inthissectionwedescribeasimplerandomizedalgorithmforlistingall-lighttriangleswithhighprobability.Thisalgorithmisusedasabuildingblockbyouralgorithmsforlistingalltrianglesindenseandsparsegraphs.Weincludethissimplerandomizedalgorithmforcompleteness.Theideasbehindithavebeenusedbefore,forinstancebyGasieniecetal.[9]who,build-inguponworkofAumannetal.[3]showedhowtondkwitnessesforBooleanmatrixmultiplicationin~On2k+n!k(3 ! )=(1 )time.InSection4wede-scribeanoveldeterministicversionofthealgorithmdescribedinthissectionusingsparserecoverytechniques.Theorem4LetG=(V;E)beagraphonnverticesandlet1n.Then,all-lighttrianglesinGcanbefoundin~On!3 !time,withhighprobability.Proof.Weassume,withoutlossofgenerality,thatV=[n]=f1;2;:::;ng.LetAbetheadjacencymatrixofthegraph.LetAbethematrixAinwhichallthe1sinthek-thcolumnofAarereplacedbyk,fork2[n].LetSV,letA[;S]denotethematrixobtainedfromAbyselectingthecolumnswhoseindicesbelongtoS.Similarly,letA[S;]denotethematrixobtainedbyselectingtherowsofAwhoseindicesbelongtoS.TherectangularBooleanproductA[;S]A[S;]tellsus,foreveryi;j2[n],whetherthereisapathoflength2fromitojthatpassesthroughavertexofS.Ifthereisonlyonesuch2-path,thenthe(i;j)-thentryoftheproductA[;S]A[S;]identiesthekforwhich(i;k);(k;j)2E.5 Supposenowthat(i;j)2Eisa-lightedge,andletTi;j=fk2Vj(i;k);(k;j)2Egbethesetof`mid-points'ofthetrianglespassingthroughtheedge(i;j).NotethatjTi;jj.LetSbearandomsubsetofVofsizen=.Letk2Ti;j.TheprobabilitythatjS\Ti;jj=1isatleast1 (1 1 ) 11 e.Thus,ifwechooseO(logn)randomsubsetsofsizen=,wecan,withhighprobability,identifyalllighttriangles.AseachproductA[;S]A[S;]andA[;S]A[S;],wherejSj=n=,canbecomputedin~O(n2(n=)! 2)(bydecomposingeachrectangularmatrixproductintosquarematrixproducts),theO(logn)productscouldallbecomputedin~O(n!3 !)time.utItisnotdiculttoconvertthealgorithmintoaLasVegasalgorithmwhoseexpectedrunningtimeis~O(n!3 !).Theideaistocheckthateachreportedtriangleexists,andcheckforeachedgethatthenumberoftrianglesreportediscorrect(bycomparingtothenumberof2-pathsconnectingitsendpoints).Aspointedoutby[9],usingfastrectangularmatrixmultiplication[11,19],onecanimprovetherunningtimeofTheorem4to~On!(3 !)=(1 )+n2~On2+n2:3730:464.Here0:303isthelargestconstantsuchthatnnbynnmatricescanbemultipliedin~On2time.ThisimpliesslightimprovementsofthetimeboundsinTheorems1and2.3ListingalltrianglesWenextdescribetwoalgorithmsforlistingalltrianglesindenseandsparsegraphsthatuseeachotherassubroutines.WeletDense(n;t)bethealgorithmforlistingalltrianglesinagraphonnverticescontainingatmostttriangles,anduseD(n;t)todenotetherunningtimeofDense(n;t).Similarly,weletSparse(m;t)bethealgorithmforlistingalltrianglesinagraphwithmedges(weassumethatthegraphhasnoisolatedverticestomakemaproperboundonthesizeofthegraph)containingatmostttriangles,andletS(m;t)denotetherunningtimeofSparse(m;t).Weassumethatthesealgorithmsreceiveanupperboundtonthenumberoftrianglesintheinputgraph.Thisupperboundcanbecomputedbeforecallingouralgorithms,eitherin~O(n!)time,orinOm2!=(!+1)time[2].Sparse(m;t)worksasfollows.Itchoosesaparameterdependingonmandt.Verticesofdegreeatmostaresaidtobelowdegreevertices.Verticesofdegreegreaterthanaresaidtobehighdegree.Thealgorithmstartsbyndingalltrianglesthatcontainalowdegreevertex.ThiscanbeeasilydoneinO(m)timebyexaminingforeveryedgeincidentonalowdegreevertexx,thelength2-pathsformedbytakinganotheredgeoutofx.Oncethisisdonewecanremovealledgesincidenttolowdegreevertices.Ifnoedgesremainwestop|otherwise,allremainingtriangles,i.e.,trianglesthatonlyincludehighdegreeverticescannowbefoundbyacalltoDense(2m=;t),asthereareatmost2m=highdegreevertices.Thus,ignoringconstantfactors,S(m;t)m+D(2m=;t):(1)6 Dense(n;t)worksasfollows.Ifn3,itreturnsnotriangles.Otherwise,itchoosesaparameterdependingonnandt.Itthenndsall-lighttrianglesin~On!3 !timebyTheorem4(oritsdeterministicversionfromSection4).Oncethisisdonewecanremoveall-lightedges.Ifnoedgesremainwestop|otherwise,astherecanbeatmost3t=-heavyedges,all-heavytrianglescanbefoundbyacalltoSparse(3t=;t).Thus,ignoringno(1)factors,D(n;t)n!3 !+S(3t=;t):(2)Toanalyzetherunningtimesofthetwoalgorithmsweset=dmax(3;6n (!+1)=(5 !)t2=(5 !))e;and=d2max(m(! 1)=(!+1);m2(! 2)=(!+1)t(3 !)=(!+1))e:Supposerstthattm.Noticethatsinceweneverchangetandthenumberofedgesneverincreasesovertherecursivecalls,ifweeverhavetm,wehavetminallsubsequentcalls.Weget=2m2(! 2)=(!+1)t(3 !)=(!+1);m=2m3(! 1)=(!+1)t(3 !)=(!+1):Considertherstrecursivecalltothedensealgorithm,andsupposethatitwascalledonnnodes,whereweknowthatn2m=.Wegetthefollowing:n2m==m(5 !)=(!+1)t (3 !)=(!+1):n(!+1)=2(2m=)(!+1)=2=m(5 !)=(!+1) t(3 !)=(!+1)(!+1)=2=t(m=t)(5 !)=2:Thus,t=n(!+1)=2(t=m)(5 !)=2whichis1whentm,andsince=maxf3;6(t=n(!+1)=2)2=(5 !)g,wegetthat=6(t=n(!+1)=2)2=(5 !)6t=m:Wenowget:n!3 !=63 !n3(! 1)=(5 !)t2(3 !)=(5 !)63 !(2m=)3(! 1)=(5 !)t2(3 !)=(5 !)=63 !m3(! 1)=(!+1)t(3 !)=(!+1):(3)Since6t=m,wegetthat3t=m=2,andhenceS(3t=;t)S(m=2;t).ByEq.1andEq.2wehaveS(m;t)m+n!3 !+S(3t=;t)(2+63 !)m3(! 1)=(!+1)t(3 !)=(!+1)+S(m=2;t)dlogmeX=1(2+63 !)(m=2)3(! 1)=(!+1)t(3 !)=(!+1)2Om3(! 1)=(!+1)t(3 !)=(!+1):7 Nextassumetm.Weget=2m(! 1)=(!+1).Bytheaboveanalysiswegetthat6(t=m)(5 !)=2,andsowhentm,wehave36.Wealsohaven2m==m2=(!+1).ByEq.1andEq.2wehaveS(m;t)m+n!3 !+S(3t=;t)(2+63 !)m2!=(!+1)+S(t;t)(2+63 !)m2!=(!+1)+Ot2!=(!+1)2Om2!=(!+1):OncewehaveestablishedthecomplexityofSparse(m;t),itisalsoeasytoestablishthecomplexityofDense(n;t).Thereareagaintwocases.Iftn(!+1)=2,then36andtherunningtimeisD(n;t)=O(n!+S(t;t))=O(n!):Ift-352;.219;n(!+1)=2,then=6n (!+1)=(5 !)t2=(5 !)andthenD(n;t)n3(! 1)=(5 !)t2(3 !)=(5 !)+S(3t=;t)(n3(! 1)t2(3 !))1=(5 !)+S((t(3 !)n(!+1))1=(5 !);t)(n3(! 1)t2(3 !))1=(5 !)+(t3 !n!+1)3(! 1)=((!+1)(5 !))t(3 !)=(!+1)=On3(! 1)=(5 !)t2(3 !)=(5 !);asrequired.4DeterministicalgorithmRandomizationwasonlyusedbythealgorithmforlistinglighttriangles.Wenowproceedtoshowhowtolistall-lighttriangles.Thisisachievedbycomputing,foreverylightedge,thelistofatmost2-pathsconnectingitsvertices.Eachsuchlistcanbethoughtofasavectorx2f0;1gnwithatmost1s,correspondingtotheconnectingnodes.LetPdenotethesetofsuchvectorsthatwewouldliketocompute.TothisendwemakeuseofasparserecoverymatrixTwiththefollowingproperties,forsomefunctionf(n)=no(1):{Thasd=(f(n))rows.{Thenumberofnon-zeroentriesinTisatmostnf(n).{Foreveryx2P,wecancomputexfromTxintimeO(f(n)).Randomsparse0-1matricesareknowntohavethesepropertieswithhighprob-abilityforf(n)=(logn)O(1)(seee.g.[22]foranoverviewofsuchconstructions),andtherealsoexistexplicit,deterministicconstructionswithf(n)=no(1)[12].LetDdenotethediagonalmatrixwherethejthentryalongthediagonalisequaltoTi;j.8 LetAdenotetheadjacencymatrixofthegraph.Tondalllighttriangleswecompute,fori=1;:::;d,thematrixproductADA.IfDhasnnon-zeroentries,thisreducestoann-by-ntimesn-by-nmatrixproduct.Foreveryx2PthisgivesusthevectorTx.Specically,ifxisthesetofverticesconnectingverticesaandb,(Tx)=(ADA)a;b.Thismeansthatwecanrecovereachx2PintimeO(f(n)).ThematrixproductADAcanbedecomposedintoO(n=n)2squarema-trixproducts,eachtakingtimeO(n!).BychoiceofTwehavePndf(n).SothetimeforcomputingalldmatrixproductsisboundedbyaconstanttimesdX=1n2n! 2dn2 dX=1n=d!! 2dn2(nf(n)=d)! 2=n!3 !f(n)! 1:TherstinequalityusesJensen'sinequalityandthefactthatn! 2isconcave(since! 22[0;1]).ThesecondinequalityusesourboundsondandPn.Similarlytoourrandomizedalgorithm,thedeterministicalgorithmcanbeim-provedtohaveruntime~On!(3 !)=(1 )+n2usingrectangularmatrixmultiplication.5ListingsometrianglesIfagraphcontainsTtrianglesandweareonlyrequiredtolisttofthem,thenanimprovedrunningtimecanbeobtainedasfollows.Firstassumethatthegivengraphistripartitebycreatingthreecopiesofeachvertexv,vIinpartitionI,vJinpartitionJandvKinpartitionK.Theneachedge(u;v)appears6times,onceforeachpairofcopiesofuandvindierentpartitions.Eachtriangleappears6timesaswell,soitsucestolist6ttrianglesinthisnewgraph.SupposenowthatwewanttolistttrianglesinatripartitegraphwithTttriangles.Wedesignarecursivealgorithmasfollows.SplitI;J;Kinto2partsofn=2nodeseach,I1;I2;J1;J2;K1;K2.Countthetrianglesineachofthe8subgraphsinducedbyI[Jj[Kk,andrecurseonthepartthathasthemosttriangles.Atsomepoint,thenumberoftrianglesinthepartI[Jj[Kkwithmosttriangleswillbet,andatthispointwenolongerrecurse,butuseourtrianglelistingalgorithmonthecurrentsubgraphG0.WeknowthatwhenwerecursedonG0,ithadatleastttriangles,butsinceeachofthe8triplesofsubgraphsofG0havet,thenG0has8ttriangles.ConsidernowthenumberofnodesofG0.Supposethatitis3n=2jforsomej,andwehavedonejrecursivestepstondG0.Ineachstepthenumberoftrianglesgoesdownbyatmostafactorof8,soG0hasatleastT=8jtriangles.Yet,G0has8ttriangles,andhence8j+1-0.8;أ倀T=t,andhencethenumberofnodesinG0isO(n=(T=t)1=3).Wethusgetarunningtimeof~O0@n!+ t T1=3n!3(! 1)=(5 !)t2(3 !)=(5 !)1A:Usingasimilaridea,combinedwithanapproachfrom[14],wecanalsogetanimprovementforsparsegraphs(intermsofm).9 6ConsequencesoffastertrianglelistingInthissectionweproveTheorem3.Weshowthatifonecouldimproveuponourtrianglelistingalgorithms(and!=2),thenQESdoesindeedhavefasteralgorithmsoveranyF.LetFbeaniteeldandq=jFjitsnumberofelements.Assumethatthereisnoq(1 3)lpoly(l;k)timealgorithmforany30thatsolvesl-variateQESonkequations.GivenaninstancetoQESonlvariableswithkequationsx0Qx+Ex+S=0overF,whereQarellmatrices,Eare1lvectors,andSarescalars,wewillshowhowonecanusetrianglelistingtosolveit.MuchasPatrascu[23]didfor3SUM,weusehashingasaltertondthesolutionstoQES.Weconstructhhashedprojectionsoftheequationsx0Ax+Bx+C=0fori=1;2;:::;hwhereA=kXj=1R(j)Qj;B=kXj=1R(j)Ej;C=kXj=1R(j)SjforarandomR2Fk(foravectorRwewriteR(j)toaddressitsjthelement).ThehashedQES(A;B;C)hasthefollowingrelationstotheoriginalQES:{Everysolutionto(Q;E;S)isasolutionalsoto(A;B;C).{Everynon-solutionto(Q;E;S)isasolutionto(A;B;C)withprob.q h.Thismeansthatif(Q;E;S)hasssolutions,(A;B;C)hasatmost2ql h+ssolutionswithprobabilityatleast1=2bythelinearityofexpectationandMarkov'sinequality.Wecanassumethatsq3lsinceifnotwecanuseanotheralgorithminparallelthatsimplyguessesanassignmentandveriesit,whichrunsinexpectedtimeO(ql=s).WenextconstructagraphGthathasatriangleforeachsolutionto(A;B;C).Letabeaparametertobexedlater.Thevertexsetistheunionofthreesets:{V1hasonevertexlabeled(1)foreachassignment1totherstl 2avariables,intotalql 2avertices.{V2hasonevertexlabeled(2;H2)foreachcombinationofanassignment2tothenextavariablesxl 2a+1;:::;xl aandavectorH2inFh,intotalqa+hvertices.{V3hasonevertexlabeled(3;H3)foreachcombinationofanassignment3tothelastavariablesxl a+1;:::;xlandavectorH3inFh,intotalqa+hvertices.Welet0kdenotetheassignmentofkvariablestothevalue0.Theedgesare:{(1)and(2;H2)hasanedgeitheassignmentsx=120l aandy=102atothevariablesgivex0Ax+By+C= H2(i),i.e.weconsiderthecontributionwhereweuseallquadratictermsassociatedwiththeverticesandthelineartermassociatedwiththerstone.Thereareql aedges.10 {(2;H2)and(3;H3)hasanedgeitheassignmentsx=0l 2a23andy=0n 2a20atothevariablesgivex0Ax+By+C=H2(i) H3(i).Thereareq2a+hedges.{(3;H3)and(1)hasanedgeitheassignmentsx=10a3andy=0n a3tothevariablesgivex0Ax+By+C=H3(i).Thereareq2a+hedges.Atriangleinthegraphcorrespondstoasolutionto(A;B;C)sinceontheleftsidewecounteachtermexactlyonce,andontherighthandsideH2andH3arecountedtwicewithoppositesignsandcancel.WecanuseourtrianglelistingalgorithmonGtosolve(Q;E;S):foreachfoundtriangle(1);(2;H2);(3;H3)weverifyifx=123isalsoasolutionto(Q;E;S).Toarriveatthelowerbound,wenotethatthegraphGhas{ql 2a+2qa+hvertices.{ql a+2q2a+hedges.{2ql h+s2ql h+q3l2ql h+3ltriangleswithprobability1=2.Weseta=(l h)=3togetm=3q2l=3+h=3andn=3ql=3+2h=3.Byvaryinghwecancontrolthenumberoftrianglesw.r.t.mandn.NowassumethereisaO(m1 1t(1 2)=3)timealgorithmfortrianglelistingforsometm.WithourboundsonmandtwegetOql 1(2l=3+h=3) 2(l=3 h=3+3l)+3ltime.Forsmallenoughconstant3wegetacontradictionoftheassumptionofnon-existenceofanyO(q(1 3)l)timealgorithmforQES.Ifweinsteadas-sumean1 1t(1 2)2=3timealgorithmfortrianglelistingforsomet,wegetOql 1(l=3+2h=3) 2(2l=3 2h=3+3l)+3ltime,alsoacontradiction.Acknowledgement.WesendourthankstoMihaiPatrascuwithwhomwerstdiscussedtheideasleadingtothispaper.WethankEricPriceandJelaniNelsonforinformationonsparserecoverymethods.References1.FotoN.Afrati,DimitrisFotakis,andJereyD.Ullman.EnumeratingsubgraphinstancesusingMap-Reduce.Proc.IEEEInternationalConferenceonDataEn-gineering(ICDE),0:62{73,2013.2.NogaAlon,RaphaelYuster,andUriZwick.Color-coding.J.ACM,42(4):844{856,1995.3.YonatanAumann,MosheLewenstein,NoaLewenstein,andDekelTsur.Findingwitnessesbypeeling.ACMTransactionsonAlgorithms,7(2):24,2011.4.JonathanBerry,LukeFostvedt,DanielNordman,CynthiaPhillips,C.Seshadhri,andAlysonWilson.Whydosimplealgorithmsfortriangleenumerationworkintherealworld?InProc.InnovationsinTheoreticalComputerScience,2014.5.JonathanW.Berry,BruceHendrickson,RandallA.LaViolette,andCynthiaA.Phillips.Toleratingthecommunitydetectionresolutionlimitwithedgeweighting.Phys.Rev.E,83:056119,May2011.11 6.ShumoChuandJamesCheng.Trianglelistinginmassivenetworks.ACMTrans.Knowl.Discov.Data,6(4):17:1{17:32,2012.7.N.Courtois,A.Klimov,J.Patarin,andA.Shamir.Ecientalgorithmsforsolvingoverdenedsystemsofmultivariatepolynomialequations.InProc.EUROCRYPT,pages392{407,2000.8.BrookeFoucaultWelles,AnneVanDevender,andNoshirContractor.Isafriendafriend?Investigatingthestructureoffriendshipnetworksinvirtualworlds.InCHI'10ExtendedAbstractsonHumanFactorsinComputingSystems,pages4027{4032.ACM,2010.9.LeszekGasieniec,MiroslawKowaluk,andAndrzejLingas.Fastermulti-witnessesforbooleanmatrixmultiplication.Inf.Process.Lett.,109(4):242{247,2009.10.XiaochengHu,YufeiTao,andChin-WanChung.Massivegraphtriangulation.InProc.ofSIGMOD,pages325{336.ACM,2013.11.X.HuangandV.Y.Pan.Fastrectangularmatrixmultiplicationandapplications.J.ofComplexity,14(2):257{299,1998.12.PiotrIndyk.Explicitconstructionsforcompressedsensingofsparsesignals.InProc.of19thSODA,pages30{33,2008.13.AlonItaiandMichaelRodeh.Findingaminimumcircuitinagraph.SIAMJournalonComputing,7(4):413{423,1978.14.ZahraJafargholiandEmanueleViola.3SUM,3XOR,triangles.CoRR,abs/1305.3827,2013.15.A.KipnisandA.Shamir.CryptanalysisoftheHFEpublickeycryptosystembyrelinearization.InProc.CRYPTO,volume1666,pages19{30,1999.16.MihailN.Kolountzakis,GaryL.Miller,RichardPeng,andCharalamposE.Tsourakakis.Ecienttrianglecountinginlargegraphsviadegree-basedvertexpartitioning.InternetMathematics,8(1-2):161{185,2012.17.S.Landau.Polynomialsinthenation'sservice:usingalgebratodesignthead-vancedencryptionstandard.AmericanMathematicalMonthly,111:89{117,2004.18.F.LeGall.Powersoftensorsandfastmatrixmultiplication.CoRR,abs:1401.7714,2014.19.FrancoisLeGall.Fasteralgorithmsforrectangularmatrixmultiplication.InProc.FoundationsofComputerScience,pages514{523,2012.20.RasmusPaghandFrancescoSilvestri.Theinput/outputcomplexityoftriangleenumeration.arXivpreprintarXiv:1312.0723,2013.21.J.Patarin.Cryptoanalysisofthematsumotoandimaipublickeyschemeofeuro-crypt'88.InProc.CRYPTO,pages248{261,1995.22.ElyPoratandMartinJ.Strauss.Sublineartime,measurement-optimal,sparserecoveryforall.InProc.of23rdSODA,pages1215{1227.SIAM,2012.23.MihaiPatrascu.Towardspolynomiallowerboundsfordynamicproblems.InProc.of42ndSTOC,pages603{610,2010.24.ThomasSchankandDorotheaWagner.Finding,countingandlistingalltrianglesinlargegraphs,anexperimentalstudy.InExperimentalandEcientAlgorithms,pages606{609.Springer,2005.25.V.VassilevskaandR.Williams.Finding,minimizing,andcountingweightedsub-graphs.InProc.STOC,pages455{464,2009.26.NanWang,JingboZhang,Kian-LeeTan,andAnthonyKHTung.Ontriangulation-baseddenseneighborhoodgraphdiscovery.Proc.VLDBEndowment,4(2):58{68,2010.27.VirginiaVassilevskaWilliams.Multiplyingmatricesfasterthancoppersmith-winograd.InProc.of44ndSTOC,pages887{898,2012.12 28.VirginiaVassilevskaWilliamsandRyanWilliams.Subcubicequivalencesbetweenpath,matrixandtriangleproblems.InProc.IEEEFoundationsofComputerScience(FOCS),pages645{654,2010.13