Data Structures & AlgorithmsHardGATE CS
For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- A. 3 and 7
- B. 7 and 7
- C. 3 and 3
- D. 3 and 8
Correct answer: A. 3 and 7
The substring must be contiguous (expand around centres: 3); the subsequence may skip letters and equals LCS(s, reverse(s)) = 7.
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
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many…
- The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (2) has one negative edge but no negative cycle…
- Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19)…
- How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–6, 8–3, 9–7, 10–8. What is the size of a minimum DOMINATING set (every vertex…