Code format update For the input below: S1 = ACCGGTCGACTGCGCGGAAGCCGGCCGAA S2 = GTCGTTCGGAATGCCGTTGCTCTGTAAA S3 =
Question:
Code format update
For the input below:
S1 = ACCGGTCGACTGCGCGGAAGCCGGCCGAA
S2 = GTCGTTCGGAATGCCGTTGCTCTGTAAA
S3 = ATTGCATTGCATGGGCGCGATGCATTTGGTTAATTCCTCG
S4 = CTTGCTTAAATGTGCA
S5 = AGTTAATAGGACCTGATACG
S6 = TCGTTAATAGGACCTGATACGGTTTACTAG
update the code to compare S1, S2, S3, S4, S5, and S6. Also, add execution time (see highlighted text and output below)
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class tutorialcup
{
static String lcs(String S1, String S2, int m, int n) {
int[][] LCS_table = new int[m + 1][n + 1];
// Building the mtrix in bottom-up way
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 || j == 0)
LCS_table[i][j] = 0;
else if (S1.charAt(i - 1) == S2.charAt(j - 1))
LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1;
else
LCS_table[i][j] = Math.max(LCS_table[i - 1][j], LCS_table[i][j - 1]);
}
}
int index = LCS_table[m][n];
int temp = index;
char[] lcs = new char[index + 1];
lcs[index] = '\0';
int i = m, j = n;
while (i > 0 && j > 0) {
if (S1.charAt(i - 1) == S2.charAt(j - 1)) {
lcs[index - 1] = S1.charAt(i - 1);
i--;
j--;
index--;
}
else if (LCS_table[i - 1][j] > LCS_table[i][j - 1])
i--;
else
j--;
}
// change the highlighted below to write to the output ( writer.write)
System.out.print("\nLCS: ");
for (int k = 0; k <= temp; k++)
System.out.print(lcs[k]);
System.out.println("");
System.out.print("String Length :" );
System.out.println(temp);
return printSubsequence(S1, S2, LCS_table);
}
public static String printSubsequence(String S1, String S2, int[][] lcs) {
String output = "";
output += "S1 : " + S1 + "\nS2 : " + S2 ;
output += "\n\nPrinting out subseqence matrix...\n\n";
for(int i=0; i
output += " ";
else
output += " "+S2.charAt(i-2);
}
output += "\n";
for(int i=0; i
if(i!=0)
output += S1.charAt(i-1)+" ";
else
output += " ";
for(int j=0; j
}
output += "\n";
}
System.out.println(output);
return output;
}
public static void main(String[] args) {
String S1 = null, S2 = null;
Scanner keyboard = new Scanner(System.in);
// Prompt for input file name
System.out.print("Please enter input filename: ");
String inputFile = keyboard.nextLine();
// Prompt for output file name
System.out.print("Please enter input filename: ");
String outputFile = keyboard.nextLine();
System.out.println();
// Read S1 and S2 from input file
try {
Scanner reader = new Scanner(new File(inputFile));
S1 = reader.nextLine();
S2 = reader.nextLine();
} catch (FileNotFoundException e) {
System.out.println("Error! "+inputFile+" not found!");
}
int m = S1.length();
int n = S2.length();
String lcsMatrix = lcs(S1, S2, m, n);
// Write into output file
try {
PrintWriter writer = new PrintWriter(new File(outputFile));
writer.write(lcsMatrix);
writer.close();
} catch (FileNotFoundException e) {
System.out.println("Error! "+outputFile+" not found!");
}
}
}
Output(part of the output):
Fundamentals Of Digital Logic With Verilog Design
ISBN: 9780073380544
3rd Edition
Authors: Stephen Brown, Zvonko Vranesic