Z Algorithm used for finding occurrences of patterns in strings