Let us consider two sequences of disks(A[0
...n-1],B[0.....m-1]):
n: Length of first sequences of disks
m: Length of second sequences of disks
//Pseudocode
Transform(A[0 ...n-1],B[0.....m-1])
{
// Create a table to store results of subproblems
int dp[n+1][m+1];
// Fill d[][] in bottom up manner
for (i=0 to n)
{
for (j=0; to m)
{
// If first sequence is empty, only option is to
// insert all disks of second sequence
if (i==0)
dp[i][j] = j; // Min. operations = j
// If second sequence is empty, only option is to
// remove all disks of second sequence
else if (j==0)
dp[i][j] = i; // Min. operations = i
// If last sequences are same, ignore last disk
// and recur for remaining sequence
else if (A[i-1] == B[j-1])
dp[i][j] = dp[i-1][j-1];
// If the last disk is different, consider all
// possibilities and find the minimum
else
dp[i][j] = 1 + min(dp[i][j-1], // Insert
dp[i-1][j], // Remove
dp[i-1][j-1]); // Replace
}
}
print( dp[n][m]);
}
Time complexity = O(n*m)
i need the solution in pseudo code please. 4 Dynamic Programmii Consider the following problem based on the transf...
In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be 0-red. 1-yellow, 2-blue, 3-pink. , c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4...
Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink. ..., c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4 ), at each time step (or iteration) you are only allowed to perform one of three basic...
In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be 0-red. 1-yellow, 2-blue, 3-pink. , c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4...
Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink. ..., c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4 ), at each time step (or iteration) you are only allowed to perform one of three basic...