Write a program to implement the naive string-matching algorithm (Algorithm 1). Insert a conditional branch so as to exit the innermost loop whenever a mismatch occurs (i.e., the shift is found to be invalid). Add a line to count the total number of character-to-character comparisons in the complete string search. (a) Write a small program to generate a text of n characters, taken from an alphabet having d characters. Let d = 5 and use your program to generate a text of length n = 1000 and a test string x of length m = 10. b) Compare the number of character-to-character comparisons performed by your program with the theoretical result quoted in Problem 18 for all pairs of the following parameters:
Write a
(a) Write a small program to generate a text of n characters, taken from an alphabet having d characters. Let d = 5 and use your program to generate a text of length n = 1000 and a test string x of length m = 10.
b) Compare the number of character-to-character comparisons performed by your program with the theoretical result quoted in Problem 18 for all pairs of the following parameters:
Step by step
Solved in 3 steps with 3 images