1 Problem Description
Instructions.
You are provided one skeleton program named
LCS.java
. The
source files are available on Canvas in a folder named
HW6
. Please modify the
skeleton code to solve the following tasks.
•
Task 1 (100 pts). Implement the
lcs
length()
function as discussed in
Lecture 11.
•
Note:
You
should not
return the double-array
b
and
c
as in the pseu-
docode. Instead, return the length of the longest common subsequence.
•
Hint:
To get the i-th character in a string s, use
s.charAt(i)
. For example, the code
String s = ”XYZ“;
System.out.println(s.charAt(1));
prints out Y.
package dp;
public class LCS {
public static int lcs_length (String X, String Y) {
/*
* fill in your code here
* Note: return the length of LCS, instead of c and b
*/
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(LCS.lcs_length("ABCBDAB", "BDCABA"));
System.out.println(LCS.lcs_length("ACCGGTCGAGTGCGCGGAAGCCGGCCGAA",
"GTCGTTCGGAATGCCGTTGCTCTGTAAA"));
}
}
CODE
public class LCS {
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
public static int lcs(char[] X, char[] Y, int m, int n)
{
if (m == 0 || n == 0)
return 0;
if (X[m - 1] == Y[n - 1])
return 1 + lcs(X, Y, m - 1, n - 1);
else
return Math.max(lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n));
}
public static int lcs_length(String X, String Y) {
return lcs(X.toCharArray(), Y.toCharArray(), X.length(), Y.length());
}
public static void main(String[] args)
{
System.out.println(LCS.lcs_length("ABCBDAB", "BDCABA"));
System.out.println(LCS.lcs_length("ACCGGTCGAGTGCGCGGAAGCCGGCCGAA",
"GTCGTTCGGAATGCCGTTGCTCTGTAAA"));
}
}
OUTPUT
4
1 Problem Description Instructions. You are provided one skeleton program named LCS.java . The source files...
The following code skeleton contains a number of uncompleted methods. With a partner, work to complete the method implementations so that the main method runs correctly: /** * DESCRIPTION OF PROGRAM HERE * @author YOUR NAME HERE * @author PARTNER NAME HERE * @version DATE HERE * */ import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class ArrayExercises { /** * Given a random number generator and a length, create a new array of that * length and fill it from...
USE JAVA Using recursion, find the largest element in an array. Skeleton code is provided. Please do not change the DataSetDemo code. Hint: Find the largest element in the subset containing all but the last element. Then compare that maximum to the value of the last element. Skeleton Code: DataSet: /** Computes the maximum of a set of data values. */ public class DataSet { private int[] values; private int first; private int last; /** Constructs a DataSet object. @param...
TreeNode.java public class TreeNode { public int key; public TreeNode p; public TreeNode left; public TreeNode right; public TreeNode () { p = left = right = null; } public TreeNode (int k) { key = k; p = left = right = null; } } BinarySearchTree.java public class BinarySearchTree { public TreeNode root; public BinarySearchTree () { root...
You will be writing some methods that will give you some practice working with Lists. Create a new project and create a class named List Practice in the project. Then paste in the following code: A program that prompts the user for the file names of two different lists, reads Strings from two files into Lists, and prints the contents of those lists to the console. * @author YOUR NAME HERE • @version DATE HERE import java.util.ArrayList; import java.util.List; import...
In a file named LLBag.java, write a class called LLBag that implements the Bag interface using a linked list instead of an array. You may use a linked list with or without a dummy head node. Bag interface code: /* * Bag.java * * Computer Science 112, Boston University */ /* * An interface for a Bag ADT. */ public interface Bag { /* * adds the specified item to the Bag. Returns true on success * and...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...
Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...
hey I need help finishing this simplex program. public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //FAIRE LES TODO dans Simplex test1();test2(); } private static void test1() { double[][] A = { { -1, 1, 0 }, { 1, 4, 0 }, { 2, 1, 0 }, { 3, -4, 0 }, ...
8.18 Ch 8, Part 3: Tabular Output Write this program using Eclipse. Comment and style the code according to CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. The program you are going to write will produce a String containing a tabular representation of a 2D String array. For the 2D arrays, assume that the first...