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]
2 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]2 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
A _________________ operating system accepts random enquires from remote locations and provides an instantaneous response
dlinn [17]

Answer:

Real-time operating system (RTOS) are

Explanation:

Real-time operating system (RTOS) are operating systems that are meant for use with time sensitive applications and systems that have very strict time requirements such as in computers serving air traffic control systems, robot systems, or missile control systems.

The processing time for each process are in the order of tenths of a second or shorter time frames using given constraints.

Real-time systems are applied in life saving systems like parachutes or air bags so as to prevent injuries in the event of an accident.

8 0
2 years ago
What are the two basic steps in communication
Andrei [34K]

The sender forms an idea.The sender encodes the idea in a message.

4 0
3 years ago
____ steganography places data from the secret file into the host file without displaying the secret data when you view the host
EastWind [94]

Answer: Insertion steganography

Explanation: Insertion steganography is the way of encrypting the data with the help of a regular files and message. It is encrypted by the ordinary files because the identification of files can be neglected. This process is carried out just for the protection purpose in extra form and gets decrypted  in the destination port .It has the working based on the replacement of the bits in a file .

8 0
2 years ago
What kind of device is a printer? output or input
ANEK [815]
A printer is output. :)
8 0
2 years ago
When entering a function or formula in a cell, which is the first character
AnnZ [28]

Answer:

B

Explanation:

6 0
2 years ago
Other questions:
  • to prevent long page load time for pages containing images. It is best to use a compress file formatlike jpeg as well as appropr
    6·2 answers
  • What is the difference between primary storage,secondary storage and offline storage what type of storage can be
    6·2 answers
  • What to buy instead of the hp chromebook 13
    15·1 answer
  • A superscope is a special type of scope that allows a dhcp server to service multiple ipv4 subnets on multiple physical networks
    7·1 answer
  • This diagram shows a number of computing devices connected to the Internet with each line representing a direct connection.
    11·1 answer
  • Convert each of the following base 10 &amp; base 2 numbers in signed magnitude, one’s complement and two’s complement. Each of t
    8·1 answer
  • In this exercise, you will get some practice with the __add__ method by implementing it for a class called ContactBook. This cla
    12·1 answer
  • Differentiate between perfect and imperfect market​
    14·1 answer
  • What is the action of extracting data fragments and then reassembling them in order to recover a file?.
    10·1 answer
  • Energy/power management systems, kitchen appliances, smart televisions, baby monitors, fitness trackers, and personal health mon
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!