Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We want to devise a dynamic programming algorithm for the following problem: There is a string of characters which might have been a sequence of

We want to devise a dynamic programming algorithm for the following problem:

There is a string of characters which might have been a sequence of words with all the spaces removed, and we want to find a way, if any, in which to insert spaces that separate valid English words. For example, theyouthevent could be from the you the vent, the youth event or they out he vent. If the input is theeaglehaslande, then theres no such way. Your task is to implement a dynamic programming solution in the following ways:

iterative bottom-up version

recursive memoized version

image text in transcribedThe program will read a text file from standard input. The name of the dictionary file should be hardwired in the code. We will be testing your program on a file named diction10k.txt, and your program will be tested in a directory containing that file.

SAMPLE INPUT:

The first line of input is an integer C. This is followed by C lines, each containing a single string, representing a phrase to be tested.

3

theyouthevent

theeaglehaslande

lukelucklikeslakeslukeducklikeslakeslukelucklickslakesluckducklickslakes

SAMPLE OUTPUT:

phrase number: 1

theyouthevent

iterative attempt: YES, can be split

the you the vent

memoized attempt: YES, can be split

the you the vent

phrase number: 2

theeaglehaslande

iterative attempt: NO, cannot be split

memoized attempt: NO, cannot be split

phrase number: 3

lukelucklikeslakeslukeducklikeslakeslukelucklickslakesluckducklickslakes

iterative attempt: YES, can be split

luke luck likes lakes luke duck likes lakes luke luck licks lakes luck duck licks lakes

memoized attempt: YES, can be split

luke luck likes lakes luke duck likes lakes luke luck licks lakes luck duck licks lakes

In C, C++, or Python please.

Assume that the original sequence of words had no other punctuation (such as periods), no capital letters, and no proper namesall the words will be available in a dictionary file that will be provided to you. Let the input string be x = x122...In. We define the subproblem split(i) as that of determining whether it is possible to correctly add spaces to Lili+1...In. Let dict(w) be the function that will look up a provided word in the dictionary, and return true if and only if the word w is in it. A recurrence relation is given below: : s true if i=n +1 1 V1=i[dict(tili+1...X;) A split(j +1)] otherwise Obviously, split(i) only finds out whether there's a sequence of valid words or not. Your pro- gram must also find at least one such sequence. Assume that the original sequence of words had no other punctuation (such as periods), no capital letters, and no proper namesall the words will be available in a dictionary file that will be provided to you. Let the input string be x = x122...In. We define the subproblem split(i) as that of determining whether it is possible to correctly add spaces to Lili+1...In. Let dict(w) be the function that will look up a provided word in the dictionary, and return true if and only if the word w is in it. A recurrence relation is given below: : s true if i=n +1 1 V1=i[dict(tili+1...X;) A split(j +1)] otherwise Obviously, split(i) only finds out whether there's a sequence of valid words or not. Your pro- gram must also find at least one such sequence

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

Find the real solutions of each equation. 2 5r 6 = x 6=x

Answered: 1 week ago

Question

Define Administration?

Answered: 1 week ago

Question

Define Decision making

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago