Question

Describe a recursive algorithm for the following variant of the text segmentation problem. Assume that you...

  1. Describe a recursive algorithm for the following variant of the text segmentation problem. Assume that you have a subroutine IsWord that takes an array of characters as input and returns True if and only if that string is a “word”.

  2. 1. Given two arrays A[1..n] and B[1..n] of characters, compute the number of different ways that A and B can be partitioned into words at the same indices.

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

FindWords: It contains A[ ] as array, WORDS_BAG as collections of different words (bag of words)

1) A[ ] <- Input the characters from user .

2) Initialize new array as splitedWords = [ ]

3) Repeat for i = 0 to i < length of A.

4) Append A[ from start to i] into splitedWords.

5) Append A[ from i +1 to last ] into splitedWords.

# eg: if the word is "artistoil" then splitedWords contain [ a, rtistoil, ar, tistoil, art, istoil, arti, stoil, artis, toil, artist, oil, artisto, il, artistoi, l ]   

6) i = i + 1

End For Loop

7) OutPut = [ ]

8) Repeat for i = 0 to length of splitedWords

9) if splitedWords[ i ] finds null then

return 0 and "Not data input"

10) if splitedWords[ i ] finds in WORDS_BAG then

append splitedWords[ i ] into OutPut

End For Loop

# eg: OutPut will contains [a, art, toil, artist, oil ]

11) Now Repeat for 0 to 2 from the step 3 for all the OutPut then we will get more words

eg: [a, art, to, toil, artist, is , oil]

end loop

12) Repeat for i =0 to length of OutPut

13) if first character of OutPut[ i ] is equal to A[ 1 ]

then add into NewOut1 list

14) if last character of OutPut[ i ] is equal to A[ last ]

then add into NewOut2 list

i++

END loop

15) combine NewOut1 with NewOut2 word wise and also cheak first and last character of output words with A[ first ] and A [ last ] and length of word also equal to each other

16) return no. of words and words

Add a comment
Know the answer?
Add Answer to:
Describe a recursive algorithm for the following variant of the text segmentation problem. Assume that you...
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
ADVERTISEMENT