Problem 1.
Write a program in Java to find the Longest Common Subsequence (LCS) using Dynamic Programming. Your program will read two strings from keyboard and display the LCS on the screen.
Assume upper and lower case letters as same.
Sample Input (taken from keyboard):
saginaw
gain
Sample output (display on the screen):
ain
import java.util.Scanner;
public class Main {
public static void longestCommonSubsequence(String str1, String str2) {
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
int m = str1.length();
int n = str2.length();
int[][] L = new int[m+1][n+1];
for (int i=0; i<=m; i++) {
for (int j=0; j<=n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (str1.charAt(i-1) == str2.charAt(j-1))
L[i][j] = L[i-1][j-1] + 1;
else
L[i][j] = Math.max(L[i-1][j], L[i][j-1]);
}
}
int index = L[m][n];
int temp = index;
char[] lcs = new char[index+1];
lcs[index] = '\t';
int i = m, j = n;
while (i > 0 && j > 0) {
if (str1.charAt(i-1) == str2.charAt(j-1)) {
lcs[index-1] = str1.charAt(i-1);
i--;
j--;
index--;
}
else if (L[i-1][j] > L[i][j-1])
i--;
else
j--;
}
System.out.print("Longest Common Subsequence of " + str1 + " and " + str2 + " is ");
for(int k=0;k<=temp;k++)
System.out.print(lcs[k]);
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first string: ");
String str1 = sc.nextLine();
System.out.println("Enter the second string: ");
String str2 = sc.nextLine();
longestCommonSubsequence(str1, str2);
}
}

NOTE: Two strings can have more than one LCS, hence the output might differ from the one you provided.
Problem 1. Write a program in Java to find the Longest Common Subsequence (LCS) using Dynamic...
1. Write the algorithm pseudocode for the longest common subsequence problem using dynamic programming. What is its running time?
Create a C++ Header Function with DYNAMIC programing with the following details: longest common subsequence input: a string a of length m and a string b of length n output: the longest string ssuch that s is a subsequence of both a and b; in the case of ties, use the substring that comes first alphabetically The dynamic programming algorithm for subsequences is similar to the one for substrings. Both involve a 2D array of strings, base cases, and a...
I need this using C++.
In this project, you will implement the dynamic programming-based solution to find the longest common subsequence (LCS) of two sequences. Your inputs will be the two sequences (as Strings) and the outputs are the longest common subsequence (printed as a String) and the final matrix (printed as a two-dimensional array) depicting the length of the longest common subsequences (as shown in the slides) for all possible subsequences of the two input sequences. The two input...
3. (4 pt) Write a Python program to find the longest common prefix string amongst an array of strings. You are required to write a function max- Prefix, which when called by the main program would get the array of strings as input and return a single string that would either be the longest 1 common prefix or a string ”NULL” depending on the input. (Note: The array is input from the keyboard in the main program (930)) If there...
***LOOPS NOT ALLOWED*** String variables and use of String methods: Write a complete Java program which prompts the user for a string with 3 words each separated by a single space and reads the line into one String variable using nextline(). Extract each word and add them to a new String variable in reverse order with a space between the words. Have the 1st letter of the new string in upper case and all other strings in lower case letter....
Using the programming language Java: Write a function to find the longest common prefix string amongst an array of strings.
Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a string entered from the keyboard (in lower case letters). The program will then provide 6 options about operations performed on the input string in the form of a menu, as shown in the following sample Input/Output. The 6 operations are given below: 1. print the string 2 reverse the string 3. print the length of the string 4. convert the lower letters to upper...
Must be in JAVA. Write a program that uses a Scanner to read in a String. The program will then output a new String with all the vowels (upper and lower case) removed. See output for example output. Details Input A string composed of non-numeric characters Output The input string with the vowels removed Sample input: Welcome to Dalhousie Sample output: Dlhs nvrsty
This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...