1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
UkoKoshka [18]
3 years ago
7

Two character strings may have many common substrings. Substrings are required to be contiguous in the original string. For exam

ple, photograph and tomography have several common substrings of length one (i.e., single letters), and common substrings ph, to, and ograph as well as all the substrings of ograph. The maximum common substring length is 6. Let X = X122 . Im and Y = yıy2 - - • Yn be two character strings. Using dynamic programming, design an algorithm to find the maximum common substring length for X and Y using dynamic programming. Please follow the general steps for designing a dynamic programming solution as in Q1 (other than the actual programming part).
Computers and Technology
1 answer:
ryzh [129]3 years ago
8 0

Answer:

Explanation:

The following function is written in Java. It takes two strings as parameters and calculates the longest substring between both of them and returns that substring length.

import java.util.*;

class Test

{

   public static void main(String[] args)

   {

       String X = "photograph";

       String Y = "tomography";

       System.out.println(X + '\n' + Y);

       System.out.println("Longest common substring length: " + longestSub(X, Y));

   }

   static int longestSub(String X, String Y)

   {

       char[] word1 = X.toCharArray();

       char[] word2 = Y.toCharArray();

       

       int length1 = X.length();

       int length2 = Y.length();

       int substringArray[][] = new int[length1 + 1][length2 + 1];

       int longestSubstringLength = 0;

       

       for (int i = 0; i <= length1; i++)

       {

           for (int j = 0; j <= length2; j++)

           {

               if (i == 0 || j == 0)

                   substringArray[i][j] = 0;

               else if (word1[i - 1] == word2[j - 1])

               {

                   substringArray[i][j]

                           = substringArray[i - 1][j - 1] + 1;

                   longestSubstringLength = Integer.max(longestSubstringLength,

                           substringArray[i][j]);

               }

               else

                   substringArray[i][j] = 0;

           }

       }

       return longestSubstringLength;

   }

}

You might be interested in
What is a computer system?
klio [65]
A system of interconnected computers that share a central storage system and various peripheral devices such as a printers, scanners, or routers. Each computer connected to the system can operate independently, but has the ability to communicate with other external devices and computers

<span>Read more: http://www.businessdictionary.com/definition/computer-system.html</span>
4 0
3 years ago
Help me please, I'm begging you
wel

Answer: 7 math 8 many

Explanation: it makes sense

5 0
3 years ago
A set of object that share a common structure and common behavior in database is called ​
Tcecarenko [31]
An Object Class. Hopefully this answer is right.
3 0
3 years ago
In a typical​ product-mix problem in linear​ programming, each general constraint states that
Montano1993 [528]
<span>In a typical product-mix problem in linear programming, each general constraint states the function to minimize and maximize a subject in programming to a finite number. This was created by George Dantzig it was further improved using a new method to solving linear programming last 1984.</span>
6 0
3 years ago
Write a javascript program that reads three integers named start, end, and divisor from three textfields. your program must outp
Karolina [17]
Please take down this question.  It is a test question and posting it on this forum is considered cheating.
7 0
2 years ago
Read 2 more answers
Other questions:
  • Craig's annual take-home pay is $75,000. What is the maximum amount that he can spend per month paying off credit cards and loan
    7·2 answers
  • I want to customize my company's logo, name, address, and similar details in all my business documents what option should use?
    12·1 answer
  • Look act the picture
    5·1 answer
  • In a flow chart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that
    9·1 answer
  • Joe always misspelled the word calendar what function corrects the word
    12·2 answers
  • Assume that ip has been declared to be a pointer to int and that enrollment has been declared to be an array of 20 elements . As
    13·1 answer
  • A report has a column of totals, with each total adding to the cell above it. What kind of calculated figure is this?
    15·1 answer
  • Which administrative tool can you use to check your computer's health or troubleshoot problems with the operating system or soft
    11·2 answers
  • What is the purpose of a report?
    12·2 answers
  • How many atoms of oxygen in 4 molecules of HN03​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!