Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. [10 marks] In the string metamorphosis problem, you are given two strings x[L,m] and y[1..n]. Your task is to determine the least costly way

image text in transcribedimage text in transcribed

2. [10 marks] In the string metamorphosis problem, you are given two strings x[L,m] and y[1..n]. Your task is to determine the least costly way to transform r into y by a left-to-right scan of r while performing operations that affect individual symbols: copy, insert, delete and replace For example, the following is one way of transforming Delicious into Dalhousie: e copy the D replace the e with a copy the 1 replace the i with h delete the c and I copy the o, u and s insert i and e. It is probably best to think of this process as follows: Use an array to store interm!e- diate results. Initially, is empty, and when this process terminates, z = y. We use indices i and j to keep track of the progress that we have made in x and z, respectively. Initially, i = j = 1, and when we finish, we have i = m + 1,J = n+ 1, During the left-to-write scan of r . A copy sets zDI 2121 and increments both i and . A replace sets z] c for some character c, and increments both i and j. A delete incrementsi only An insert sets c for some character c, and inc rernentsj. We assign costs to these operations as follows: A copy is free and it costs nothing, while all the other three operations costs 1 for each single use. Thus, 5 is the cost of transforming Delicious to Dalhousie using the sequence of operations given in the example above. Since no other sequence of operations can transform Delicious to Dalhousie more cheaply, the metamorphosis number of these two strings is 5. 2. [10 marks] In the string metamorphosis problem, you are given two strings x[L,m] and y[1..n]. Your task is to determine the least costly way to transform r into y by a left-to-right scan of r while performing operations that affect individual symbols: copy, insert, delete and replace For example, the following is one way of transforming Delicious into Dalhousie: e copy the D replace the e with a copy the 1 replace the i with h delete the c and I copy the o, u and s insert i and e. It is probably best to think of this process as follows: Use an array to store interm!e- diate results. Initially, is empty, and when this process terminates, z = y. We use indices i and j to keep track of the progress that we have made in x and z, respectively. Initially, i = j = 1, and when we finish, we have i = m + 1,J = n+ 1, During the left-to-write scan of r . A copy sets zDI 2121 and increments both i and . A replace sets z] c for some character c, and increments both i and j. A delete incrementsi only An insert sets c for some character c, and inc rernentsj. We assign costs to these operations as follows: A copy is free and it costs nothing, while all the other three operations costs 1 for each single use. Thus, 5 is the cost of transforming Delicious to Dalhousie using the sequence of operations given in the example above. Since no other sequence of operations can transform Delicious to Dalhousie more cheaply, the metamorphosis number of these two strings is 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions