Let us consider two sequences of disks(A,B):
m: Length of first sequences of disks
n: Length of second sequences of disks
followings are steps taken two find minimum cost for converting one
sequences of disk to another sequences of disk using dynamic
programming.
1)Declare an arr[m+1][n+1], which arr[i][j] stores minimum cost
of converting sequences of disks A(0,n-1 )into sequences of disks
B(0,m-1).
2)for(i=0.......m)
for(j=0.........n)
(a)if i=0 If first string is empty, only option
is to insert all characters of second string i.e arr[i][j]=n;
(b)if j=0 If second string is empty, the only
option is to remove all characters of first string i.e
arr[i][j]=m;
(c)if last characters of two strings are same,
Ignore last characters and recur for remaining strings.
i.e if(B[i-1]==A[j-1])
arr[i][j]=arr[i-1][j-1];
(e)if the last character is different, consider
all possibilities :-
(i) Insert: value for i and j-1 i.e
arr[i][j-1]
(ii) Remove: value for i-1 and j i.e
arr[i-1][j]
(iii) Replace: value for i-1 and j-1 i.e
arr[i-1][j-1]
now take minimum
of above three possibilities ,also show which type of operation
performed over A.
if arr[i][j-1]
is minimum ,then operation is inserting a character at jth place in
string A.
if arr[i-1][j]
is minimum ,then operation is removing a character at jth place in
string A.
if arr[i-1][j-1]
is minimum .then operation is replacing a character at jth place in
string A.
arr[i][j]=( 1+
min(arr[i][j-1], arr[i-1][j], arr[i-1][j-1]));
}
(3)finally return value at arr[m][n].
Time complexity = O(m*n)
Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that...
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...
i need the solution in pseudo code please. 4 Dynamic Programmii 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, cl. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink,. c-black For a given sequence of coloured disks eg.,0,1,2,3,4), at each time step (or iteration) you are only...
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...
In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one).You have the following constraints: (A) Only one disk can be moved at a time. (B) A disk is slid off the top of one rod onto the next rod....
A priority queue is a collection of items each having a priority. A priority queue supports three fundamental operations. You can ask a priority queue whether it is empty. You can insert an item into the priority queue with a given priority. You can remove the item from the priority queue that has the smallest priority. For example, suppose that you start with an empty priority queue and imagine performing the following steps. Insert item "one" with priority 10. Insert...
Question 5. Consider the following four ticis hoop, afat disks sphere, and a hollow sphere. Each of the a cts has mass M and radius R The axis of rotation passes through the center of each obiect, and is perpendicular the plane of the hood and the plane of the fat disk Which of these objects requires the largest torgue to give it the same angular acceleration? A) the hoop B) the hollow sphere C) the solid sphere D) the...
Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...
writting a c program that does the following: example output • Use Descriptor I/O operations to open the file specified as a command line argument and read at least one byte from the sequence of bytes before Hard Coded Pause Point 1. Use file system operations to remove the i-node entry for the file opened in between Hard Coded Pause Point 1 and Hard Coded Pause Point 2. You may assume the file specified on the command line will have...
Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...