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
kirza4 [7]
3 years ago
10

Dr. Watson has been kidnaped! Sherlock Holmes was contacted by the kidnapper for ransom. Moments later he received a message fro

m Dr. Watson's phone. The message contained three random strings. Sherlock being Sherlock, was able to deduce immediately that Dr. Watson was trying to give a hint about his location. He figured out that the longest common subsequence between the 3 words is the location. But since it was too easy for him, he got bored and asked you to find out what the actual location is. Your task is to find the longest common subsequence from the 3 given strings before it is too late. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. For instance, given a sequence "drew"; "d", "w", "de", "drw", "drew" are all examples of valid subsequences (there are also others), while "er", "wdre" are not. Design a dynamic programming algorithm which takes three input sequences X, Y, and Z, of lengths m, n, and p, respectively, and returns their longest common subsequence. For full marks your algorithm should run in (mnp) time. Note that W is a common subsequence of X, Y, and Z if and only if W is a subsequence of X, W is a subsequence of Y, and W is a subsequence of Z.
Required:
Describe the set of subproblems that your dynamic programming algorithm will consider.
Computers and Technology
1 answer:
adelina 88 [10]3 years ago
8 0

Answer:

please mark me brainlist

Explanation:

This algorithm works for n number of strings in python3

Input:

83217

8213897

683147

Output:

837

from itertools import product

import pdb

import numpy as np

def neigh(index):

N = len(index)

for ri in product((0, -1), repeat=N):

if not all(i == 0 for i in ri):

yield tuple(i + i_rel for i, i_rel in zip(index, ri))

def longestCommonSubSequenceOfN(sqs):

numberOfSequences = len(sqs); # to know number of sequences

lengths = np.array([len(sequence) for sequence in sqs]); # to know length of each sequences placed in # array

incrLengths = lengths + 1; # here we are taking no .of sequences +1

lengths = tuple(lengths); # making lengths into tuple to make it mutable

inverseDistances = np.zeros(incrLengths);

ranges = [tuple(range(1, length+1)) for length in lengths[::-1]]; # finding ranges from 1 to each lengths

for tupleIndex in product(*ranges):

tupleIndex = tupleIndex[::-1];

neighborIndexes = list(neigh(tupleIndex)); # finding neighbours for each tupled index value and # store them in list

operationsWithMisMatch = np.array([]); # creating array which are miss matched

 

for neighborIndex in neighborIndexes:

operationsWithMisMatch = np.append(operationsWithMisMatch, inverseDistances[neighborIndex]);

#appending newly created array with operations miss match and inverseDistances

operationsWithMatch = np.copy(operationsWithMisMatch);

# copying newly generated missmatch indexs

operationsWithMatch[-1] = operationsWithMatch[-1] + 1;

# incrementing last indexed value

chars = [sqs[i][neighborIndexes[-1][i]] for i in range(numberOfSequences)];

# finding a string(chars) with neighbour indexes and checking with other sequences

if(all(elem == chars[0] for elem in chars)):

inverseDistances[tupleIndex] = max(operationsWithMatch);

else:

inverseDistances[tupleIndex] = max(operationsWithMisMatch);

 

subString = ""; # resulted string

mainTupleIndex = lengths; # copying lengths list to mainTupleIndex

while(all(ind > 0 for ind in mainTupleIndex)):

neighborsIndexes = list(neigh(mainTupleIndex));

#generating neighbour indexes with main tuple index in form of list

anyOperation = False;

for tupleIndex in neighborsIndexes:

current = inverseDistances[mainTupleIndex];

if(current == inverseDistances[tupleIndex]): # comparing indexes in main tuple index and inverse #distance tuple index

mainTupleIndex = tupleIndex;

anyOperation = True;

break;

if(not anyOperation): # if anyoperation is False then we are generating sunString

subString += str(sqs[0][mainTupleIndex[0] - 1]);

mainTupleIndex = neighborsIndexes[-1];

return subString[::-1]; # reversing resulted string

sequences = ["83217", "8213897", "683147"]

print(longestCommonSubSequenceOfN(sequences)); #837

You might be interested in
Hi i need help with something:(
AleksandrR [38]

Answer: what do  you need help with?

Explanation:

4 0
2 years ago
Read 2 more answers
Which type of chart is most useful when a user is trying to visually represent sets of data as parts of a whole, such as product
nataly862011 [7]

Pie chart, I’m fairly sure the rest aren’t real

5 0
3 years ago
Read 2 more answers
If you have long column labels with columns so wide that they affect the readability of a worksheet, you should first
Alla [95]
The answer is (C) consider how you could shorten the column labels.

The label at the top of a column is sometimes wider than the data stored in the column. Expanding a column is an option but this may mean that you will not see as many columns on a page as possible. Wrapping text is also an option but has a downside to it as well since it will make the row with great height. 

Rotating the labels is also a possibility but is also not recommended. This leaves us with shortening the column labels and keep dictionary worksheet for users. As much as you can, consider using acronyms and abbreviations.






6 0
3 years ago
Read 2 more answers
Which three IP addresses may be pinged by the Test Management Network feature in the ESXi hosts DCUI
Sholpan [36]

Answer:

Primary DNS server

Secondary DNS server

Default gateway

Explanation:

The following tests are performed by ESXi:

  • Pings the subnet gateway that is stated.
  • Pings the primary DNS server that is stated.
  • Pings the secondary DNS server that is stated.
  • Ensure that the hostname of the ESXi host is resolved by it.

Based on the above, the three IP addresses may be pinged by the Test Management Network feature in the ESXi hosts DCUI are are therefore the following:

  • Primary DNS server
  • Secondary DNS server
  • Default gateway
5 0
3 years ago
the header, in an academic report, typically contains the author’s name and the current page number true or false
kolbaska11 [484]
TRUE

True


In most academic reports, most specifically, an MLA academic report, Student’s last name and current page number is contained in the headers. In MLA, which is most common used formatting guide in academic reports, headers numbers all pages consecutively within the right margin.


6 0
3 years ago
Other questions:
  • What is tuple and attribute of a relation​
    11·1 answer
  • A ____ is a collection of computers and users that are identified by a common security database. workgroup controller segment do
    7·1 answer
  • We are continuously sending and receiving messages that may change midstream. This illustrates that____________.
    15·1 answer
  • Which option can be used to access more settings than are available in the Backstage view?
    5·1 answer
  • Are to print or find<br> the sum<br> 5 numbers<br> of<br> using flow chart
    6·1 answer
  • To gain a competitive edge this year, the upper management of a global IT company has decided to focus on customer service, empl
    13·1 answer
  • Businesses and sometimes individuals use a _____ to assimilate all of their social media content on a specific topic to engage r
    13·1 answer
  • What are 3 software programs for mobile computing?
    10·1 answer
  • Explain briefly the use of the computers in the advertising area​
    11·1 answer
  • Hexadecimal to denary gcse method
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!