Question

Find the shortest common superstring for eight 3-mers: {AGT, AAA, ACT, AAC, CTT, GTA, TTT, TAA}

Find the shortest common superstring for eight 3-mers:

{AGT, AAA, ACT, AAC, CTT, GTA, TTT, TAA}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
using namespace std;

int maxOverLapOfTwoStrings(string s1, string s2, string &str)
{
   // maxValue stores the max of prefix and suffix those are matching
   int maxValue= INT_MIN;
   int l1 = s1.length();
   int l2 = s2.length();

   //checking whether prefix of s2 is suffix of s1 or not
   for (int i = 1; i <= min(l1, l2); i++)
   {
       if (s1.compare(l1-i, i, s2, 0, i) == 0)
       {
           if (maxValue< i)
           {
               maxValue= i;
               str = s1 + s2.substr(i);
           }
       }
   }

   // validating whether prefix of s1 matches suffix of s2
   for (int i = 1; i <= min(l1, l2); i++)
   {
       if (s1.compare(0, i, s2, l2-i, i) == 0)
       {
           if (maxValue< i)
           {
               maxValue= i;
               str = s2 + s1.substr(i);
           }
       }
   }

   return maxValue;
}

string fun(string A[], int n )
{
   //consider each pair
   while(n != 1)
   {
       int maxValue= INT_MIN;
       int l, r;
       string ansStr; //resultant string after overlap

       for (int i = 0; i < n; i++)
       {
           for (int j = i + 1; j < n; j++)
           {
               string str;

               int ans = maxOverLapOfTwoStrings(A[i], A[j], str);

               //look for max overlap
               if (maxValue< ans)
               {
                   maxValue= ans;
                   ansStr.assign(str);
                   l = i, r = j;
               }
           }
       }

       n--;

       if (maxValue== INT_MIN)
           A[0] += A[n];
       else
       {
           A[l] = ansStr;
           A[r] = A[n];
       }
   }
   return A[0];
}

int main()
{
   string A[] ={"AGT", "AAA", "ACT", "AAC", "CTT", "GTA", "TTT", "TAA"};
   int n = sizeof(A)/sizeof(A[0]);

   cout << "For given 8 strings the shortest superstring is "<< fun(A, n);
   cout<<endl;
   return 0;
}


output -

For given 8 strings the shortest superstring is AGTAAACTTT

Add a comment
Know the answer?
Add Answer to:
Find the shortest common superstring for eight 3-mers: {AGT, AAA, ACT, AAC, CTT, GTA, TTT, TAA}
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • mRNA transcr leaves the mucl ke protcins Th eings the amino no acids anre the bui...

    mRNA transcr leaves the mucl ke protcins Th eings the amino no acids anre the bui ead in onder to. start and stop mak Land when to stot C. Use your codon chart to determine the amino acid sequence. Remember to read through the strand and ONLY start on AUG and STOP when it tells you to stop Follow example below Example: DNA AGA CGG TAC CTC CGG TGG GTG CTT GTC TGT ATC CTT CTC AGT ATC UCU GCC...

  • Adenosine deaminases modify adenosines to form _____________________, which is then read as _________________________ by the translation...

    Adenosine deaminases modify adenosines to form _____________________, which is then read as _________________________ by the translation and splicing systems, as well as by reverse transcriptase. Cephalopods like squid and octopus use this form of editing very extensively in their protein-coding regions.  For each of the following, please indicate how these enzymes can alter the mRNA to produce the indicated codon changes.   I (Ileu)  is changed to V (val): K (Lys) is changed to E (Glu): T (Thr) is changed to A (ala):...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT