Data Structures & AlgorithmsHardGATE CS
What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [12, 2, 25, 6, 15, 16, 21, 10, 3]?
- A. 8
- B. 7
- C. 4
- D. 3
Correct answer: B. 7
max(inc[i] + dec[i] − 1) = 7, e.g. 2, 6, 15, 16, 21, 10, 3 peaking at 21. Forgetting the −1 counts the peak twice (8), 4 is the decreasing tail from the maximum 25, and 3 is the longest decreasing contiguous run (21, 10, 3).
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
- DFS on the directed graph with adjacency lists A: –; B: ACF; C: FG; D: E; E: BC; F: A; G: A starts at A (scanning lists in the order…
- All suffixes of the string 'radar' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–2, 5–3, 6–3, 7–6, 8–6, 9–6. What are its diameter and radius, and which vertex/vertices form…
- A binary search tree holds exactly the keys 20, 26, 28, 45, 49, 87, 91, 92. Which ONE of the following sequences can be its PREORDER…
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–3, 7–5, 8–7, 9–8, 10–6. What is the size of a minimum DOMINATING set (every vertex…
- Keys 90, 39, 48, 71, 49, 22, 33, 44, 15 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?