You are asked to modify the LCS algorithm to identify the heaviest common subseq
ID: 3576654 • Letter: Y
Question
You are asked to modify the LCS algorithm to identify the heaviest common subsequences (HCS) using a weighted scoring scheme, denoted as matrix M, as shown below. Based on this score scheme, A-A match has a score of 1, B-B match has a score of 2, A-B match has a score of 0.5. For example, given that X - {BACBADCDD} and Y = {BCDABCBDD}, the subsequences S_1 x = {BABA} and S_1 y = {BABB} has a matching score of 2 + 1 - 2 - 1 - 0.5 = 5.5, and the subsequence S_2 = {CDCDD} has a matching score of 1 + 1 + 1 + 1 + 1 = 5. Hence, the shared sequence of S_1 x and S_1 y is heavier (with higher scores) than the perfect, match subsequence of S_2. (In practice, S_1 a and S_1 b are often merged as {BABA/B}. Your task is to design an algorithm to identify the heaviest, common subsequence by modifying the LCS algorithm in CLRS textbook (a) First, illustrate the application of dynamic programming on heaviest common sub-sequence (HCS) using the example of X and Y sequences given above, by following the example of Figure 15.8 in the CLRS textbook. (b) Design a HCS algorithm by modifying the LCS-LENGTH(X, Y) in Chapter 15 of the CLRS textbook using a weighted scoring matrix M as shown above. The rows and columns in M are symbols of of {A, B, C, D}, and the elements of M are scores such that M[A, A] = 1, M[B, B] = 2, M [A, B] = 0.5, M[A, C] = 0, ....Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
struct node
;
typedef struct node n;
n* create_node(int);
void add_node();
void insert_at_first();
void insert_at_end();
void insert_at_position();
void delete_node_position();
void sort_list();
void update();
void search();
void display_from_beg();
void display_in_rev();
n *new, *ptr, *prev;
n *first = NULL, *last = NULL;
int variety = 0;
void main()
come new;
}
/*
*ADDS NEW NODE
*/
void add_node()
next = new;
new->prev = last;
last = new;
last->next = first;
first->prev = last;
" id="tip_19">
}
/*
*INSERTS part initially
*/
void insert_at_first()
currently new node is inserted however at first");
initial = last = new;
first->next = last->next = NULL;
first->prev = last->prev = NULL;
}
else
}
/*
*INSERTS THE part AT GIVEN POSITION
*/
void insert_at_position()
{
int info, pos, len = 0, i;
n *prevnode;
printf(" enter the worth that you simply would love to insert:");
scanf("%d", &info);
printf(" enter the position wherever you have got to enter:");
scanf("%d", &pos);
new = create_node(info);
if (first == last && initial == NULL)
{
if (pos == 1)
{
initial = last = new;
first->next = last->next = NULL;
first->prev = last->prev = NULL;
}
else
printf(" empty coupled list you cant insert at that specific position");
}
else
}
}
for (ptr = initial, i = 0;i < number;ptr = ptr->next,i++)
printf(" %d", ptr->val);
}
}
/*
*DELETION is completed
*/
void delete_node_position()
zero, key, i, f = 0;
printf(" enter the worth to be searched:");
scanf("%d", &key);
if (first == last && initial == NULL)
printf(" list is empty no elemnets in list to search");
else
{
for (ptr = initial,i = 0;i < number;i++,ptr = ptr->next)
{
count++;
if (ptr->val == key)
{
printf(" the worth is found at position at %d", count);
f = 1;
}
}
if (f == 0)
printf(" the worth isn't found in linkedlist");
}
}
/*
*DISPLAYING IN starting
*/
void display_from_beg()
{
int i;
if (first == last && initial == NULL)
printf(" list is empty no elemnts to print");
else
{
printf(" %d variety of nodes square measure there", number);
for (ptr = initial, i = 0;i < number;i++,ptr = ptr->next)
printf(" %d", ptr->val);
}
}
/*
* DISPLAYING IN REVERSE
*/
void display_in_rev()
{
int i;
if (first == last && initial == NULL)
printf(" list is empty there aren't any elments");
else
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.