In Bioinformatics, a DNA sequence is made up of a
combination of 4 characters, namely “A,C,G,T”. A
subsequence of a given sequence of characters a0, a1, …an-
1, is any subset of the characters taken in order, of the
form ai0 , ai1 ,…..aik-1 where 0 ≤ i0 <i1….< ik-1 ≤ n-1.
For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”,
we can have subsequences “A,G,T”, “A,C,A,A” and many more.
A subsequence is palindromic if it is the same whether read
left to right or right to left. For instance, the
sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many
palindromic subsequences, including “A,C,G,C,A”
and “A,A,A,A” (on the other hand, the subsequence “A,C,T”
is not palindromic). Devise an algorithm (using dynamic
programming) that takes a sequence of characters X[0 … n-1]
from the alphabet set (A,C,G,T) and returns the (length of
the) longest palindromic subsequence. Implement the
algorithm in an appropriate language.
Answer Posted / pragnesh
import java.io.*;
import java.util.*;
public class p3{
public static void main(String[] args) throws
FileNotFoundException{
Scanner inFile = new Scanner(new FileReader("words.txt"));
String s;
String temp, tempRev="";
while(inFile.hasNext()){
s=inFile.nextLine();
temp=s;
temp = temp.replace("?","");
temp = temp.replace(".","");
temp = temp.replace(",","");
temp = temp.replace(":","");
temp = temp.replace("\"","");
temp = temp.replace(" ","");
for(int x=temp.length()-1;x>=0;x--)
tempRev = tempRev + temp.charAt(x);
if(temp.equalsIgnoreCase(tempRev))
System.out.println(s + " is a palindrome");
else
System.out.println(s + " is not a palindrome");
tempRev="";
}
inFile.close();
}
}
maybe you could adapt that to c++
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
what are all the validation we need to perform in data stage?
1) How can u create the table?
I am looking for selenium RC online Training in chennai. can any one tell me the best institute
I am taking the bmc control m/enterprise manager 7.0 scheduling test and just wanted to see what kind of questions they would ask or if anyone has taken the test and how long it is for how many questions?
along with oracle which language will be beneficial to have knowledge with,java,.net,since i m doing oracle have appeared for 8th sem BEIT,plz suggest
Difference between debugging, running, executing of an application
what is apt_dump_score in datastage where it is useful
What is SOLID Principle in Programming Language?
I want Ada programming language books. Could anyone post me any link for that?
how do i create my own exception class which will restrict IO exception?
5. How do you round the addition or subtraction of two numbers in assembler?
Write a program to create a process in UNIX
3. What is the difference between testing and Quality Assurance?
what is woransient key word? how it is used in java
Explain what is OOPS and its concepts?