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 resources can be shared over a computer network?
quester [9]

Answer:birthday

Explanation:

4 0
3 years ago
Read 2 more answers
Mary uploaded some images on her website. She chose an image and downloaded it. She found that the image she saw on screen did n
kondor19780726 [428]
It could be A or B, with a guess that it’s A. Many websites require images to be compressed on uploading so that it takes less of the site’s database storage, but the wording leads me to believe it may be B. Any thoughts?
4 0
3 years ago
Which feature is a dynamic grouping of applications used in Security policy rules?
larisa86 [58]

The answer is application group.


4 0
3 years ago
I need help with this. It's while loops in python.
CaHeK987 [17]

Answer:

Here is a simple application running loop example in python

running = true

while(running):

# YOUR CODE HERE

Explanation:

A while loop is basically a loop of something if something is true

so if there is a boolean set to true for a application to run then use a while loop. Have a nice day! :)

4 0
3 years ago
Complete the following sentence.
lidiya [134]

Answer:

Some dams produce renewable hydroelectric power  

Explanation:

hydroelectric is power from water

6 0
3 years ago
Other questions:
  • Radio waves pros and cons
    10·2 answers
  • Define a function below called increase_elements_by_x, which takes two arguments - a list of numbers and a single positive numbe
    13·1 answer
  • Jenna wants to convert a decimal number to its octal form. Which option will she use to calculate the octal number?
    8·1 answer
  • To move or copy a range of cells, select the correct order:
    5·1 answer
  • 1. Write a SELECT statement that returns these columns: The count of the number of orders in the Orders table The sum of the Tax
    12·1 answer
  • Which of the following binary numbers is equivalent to decimal 4?
    8·2 answers
  • It is where the home tab is located where you can view all the all the formatting purpose <br>​
    11·1 answer
  • Which clue can be used to identify a chemical reaction as a combustion reaction?
    9·1 answer
  • How do I answer other peoples question. is there something to click because i dont see it.
    14·2 answers
  • Firestick optimizing system storage and applications loop
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!