I am trying to understand how
n being the string and
m being the pattern) is derived. As in, how could you determine a formula for the number of comparisons in the worst case of a brute-force string matching algorithm.
Here is a look at
(n-m+1) being mathmatically derived (where I'm at), that I found:
In the above derivation, I am unable to see where the
+1 comes into the equation mathmatically.
(n-m+1)is the number of comparisons, but I want to understand the WHY. Like you would explaining to someone the classic ""Why do you have to have the -1 in
i <= array.length-1in the for loop?". $\endgroup$