Give an example of a dynamic programming algorithm which solves the following problem:
Input. Two strings w1 and w2
Output. Yes if w1 contains all the letters of w2 in order, no
otherwise.
(example problem instance and solutions)
Input. w1="abccba", w2="bba"
Output. Yes
Input. w1="abcabc", w2="bba"
Output. No
You do not need to prove the algorithm is correct. But you should analyze its runtime.
The algorithm is given as:
function boolean contains(String str1, String str2) {
m = str1.length()
n = str2.length()
j = 0
for i = 0 to i < m such that j < n do
if str1[i] == str2[j] then
j++
end if
end loop
if (j == n) then
print "Yes"
else
print "No"
end if
}
Time complexity: O(m) where m is the length of str1.
Give an example of a dynamic programming algorithm which solves the following problem: Input. Two strings...