String matching with universal characters in it

Revision en2, by K0NSTANT1N3, 2025-10-14 00:39:21

Given two strings: s1, s2 s1 has some characters that equal to every character (call them universal characters) and s1 also has some characters that are not equal to any character.

find all occurences of s1 in s2.

for example

s1 = ab?a? s2 = aabcabaaa

here s1 occurs in s2 on indexes 1 (as abcab) and 4 (as abaaa)

i have tried using KPM or Z Array, but both failed do to unpredictable misbihaviour.

what algorithm can be used to solve this problem in linear time? (or at least O(n*logn))?

Tags string, prefix- and z-functions, substring search, string match, aho-corasick, suffix trie, algorithms, hashing

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English K0NSTANT1N3 2025-10-14 00:39:21 0 If there is any probem on anywhere similar to mine, i would gladly read its solution.
en1 English K0NSTANT1N3 2025-10-14 00:36:59 565 Initial revision (published)