For example, let the string be the first 10 digits of pi, 3141592653
, and the subsequence be 123
. Note that the sequence occurs twice:
Notice, we need not FIND all sequences, we need only COUNT them. So, all algorithms that search for sequences, are excessively complex.
That is all. The complexity is O(N). Really, for the normal line of digits, it will take about twice the time of the shortening of the source line.
If the sequence will be longer, of , say, M members, the procedure could be repeated M times. And complexity will be O(MN), where N already will be the length of the shortened source string.