input to this problem is a pair of strings A = a1 · · · am and B = b1 · · · bn. The goal is to convert A into B as cheaply as possible. The rules and cost are defined as follow. For a cost of 3 you can delete any letter. For a cost of 4 you can insert a letter in any position. For a cost of 5 you can replace any letter by any other letter. For example, you can convert A = abcabc to B = abacab via the following sequence: abcabc at a cost of 5 can be converted to abaabc, which at cost of 3 can be converted to ababc, which at cost of 3 can be converted to abac, which at cost of 4 can be converted to abacb, which at cost of 4 can be converted to abacab. Thus the total cost for this conversion would be 19. This is probably not the cheapest possible conversion. (Note that the Unix diff command essentially solves this problem.) (a) Give a dynamic programming algorithm to solve this problem. (b) Apply your algorithm in (a) to convert A = abcabc to B = abacab with the minimum total cost. Show all your work
he input to this problem is a pair of strings A = a1 · · · am and B = b1 · · · bn. The goal is to convert A into B as cheaply as possible. The rules and cost are defined as follow. For a cost of 3 you can delete any letter. For a cost of 4 you can insert a letter in any position. For a cost of 5 you can replace any letter by any other letter. For example, you can convert A = abcabc to B = abacab via the following sequence: abcabc at a cost of 5 can be converted to abaabc, which at cost of 3 can be converted to ababc, which at cost of 3 can be converted to abac, which at cost of 4 can be converted to abacb, which at cost of 4 can be converted to abacab. Thus the total cost for this conversion would be 19. This is probably not the cheapest possible conversion. (Note that the Unix diff command essentially solves this problem.)
(a) Give a dynamic
(b) Apply your algorithm in (a) to convert A = abcabc to B = abacab with the minimum total cost. Show all your work
Trending now
This is a popular solution!
Step by step
Solved in 2 steps