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.

C-12.5<br />

Say that a pattern P of length m is a circular substr<strong>in</strong>g of a text T of length n if<br />

there is an <strong>in</strong>dex 0 ≤ i < m, such that P = T[n − m + i..n − 1] + T[0..i − 1], that is,<br />

if P is a (normal) substr<strong>in</strong>g of T or P is equal to the concatenation of a suffix of<br />

T <strong>and</strong> a prefix of T. Give an O(n + m)-time algorithm for determ<strong>in</strong><strong>in</strong>g whether P<br />

is a circular substr<strong>in</strong>g of T.<br />

C-12.6<br />

The KMP pattern match<strong>in</strong>g algorithm can be modified to run faster on b<strong>in</strong>ary<br />

str<strong>in</strong>gs by redef<strong>in</strong><strong>in</strong>g the failure function as<br />

, where<br />

denotes the complement of the kth bit of P. Describe how to modify the KMP<br />

algorithm to be able to take advantage of this new failure function <strong>and</strong> also give<br />

a method for comput<strong>in</strong>g this failure function. Show that this method makes at<br />

most n comparisons between the text <strong>and</strong> the pattern (as opposed to the 2n<br />

comparisons needed by the st<strong>and</strong>ard KMP algorithm given <strong>in</strong> Section 12.2.3).<br />

C-12.7<br />

Modify the simplified BM algorithm presented <strong>in</strong> this chapter us<strong>in</strong>g ideas from<br />

the KMP algorithm so that it runs <strong>in</strong> O(n + m) time.<br />

C-12.8<br />

Given a str<strong>in</strong>g X of length n <strong>and</strong> a str<strong>in</strong>g Y of length m, describe an O(n + m)-<br />

time algorithm for f<strong>in</strong>d<strong>in</strong>g the longest prefix of X that is a suffix of Y.<br />

C-12.9<br />

Give an efficient algorithm for delet<strong>in</strong>g a str<strong>in</strong>g from a st<strong>and</strong>ard trie <strong>and</strong> analyze<br />

its runn<strong>in</strong>g time.<br />

C-12.10<br />

Give an efficient algorithm for delet<strong>in</strong>g a str<strong>in</strong>g from a compressed trie <strong>and</strong><br />

analyze its runn<strong>in</strong>g time.<br />

C-12.11<br />

Describe an algorithm for construct<strong>in</strong>g the compact representation of a suffix<br />

trie, given its noncompact representation, <strong>and</strong> analyze its runn<strong>in</strong>g time.<br />

C-12.12<br />

Let T be a text str<strong>in</strong>g of length n. Describe an O(n)-time method for f<strong>in</strong>d<strong>in</strong>g the<br />

longest prefix of T that is a substr<strong>in</strong>g of the reversal of T.<br />

785

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

Saved successfully!

Ooh no, something went wrong!