Data Structure Multiple Choice Questions on “Longest Increasing Subsequence”.
1. The longest increasing subsequence problem is a problem to find the length of a subsequence from a sequence of array elements such that the subsequence is sorted in increasing order and it’s length is maximum. This problem can be solved using __________ Answer: d 2. Find the longest increasing subsequence for the given sequence: Answer: d 3. Find the length of the longest increasing subsequence for the given sequence: Answer: d 4. For any given sequence, there will ALWAYS be a unique increasing subsequence with the longest length. Answer: b 5. The number of increasing subsequences with the longest length for the given sequence are: Answer: d 6. In the brute force implementation to find the longest increasing subsequence, all the subsequences of a given sequence are found. All the increasing subsequences are then selected and the length of the longest subsequence is found. What is the time complexity of this brute force implementation? Answer: d 7. Complete the following dynamic programming implementation of the longest increasing subsequence problem: a) tmp_max = LIS[j] Answer: a 8. What is the time complexity of the following dynamic programming implementation used to find the length of the longest increasing subsequence? a) O(1) Answer: c 9. What is the space complexity of the following dynamic programming implementation used to find the length of the longest increasing subsequence? a) O(1) Answer: b 10. What is the output of the following program? a) 3 11. What is the value stored in LIS[5] after the following program is executed? a) 2 Answer: c
a) Recursion
b) Dynamic programming
c) Brute force
d) Recursion, Dynamic programming, Brute force
Clarification: The longest increasing subsequence problem can be solved using all of the mentioned methods.
{10, -10, 12, 9, 10, 15, 13, 14}
a) {10, 12, 15}
b) {10, 12, 13, 14}
c) {-10, 12, 13, 14}
d) {-10, 9, 10, 13, 14}
Clarification: The longest increasing subsequence is {-10, 9, 10, 13, 14}.
{-10, 24, -9, 35, -21, 55, -41, 76, 84}
a) 5
b) 4
c) 3
d) 6
View Answer
Clarification: The longest increasing subsequence is {-10, 24, 35, 55, 76, 84} and it’s length is 6.
a) True
b) False
Clarification: For a given sequence, it is possible that there is more than one subsequence with the longest length.
Consider, the following sequence: {10,11,12,1,2,3}:
There are two longest increasing subsequences: {1,2,3} and {10,11,12}.
{10, 9, 8, 7, 6, 5}
a) 3
b) 4
c) 5
d) 6
Clarification: Each array element individually forms a longest increasing subsequence and so, the length of the longest increasing subsequence is 1. So, the number of increasing subsequences with the longest length is 6.
a) O(n)
b) O(n2)
c) O(n!)
d) O(2n)
Clarification: The time required to find all the subsequences of a given sequence is 2n, where ‘n’ is the number of elements in the sequence. So, the time complexity is O(2n).#include
b) LIS[i] = LIS[j]
c) LIS[j] = tmp_max
d) tmp_max = LIS[i]
Clarification: tmp_max is used to store the maximum length of an increasing subsequence for any ‘j’ such that: arr[j] < arr[i] and 0 < j < i.
So, tmp_max = LIS[j] completes the code.#include
b) O(n)
c) O(n2)
d) O(nlogn)
Clarification: The time complexity of the above dynamic programming implementation used to find the length of the longest increasing subsequence is O(n2).#include
b) O(n)
c) O(n2)
d) O(nlogn)
Clarification: The above dynamic programming implementation uses space equal to the length of the sequence. So, the space complexity of the above dynamic programming implementation used to find the length of the longest increasing subsequence is O(n).#include
b) 4
c) 5
d) 6
Answer: d
Clarification: The program prints the length of the longest increasing subsequence, which is 6.#include
b) 3
c) 4
d) 5
Clarification: The value stored in LIS[5] after the program is executed is 4.