Search⌘ K

Text Segmentation

Explore how to apply dynamic programming to the text segmentation problem by recursively partitioning a string into valid words. Understand memoization techniques that eliminate redundant computations, drastically improving efficiency. Learn to develop and implement algorithms that use recursion and bottom-up tabulation to determine if a string can be segmented into a valid sequence of words.

Optimizing the text segmentation problem

For our next dynamic programming algorithm, let’s consider the text segmentation problem from the previous chapter. We are given a string A[1..n]A[1 .. n] and a subroutine IsWordIsWord that determines whether a given string is a word (whatever that means), and we want to know whether AA can be partitioned into a sequence of words.

We solved this problem by defining a function Splittable(i)Splittable(i) that returns True if and only if the suffix A[i..n]suffix\space A[i .. n] can be partitioned into a sequence of words. We need to compute Splittable(1)Splittable(1). This function satisfies the recurrence

Splittable(i)={ True if i>nj=1n(IsWord(i,j)Splittable(j+1))otherwiseSplittable(i)=\begin{cases} & \text{ True \hspace{5.8cm}} if\space i > n \\ & \overset{n}{\underset{j=1}{\vee}} \left ( IsWord(i,j) \wedge Splittable(j+1) \right ) \hspace{1cm} otherwise \end{cases} ...