Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LCS knapsack code Algorithms Complete the following problem using python3 language. Please paste the codes using proper intended blocks with (Ctrl+shift+v). Also please provide the

LCS knapsack code

Algorithms

Complete the following problem using python3 language. Please paste the codes using proper intended blocks with (Ctrl+shift+v). Also please provide the screenshots of the codes. Do not do mistake sir please follow the proper instructions. Thank you.i will up vote you if you do it unique and properly.do it in your own way.do not copy from others.thanks sir.

Note: please follow all the instruction given in the question.Read the question properly first.

Question:

Problem Description: The following tasks needed to be solved by using dynamic Programming. Dynamic programming is a way of finding the optimal solution of a problem where it reduces the call of functions by storing their results in every sequence. It compares the results of every step and from the comparison finds out the optimal solution. Longest common subsequence (LCS) is such an algorithm that functions as a dynamic approach. It basically finds out the longest subsequence which is common to the given sequences. Read the task descriptions carefully and implement the algorithm using Python .The output format MUST match exactly as shown in each task.

Note: please follow all the instruction given in the question.Take input from text files called "input2.txt", and output at "output2.txt", where X is the task number. Must be follow this.

*Read the question properly first.

Problem 2 :

You know about how to find the Longest Common Subsequence (LCS) between two strings using dynamic programming. Lets make it a bit challenging. I will give you three strings instead of two, and now you need to find out the Longest Common Subsequence (LCS) among these three strings. Sounds interesting, right? I know you can do it!

Input: Each input will consist of three strings in each line. The length of each string will be no greater than 100.

Output: Output the length of the longest common subsequence of the given three strings.

Sample Input 1: hell hello bella

Sample Output 1: 3

Sample Input 2: abbcdab daccbadb abccdaab

Sample Output 2: 4

Hint: For this problem you have to construct LCS for 3 parameters. You can use the following pseudo code to find out the longest common subsequence of three strings.

LCS(X, Y, Z): m <- length[X] + 1 n <- length[Y] + 1 o <- length[Z] + 1 c[m][n][o] t[m][n][o] for i <- 1 to m: for j <- 1 to n: for k <-1 to o: if i = 0 Or j = 0 Or k = 0: c[i][j][k] <- 0 t[i][j][k] <- null/None else: if x[i] = y[j] And x[i] = z[k]: c[i][j][k] <- 1 + c[i-1][j-1][k-1] t[i][j][k] <- diagonal else: if c[i-1][j][k] >= c[i][j-1][k]: max <- c[i-1][j][k] if max >= c[i][j][k-1]: c[i][j][k] <- max t[i][j][k] <- up-up-left else: max <- c[i][j][k-1] c[i][j][k] <- max t[i][j][k] <- left-up-up else: max <- c[i][j-1][k] if max >= c[i][j][k-1]: c[i][j][k] <- max t[i][j][k] <- up-left-up else: max <- c[i][j][k-1] c[i][j][k] <- max t[i][j][k] <- left-up-up

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions