vendredi 1 décembre 2017

What algorithm ilustrated to solve this run in time [O(n+m),O(nlgn)

enter image description here

Suppose you are given a source string S[0 . . n − 1] of length n, consisting of symbols a and b. Suppose further that you are given a pattern string P [0 . .m − 1] of length ≪ , consisting of symbols a, b, and ∗, representing a pattern to be found in string S. The symbol ∗ is a “wild card” symbol, which matches a single symbol, either a or b. The other symbols must match exactly. The problem is to output a sorted list M of valid “match positions”, which are positions j in S such that pattern P matches the substring S[j . . j + |P| − 1]. For example, if = and = ∗, then the output M should be [0, 2]. Write a straightforward, naıve algorithm to solve the problem. Your algorithm should run in time . Illustrate your algorithm on the example above




Aucun commentaire:

Enregistrer un commentaire