pattern-matching algorithms in the classic pattern-matching problemwe are given text string of length and pattern string of length mand want to find whether is substring of if sowe may want to find the lowest index within at which beginssuch that [ : +mequals por perhaps to find all indices of at which pattern begins the pattern-matching problem is inherent to many behaviors of python' str classsuch as in tt find( ) index( ) count( )and is subtask of more complex behaviors such as partition( ) split( )and replace(pqin this sectionwe present three pattern-matching algorithms (with increasing levels of difficultyfor simplicitywe model the outward semantics of our functions upon the find method of the string classreturning the lowest index at which the pattern beginsor - if the pattern is not found brute force the brute-force algorithmic design pattern is powerful technique for algorithm design when we have something we wish to search for or when we wish to optimize some function when applying this technique in general situationwe typically enumerate all possible configurations of the inputs involved and pick the best of all these enumerated configurations in applying this technique to design brute-force pattern-matching algorithmwe derive what is probably the first algorithm that we might think of for solving the problem--we simply test all the possible placements of relative to an implementation of this algorithm is shown in code fragment def find brute(tp) """return the lowest index of at which substring begins (or else - "" nm len( )len(pintroduce convenient notations for in range( - + )try every potential starting index within = an index into pattern while and [ = [ ]kth character of matches + if =mif we reached the end of pattern return substring [ : +mmatches return - failed to find match starting with any code fragment an implementation of brute-force pattern-matching algorithm