For example, there are four such substrings in CABAAXBYA.
The original brute force algorithm I used was: using the external for loop, whenever I run into A, I go inside another loop to check if B is present or not. If B is found, I increase the score. Finally, the value stored in the count variable gives the desired result.
I came across a point while reading string matching algorithms, when you move from right to left, and not from left to right, your algorithm is more efficient, but here the substring is not indicated as a parameter of the function that you would use to calculate the required value.
My question is, if I cross the line from right to left, and not from left to right, will this make my algorithm more efficient anyway?
source share