- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
We are given $2$ strings $A=[1 \dots m]$ and $B[1 \dots n]$ and the following $3$ operations are allowed:
We are looking for the optimal sequence of operations(sequence of operations with the minimum cost),for the conversion of the string $A$ to the string $B$.
$$T(i,j)=\text{ the minimum cost of the conversion of the string } A[1 \dots i] \text{ to } B[1 \dots j], 1 \leq i \leq m, 1 \leq j \leq n$$
According to my notes:
$$T(i,j)=\min \left\{\begin{matrix}
T(i-1,j)+c_d & \text{ // delete the i-th charachter of A}\\
T(i,j-1)+c_i & \text{ // insert the j-th charachter of B} \\
T(i-1,j-1) & \text{if } A=B[j]\\
T(i-1,j-1)+c_r & \text{if } A \neq B[j]
\end{matrix}\right.$$
Why is the cost given by the above formula?Could you explain it to me? (Thinking)
We are given $2$ strings $A=[1 \dots m]$ and $B[1 \dots n]$ and the following $3$ operations are allowed:
- Insert a charachter,with cost $c_i$
- Delete a character,with cost $c_d$
- Replace a character,with cost $c_r$
We are looking for the optimal sequence of operations(sequence of operations with the minimum cost),for the conversion of the string $A$ to the string $B$.
$$T(i,j)=\text{ the minimum cost of the conversion of the string } A[1 \dots i] \text{ to } B[1 \dots j], 1 \leq i \leq m, 1 \leq j \leq n$$
According to my notes:
$$T(i,j)=\min \left\{\begin{matrix}
T(i-1,j)+c_d & \text{ // delete the i-th charachter of A}\\
T(i,j-1)+c_i & \text{ // insert the j-th charachter of B} \\
T(i-1,j-1) & \text{if } A=B[j]\\
T(i-1,j-1)+c_r & \text{if } A \neq B[j]
\end{matrix}\right.$$
Why is the cost given by the above formula?Could you explain it to me? (Thinking)