Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please provide comments for better understanding, use Java if in code, follow th

ID: 3593929 • Letter: P

Question

Please provide comments for better understanding, use Java if in code, follow the prompt and example given

(5 + 2 points) Given two sequences of symbols A and B of lengths m and n resepec- tively, design an algorithm for computing the length of the longest possible common subsequence if we are allowed to change at most one element of A. For example, if A-[a, a,b, b, b] and B-la, c, c, b] , then the answer is 3, because we can change the second symbol in A and get A = [a,c,b,b,b]. After that, the longest common subsequence is [a, c,b]. The complexity of the algorithm has to be 0(mn)

Explanation / Answer

//Using Java 8 collections.

1. Assign A and B to two lists and get the size of the list to vriables firstSize and secondSize.

2. Check whether A or B is having duplicates. if yes set separate flag for both, flagA= true, if A has duplictaes. flagB=true if B has duplicates.

3. Assign A to a set and B to another set.

4. Set will remove the dupicates in A and B and unique data will be assigned in A and B.

5. Get the size of set A to setOne and B to setTwo.

6. check whether setOne is greater than setTwo and flagB is true, If yes answer is setOne

7.check whether setTwo is greater than setOne and flagA is true, If yes answer is setTwo.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote