Data Structures & AlgorithmsHardGATE CS · Product-company placement
What is the length of the longest common subsequence of ONTOLOGY and TOPOLOGY, and how many DISTINCT longest common subsequences (as strings) are there?
- A. Length 6, 1 distinct
- B. Length 6, 2 distinct
- C. Length 7, 2 distinct
- D. Length 6, 3 distinct
Correct answer: B. Length 6, 2 distinct
The LCS table gives length 6; following every tie in the table and keeping distinct strings yields OOLOGY, TOLOGY.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Edit distance between MARTIAN and COMPILER where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Dijkstra's algorithm runs from A on the directed graph A→C (4), B→A (1), B→F (6), C→B (7), C→E (12), C→F (6), D→C (3), E→A (15), E→B (3)…
- The weighted undirected graph A–B (27), A–D (3), A–E (1), B–C (25), B–D (8), B–E (18), B–F (5), C–E (9) has a unique MST. What is the…
- A simple undirected graph has 13 vertices and exactly 4 connected components. What is the maximum possible number of edges?
- What is the length of the shortest string that has BOTH COMPILER and SHORTEST as subsequences (shortest common supersequence)?
- Prim's algorithm starts at G on the weighted undirected graph A–B (19), A–F (12), A–G (21), B–C (13), B–D (23), B–E (6), B–G (29), D–E…