Question

3. (10 marks) a) (5 marks) For a given string S = p1p2...pn, the definition for next(i), 2 ≤ i ≤ n, is as follows: next(i) = the maximum j (0 < j < i − 1) such that p1p2...pj = pi−jpi−j+1...pi−1, 0 if no such j exists. (next(1) is defined as -1.) Compute the next function for string “abababc”.

3. (10 marks) a) (5 marks) For a given string S = P1P2...Pn, the definition for next(i), 2 si s n, is as follows: next(i) = t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

GIVEN THAT:

Given string S = p1p2...pn, the definition for next(i), 2 ≤ i ≤ n:

1. Given String is abababc and let thier indices be 1234567 , the string will be as below

9

2. Here S = p1p2...pn where p1=a , p2=b, p3=a, p4=b, p5=a, p6=b, p7=c

Given next(1) = -1

3. next(2) = 0 (as here 0<j<1 and we cant find any j)

4. next(3) = 0 (as here 0<j<2 and we will get i=3 and j=1 and equation is p1!=p2(a!=b) hence next(3) is 0)

5. next(4) = 1 (as here 0<j<3 we will get i=4 and j=1 and equation is p1=p3(a=a) and other combination is i=4 and j=2 p1p2!=p2p3(ab != ba) hence j=1)

6. next(5) = 2 (as here 0<j<4 we will get i=5 and j=1 and equation is p1!=p4(a=b) and other combination is i=5 and j=2 p1p2=p3p4(ab = ab) and other combination is i=5 and j=3 p1p2p3!=p2p3p4(aba = bab) hence j=2)

7. next(6) = 3 (as here 0<j<5 we will get i=6 and j=1 and equation is p1=p5(a=a) and other combination is i=6 and j=2 p1p2!=p4p5(ab = ba) and other combination is i=6 and j=3 p1p2p3=p3p4p5(aba = aba) and other combination is i=6 and j=4 p1p2p3p4!=p2p3p4p5(ababa=baba) hence j=3)

8. next(7) = 4 (as here 0<j<6 we will get i=7 and j=1 and equation is p1!=p6(a=b) and other combination is i=7 and j=2 p1p2=p5p6(ab = ab) and other combination is i=7 and j=3 p1p2p3!=p4p5p6(aba = bab) and other combination i=7 and j=4 p1p2p3p4=p3p4p5p6(abab=abab) and other combination i=7 and j=5 p1p2p3p4p5=p2p3p4p5p6(abab=babab) hence j=4)

So

9. next function of the string abababc is -1001234

Add a comment
Know the answer?
Add Answer to:
3. (10 marks) a) (5 marks) For a given string S = p1p2...pn, the definition for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT