23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

R-12.10<br />

Draw the compact representation of the suffix trie for the str<strong>in</strong>g "m<strong>in</strong>imize<br />

m<strong>in</strong>ime".<br />

R-12.11<br />

What is the longest prefix of the str<strong>in</strong>g "cgtacgttcgtacg" that is also a<br />

suffix of this str<strong>in</strong>g?<br />

R-12.12<br />

Draw the frequency array <strong>and</strong> Huffman tree for the follow<strong>in</strong>g str<strong>in</strong>g: "dogs<br />

do not spot hot pots or cats".<br />

R-12.13<br />

Show the longest common subsequence array L for the two str<strong>in</strong>gs<br />

X = "skull<strong>and</strong>bones"<br />

Y = "lullabybabies".<br />

What is a longest common subsequence between these str<strong>in</strong>gs?<br />

Creativity<br />

C-12.1<br />

Give an example of a text T of length n <strong>and</strong> a pattern P of length m that force<br />

the brute-force pattern match<strong>in</strong>g algorithm to have a runn<strong>in</strong>g time that is Ω(nm).<br />

C-12.2<br />

Give a justification of why the KMPFailureFunction method (Code<br />

Fragment 12.5) runs <strong>in</strong> O(m) time on a pattern of length m.<br />

C-12.3<br />

Show how to modify the KMP str<strong>in</strong>g pattern match<strong>in</strong>g algorithm so as to f<strong>in</strong>d<br />

every occurrence of a pattern str<strong>in</strong>g P that appears as a substr<strong>in</strong>g <strong>in</strong> T, while still<br />

runn<strong>in</strong>g <strong>in</strong> O(n+m) time. (Be sure to catch even those matches that overlap.)<br />

C-12.4<br />

Let T be a text of length n, <strong>and</strong> let P be a pattern of length m. Describe an<br />

O(n+m)time method for f<strong>in</strong>d<strong>in</strong>g the longest prefix of P that is a substr<strong>in</strong>g ofT.<br />

784

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!