StringMatchingThestringmatchingproblemisasfollows:Givenapatternp,andastringoftextt,,:,,eupwithsomecodetoimplementthisbruteforcealgorithm:publicstaticbooleanmatch(Stringtext,Stringpattern){for(inti=0;i<=()-();i++){intj=0;while(j<()&&(j)==(i+j))j++;if(j==())returntrue;}returnfalse;}Boyer-MooreAlgorithmThisalgorithmdoesacouplethingsdifferentlythanthebruteforcealgorithm:1)Insteadofcheckingforastringmatchfromthebeginningofthestring,)Insteadofalwaysmovingaheadonespaceafteryouhaveeliminatedastringchoice,'sgothroughanexample:0123Text:bbaabacbbabbbbbaabbbabbbaaaaPattern:hepatternupwiththebeginningofthetext,whenwelookatthelastcharacters,,,'tmatchb,,thatmeansonlyslidingovert
String Matching 来自淘豆网m.daumloan.com转载请标明出处.