Question: Breaking words. When we type something hastily into a search box, we often mistype and leave out one or more spacesbetweenwords. However, search engines are

Breaking words.
When we type something hastily into a search box, we often mistype and leave out one or
more spacesbetweenwords. However, search engines are usually still able to search for what we
"meant" to type, in part by checking whether the input string can be split into words from a
dictionary. Using the power of dynamic programming, you will design an algorithm that does
this!
(a) We want an algorithm Word-Break(S,L), where S is a string and L is a list of words. It
should return true exactly when S is the concatenation of a sequence of words from L
(the words in L are distinct and non-empty; each may appear zero, one, or many times
in S). Here are a few examples:
Input: 'EECS', '376','Is', 'Awesome'],S= 'Awesome376IsAwesome'.
Output = true.
Input: L=['cats', 'and', 'dogs'],S= 'catsanddogs'.
Output = true.
Input: L=['cats', 'and', 'dogs'],S= 'catsandogs'.
Output = false.
Input: L=['cats', 'and', 'dogs', 'cat', 'sand'],S= 'catsand'.
Output = true.
Derive, with justification, a recurrence relation (including base case(s)) that is suitable for
a dynamic-programming implementation of Word-Break. Your recurrence may rely on
a 'lookup' function L(w) that outputs true if winL, and false otherwise.
[
(b) Fill in a table containing all the relevant values of your recurrence for the input
S= 'catsand', L=['cat', 'cats', 'sand', 'and'].
Describe the order in which you filled the table, and the criteria you used to decide which
already-filled cell(s) to consult as you filled each cell.
(c) In the fourth example above (in which S= 'catsand'), the correct output is true, and in
fact there are two sequences of words from L that can be concatenated to form S. Modify
your original recurrence so that instead of outputting a true/false value, it outputs how
many ways S can be expressed as a concatenation of words from L. For this purpose, you
may modify the lookup function so that L(w)=1 if winL, and L(w)=0 otherwise.
Breaking words. When we type something hastily

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!