GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The strings X = XYXZYXZ and Y = YZXYXZY are given. Their longest common subsequences all have length 5. How many distinct strings of length 5 are common subsequences of both X and Y?
- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: D. 3
Running the LCS table and collecting all optimal paths gives exactly three distinct strings: XYXZY, YXYXZ and YZYXZ (verified by exhaustive backtracking). Counting alignments instead of distinct strings would overcount, and counting only one path misses the others.
More Algorithms questions
- The edit distance between PNEUMONIA and AMMONIA is computed with insertion, deletion and substitution each costing 1. What is the minimum…
- Matrices A₁ … A₇ have dimensions 5×12, 12×7, 7×20, 20×4, 4×15, 15×9 and 9×6, i.e. the dimension array p = [5, 12, 7, 20, 4, 15, 9, 6]…
- A recursive matrix-chain function without memoisation, cost(i, j), returns 0 when i = j and otherwise calls cost(i, k) and cost(k+1, j)…
- A 0/1 knapsack has capacity 26 and items (weight, value): (12, 24), (7, 13), (11, 23), (8, 15), (9, 16), (6, 11). The maximum total value…
- A coin system has denominations {1, 5, 10, 20, 25}. The greedy algorithm (always take the largest coin that fits) first gives a…
- For the coin system {1, 5, 12, 25}, among the amounts 1, 2, …, 100, for how many amounts does the greedy algorithm use more coins than the…