
Implement a function that finds the first occurrence of a pattern P in a text T and returns the starting index (or -1 if not found). Follow-ups: compare the naive method to KMP and Rabin–Karp; extend the matcher to support wildcard characters '?' (match any single char) and '*' (match any sequence); discuss time and space complexity and key edge cases (empty strings, repeated patterns, very long inputs).