Data Structures & AlgorithmsHardProduct-company placement
What is the length of the longest common subsequence of MATRIX and MARTIAN, and how many DISTINCT longest common subsequences (as strings) are there?
- A. Length 4, 1 distinct
- B. Length 5, 2 distinct
- C. Length 4, 3 distinct
- D. Length 4, 2 distinct
Correct answer: D. Length 4, 2 distinct
The LCS table gives length 4; following every tie in the table and keeping distinct strings yields MARI, MATI.
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
- Lectures occupy half-open intervals [start, end): [3, 10), [6, 10), [7, 12), [9, 11), [10, 15), [10, 17), [10, 18), [20, 25). A lecture…
- A binary max-heap is stored in a 0-indexed array [57, 47, 54, 14, 15, 6, 21]. Perform, in order: delete-max, insert 10, delete-max, insert…
- Keys 13, 30, 35, 39, 54 are searched with frequencies 8, 1, 9, 9, 12 respectively (only successful searches). The cost of a BST is Σ…
- A min-heap holds 63 distinct keys in a 0-indexed array (a full tree with 6 levels). At how many different indices can the 5th-smallest key…
- Keys 20, 94, 97, 28, 21, 78, 37, 93, 79, 36 are inserted into an empty AVL tree (giving preorder 78, 28, 21, 20, 37, 36, 93, 79, 94, 97)…
- Dijkstra's algorithm runs from A on the directed graph A→B (14), A→C (11), A→D (8), A→E (1), A→F (15), B→C (6), B→E (2), B→F (5), C→D (9)…