Data Structures & AlgorithmsModerateProduct-company MCQ pattern
What is the length of the longest strictly increasing subsequence of [3, 10, 2, 1, 20, 4, 6, 7]?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: A. 4
For example 3, 4, 6, 7 (or 2, 4, 6, 7, or 1, 4, 6, 7), length 4. Taking 3, 10, 20 (length 3) shows why a greedy 'jump to the next bigger value' fails.
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
- AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?
- What is the minimum number of nodes in an AVL tree of height 4 (a single node has height 0)?
- How many different spanning trees does the complete graph K₄ have?
- How many times in total is fib called (including the first call) when fib(6) is evaluated? c int fib(int n) { if (n <= 1) return n; return…
- What does fun(3) print? c void fun(int n) { if (n > 0) { fun(n - 1); printf("%d ", n); fun(n - 1); } }
- What are the time complexities of versions P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2) + n; } int Q(int n) { if…