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
The difference between a dot matrix printer and a line printer
bezimeni [28]

Answer:

please give me brain list and follow

Explanation:

Difference Between Dot Matrix and Line Printer is that Dot-matrix printer produce printed images, they produce image when tine wire pins on a print head mechanism strike an inked ribbon. While Line printer is a type of impact printer which is high-speed and printer an entire line at a time.

4 0
3 years ago
Read 2 more answers
This is a graded practice activity. This is not an actual quiz.
Lerok [7]

Answer:

0

Explanation:

x=27

y=5

22+(27-5)

22+(22)

0

8 0
1 year ago
Question # 4
arlik [135]

Answer:

Explanatio Morse code

4 0
2 years ago
You can customize backdrops in Scratch, adding text or freestyle drawings over the initial image
sveticcg [70]

Answer:

A. True

Explanation:

ive done this myself

https://scratch.mit.edu/projects/395142260/

3 0
2 years ago
Class 7th Subject Computer all chapters 2nd page​
LenKa [72]

no.13 answer is( B ) and no.14 answer is also (B)

7 0
3 years ago
Other questions:
  • True or false? It is just too challenging to have different password for every
    12·1 answer
  • Which markup language would be considered the most current for web design? HTLM, HTML5, XHTLM, XHTML 6
    14·2 answers
  • It is not possible to convert a numbered list to a bulleted list in Word 2007. T or F
    13·1 answer
  • Write a program that reads a list of scores and then assigns grades python
    9·1 answer
  • What should you do prior to writing your business document?
    11·1 answer
  • A forensic investigator at a crime lab is performing a forensic analysis of a hard drive that was brought in by state troopers.
    10·1 answer
  • What is the Role of an algorithm?
    11·1 answer
  • Help Me<br><br> What are the four types of graphic models?
    10·1 answer
  • A system administrator issues the command ps on a server that is running the Linux operating system. What is the purpose of this
    9·1 answer
  • In a database, what term is used to describe a group of fields that are all associated with and accessed using single primary ke
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!