adding algorithm for counting number of occurences of substring