edited by
758 views
0 votes
0 votes
Given a text array $T[1…..n]$ and a pattern array $P[1….m]$ such that T and P are character taken from alphabet $\sum$,

$\sum={a,b,c,…..z}$. String matching problem is to find all the occurence of P in T. A pattern occur with shift s in T if $P[1…..m]=T[s+1,…...s+m]$.

Consider $T=bacacbaacacac$

               $P=cac$

The sum of the value of all s is ________
edited by

2 Answers

Best answer
2 votes
2 votes

The 3 occurrences of "cac"  are as shown: 

bacacbaacacac

bacacbaacacac

bacacbaacacac 

For the first occurrence, 

P[1..3]= cac = T[3..5]. 

Now s+1=3, thus s=2.

Calculating s for the other 2 occurrences, we get s= 8 and s=10. So sum of all values of s is 20.

selected by
1 votes
1 votes

s =2 + 8 + 10 = 20

Related questions

0 votes
0 votes
0 answers
1
Shamim Ahmed asked Nov 26, 2018
393 views
Which of the following procedure is suitable to find longest path from given vertex to any other vertex in Directed Acyclic Graph?Answer: Dynamic Programming.Why Greedy A...
1 votes
1 votes
0 answers
2
Nidhi Budhraja asked Sep 10, 2018
384 views
Consider an OBST with n=4,p[1..4]={3,3,1,1} q[0..4]={2,3,1,1,1}Cost of OBST=___?Pls give the solution for this question.
1 votes
1 votes
1 answer
4