Question: Refertothepattern-matchingalgorithminFigure2.16. a. What is the output of the algorithm as it currently stands if our text is Text:We must band together and handle adversity and
Refertothepattern-matchingalgorithminFigure2.16.
a. What is the output of the algorithm as it currently stands if our text is Text:We must band together and handle adversity and we search for the pattern and?
b. How could we modify the algorithm so that it finds only the complete word and rather than the occurrence of the character sequence a, n, and d that is contained within another word, such as band?

FIGURE 2.16 Get values for n and m, the size of the text and the pattern, respectively Get values for both the text T, T...T, and the pattern P, P...Pm Set k, the starting location for the attempted match, to 1 While (ks (n m+ 1)) do Set the value of i to 1 Set the value of Mismatch to NO While both (i s m) and (Mismatch = NO) do lf P, +(i-1) then Set Mismatch to YES Else Increment i by 1 (to move to the next character) End of the loop If Mismatch = NO then Print the message There is a match at position Print the value of k Increment k by 1 End of the loop Stop, we are finished FIGURE 2.16 Get values for n and m, the size of the text and the pattern, respectively Get values for both the text T, T...T, and the pattern P, P...Pm Set k, the starting location for the attempted match, to 1 While (ks (n m+ 1)) do Set the value of i to 1 Set the value of Mismatch to NO While both (i s m) and (Mismatch = NO) do lf P, +(i-1) then Set Mismatch to YES Else Increment i by 1 (to move to the next character) End of the loop If Mismatch = NO then Print the message There is a match at position Print the value of k Increment k by 1 End of the loop Stop, we are finished
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
