performance the analysis of the brute-force pattern-matching algorithm could not be simpler it consists of two nested loopswith the outer loop indexing through all possible starting indices of the pattern in the textand the inner loop indexing through each character of the patterncomparing it to its potentially corresponding character in the text thusthe correctness of the brute-force pattern-matching algorithm follows immediately from this exhaustive search approach the running time of brute-force pattern matching in the worst case is not goodhoweverbecausefor each candidate index in twe can perform up to character comparisons to discover that does not match at the current index referring to code fragment we see that the outer for loop is executed at most timesand the inner while loop is executed at most times thusthe worst-case running time of the brute-force method is (nmexample suppose we are given the text string "abacaabaccabacabaabband the pattern string "abacabfigure illustrates the execution of the brute-force pattern-matching algorithm on and textpatterna comparisons not shown figure example run of the brute-force pattern-matching algorithm the algorithm performs character comparisonsindicated above with numerical labels