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
The Status bar is used to control the majority of the drafting settings in AutoCAD
kifflom [539]

The answer is "true"

Hope this helps!

6 0
3 years ago
Which of the following bit patterns represents the value -9 in two’s complement notation?
nadya68 [22]

Answer:

B. 11110111

Explanation:

Binary representation of number 9 = 00001001

Binary representation of -9 would involve calculating the twos complement representation of 00001001

First we compute the ones complement of this number by reversing the bits.

00001001 => 11110110

Next we calculate the twos complement representation by adding 1 to the ones complement.

11110110+1 = 11110111

So the final representation is 11110111.

5 0
3 years ago
In black and white,<br><br> we must be more conscious of image
scZoUnD [109]

is it true or false is so it is false

3 0
3 years ago
This formatting option functions like a space bar. However, instead of moving one space at a time, it allows you to move your te
uysha [10]
Would it be Tab. I know that if you are in Microsoft word it works like that.<span />
3 0
3 years ago
Coordinate with
Lunna [17]

Answer:

First blank: producer

Second blank: Hairdressers

5 0
3 years ago
Other questions:
  • A benefit of IPsec is __________.
    8·1 answer
  • Anybody good with Microsoft excel? I need help with this class.
    9·2 answers
  • What do developers do to support software products? explain to users which development process model was used to make the produc
    8·1 answer
  • Person-name: String+setName(String name): void+getName(): String^Student-studentID: long+Student(String sname, long sid)+setID()
    10·1 answer
  • What is the best way to learn JavaScript?
    5·2 answers
  • What is the meaning of 4 8 15 16 23 42?
    14·1 answer
  • What does the CFO of a company do
    14·1 answer
  • Write a brief, two-page paper describing how your lifestyle and values impact your use of the Web for e-commerce. How is your on
    15·1 answer
  • create a function that has an argument is the triple jump distance. It returns the estimate of vertical jump height. The world r
    8·1 answer
  • Learning Task 3: Write the safety requirement indicated in each number on a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!