Data Structures & AlgorithmsModerateProduct-company MCQ pattern
What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?
- A. 5
- B. 4
- C. 2
- D. 7
Correct answer: D. 7
Both words end in RITHM, and before it ALGO and LOGA share two letters in order (L O or L G), so the LCS is 7 (e.g. LORITHM). The longest common substring is only RITHM (5), 4 is the insert/delete distance 18 − 2·7, and 2 is the ALGO/LOGA part alone.
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
- What is the edit distance (insert, delete, replace, each cost 1) between FLASK and FLOSSY?
- In how many ways can 10 be made from coins of 2, 3 and 5 (unlimited supply, order does not matter)?
- 0/1 knapsack, capacity 7. Items (weight, value): (1, 1), (3, 4), (4, 5), (5, 7). What is the maximum total value?
- Matrices A (10 × 20), B (20 × 30) and C (30 × 40) are to be multiplied. What is the minimum number of scalar multiplications?
- What is the length of the longest strictly increasing subsequence of [3, 10, 2, 1, 20, 4, 6, 7]?
- AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?