0% found this document useful (0 votes)
6 views18 pages

18 DP String Apps2

Uploaded by

Jagrati Kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views18 pages

18 DP String Apps2

Uploaded by

Jagrati Kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Dynamic Programming
(MatExp, Strings)

Dr. Shahbaz Khan


Department of Computer Science and Engineering,
Indian Institute of Technology Roorkee
[email protected]
Minimum deletions to make a palindrome

Given a string S[1,..., n], remove or delete the minimum number of


characters from the string so that the resultant string is a palindrome.
Eg. abaccdba = 2 (abccba)

minD[i][j] = Minimum deletions to make S[i,...,j] a palindrome

5
Longest Palindromic Subsequence

Given a string S[1,..., n], what is the size of the longest subsequence
which is also a palindrome.
Eg. abaccdba = 6 (abccba)

6
Longest Palindromic Subsequence

Given a string S[1,..., n], what is the size of the longest subsequence
which is also a palindrome.
Eg. abaccdba = 6 (abccba)

longP[i][j] = Longest Palindromic Subsequence of S[i,...,j]

7
Palindrome Partitioning

Given a string S[1,..., n], what is the minimum number of partitions such
that each partition is a palindrome.
Eg. ababbbabbababa = 3 (a|babbbab|b|ababa)

minD[i][j] = Minimum deletions to make S[i,...,j] a palindrome

9
Palindrome Partitioning

Given a string S[1,..., n], what is the minimum number of partitions such
that each partition is a palindrome.
Eg. ababbbabbababa = 3 (a|babbbab|b|ababa)

minD[i] = Minimum deletions to make S[0,...,i] a palindrome

10
Pattern in a given Text

Given a pattern P[m], preprocess P to report all locations where P


occurs in any T[n] in O(n) , where m>n.
Eg. P= "WXYZ", T=TUVWXYZABCDWXYZ,
P=“AABA”, T=AABAACAADAABAABA,

General Version:
Given a dictionary of k words, preprocess them to report
all their appearances in text T in O(n).

11
Pattern in a given Text

General Version:
Given a dictionary of k words, preprocess them to report
all their appearances in text T in O(n).

13
Pattern in a given Text

Given a pattern P[m], preprocess P to report all locations where P


occurs in any T[n] in O(n) , where m>n.
Eg. P= "WXYZ", T=TUVWXYZABCDWXYZ,
P=“AABA”, T=AABAACAADAABAABA,
KMP 1970...
General Version:
Given a dictionary of k words, preprocess them to report
all their appearances in text T in O(n).
Aho Corasick 1975

14

You might also like