GATE Computer ScienceVery hardGATE CS (PYQ pattern)
X = ABCBDAB and Y = BDCABA have longest common subsequences of length 4. How many DIFFERENT strings are shortest common supersequences of X and Y (strings of minimum length that contain both X and Y as subsequences)?
- A. 1
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
Any SCS has length |X| + |Y| − LCS = 7 + 6 − 4 = 9. Enumerating with the DP (keep both branches on ties, collect the strings into a set) gives exactly 3 distinct length-9 supersequences; several LCS alignments lead to the same string, so counting LCSs or DP paths overcounts.
More Algorithms questions
- The fractional knapsack greedy algorithm (taking items by value/weight ratio, the last one fractionally) is run on capacity 26 and items…
- Dijkstra's algorithm (never re-inserting or re-opening a vertex once it has been extracted) is run from S on a directed graph with edges…
- Dijkstra's algorithm with a binary min-heap (lazy insertion is not used: a decrease-key is performed whenever an edge improves the label…
- In the undirected weighted graph with edges SA 1, SB 1, SC 2, AD 2, BD 2, CD 1, AE 3, BE 3, CE 2, DT 2, ET 1 and AB 1, how many distinct…
- Bellman–Ford is run from A on a 6-vertex graph with directed edges relaxed in this fixed order in every pass: E→F 2, D→E 3, C→D 2, B→C 4…
- A weighted undirected graph has vertices A–F and edges AB 1, BC 1, CA 1, CD 2, DE 2, EC 2, EF 3, FD 3, AF 7. How many distinct minimum…