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 WordBreak where is a string and is a list of words. It
should return true exactly when is the concatenation of a sequence of words from
the words in are distinct and nonempty; each may appear zero, one, or many times
in Here are a few examples:
Input: 'EECS', Is 'Awesome' 'AwesomeIsAwesome'.
Output true.
Input: cats 'and', 'dogs' 'catsanddogs'.
Output true.
Input: cats 'and', 'dogs' 'catsandogs'.
Output false.
Input: cats 'and', 'dogs', 'cat', 'sand' 'catsand'.
Output true.
Derive, with justification, a recurrence relation including base cases that is suitable for
a dynamicprogramming implementation of WordBreak. Your recurrence may rely on
a 'lookup' function that outputs true if winL, and false otherwise.
b Fill in a table containing all the relevant values of your recurrence for the input
'catsand', 'cats', 'sand', 'and'
Describe the order in which you filled the table, and the criteria you used to decide which
alreadyfilled cells to consult as you filled each cell.
c In the fourth example above in which 'catsand' the correct output is true, and in
fact there are two sequences of words from that can be concatenated to form Modify
your original recurrence so that instead of outputting a truefalse value, it outputs how
many ways can be expressed as a concatenation of words from For this purpose, you
may modify the lookup function so that if winL, and otherwise.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
