Question

An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array A[0:n−1]A[0:n-1] is given below.

Let LiL_i denote the length of the longest monotonically increasing sequence starting at index ii in the array.

Initialize Ln−1=1L_{n-1} = 1.

For all ii such that 0≤i≤n−20 \le i \le n-2:

Li={1+Li+1if A[i]<A[i+1]1otherwiseL_i = \begin{cases} 1 + L_{i+1} & \text{if } A[i] < A[i+1] \\ 1 & \text{otherwise} \end{cases}

Finally the length of the longest monotonically increasing sequence is max⁡(L0,L1,…,Ln−1)\max(L_0, L_1, \dots, L_{n-1}).

Which of the following statements is TRUE?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2011 answer key

Solution

Classify the given recurrence and memoization scheme among algorithm design paradigms.

  1. The algorithm computes optimal solutions to subproblems LiL_i (the length of the longest increasing sequence starting at index ii) using the recurrence:
Li=1+Li+1if A[i]<A[i+1],else 1L_i = 1 + L_{i+1} \quad \text{if } A[i] < A[i+1], \quad \text{else } 1
  1. The subproblems exhibit optimal substructure and overlapping subproblems: the solution for LiL_i depends directly on the already-computed value of Li+1L_{i+1}.
  1. The algorithm evaluates subproblems in reverse order (from index n−2n-2 down to 0) and stores the intermediate results in a table LL, which is the classic bottom-up dynamic programming paradigm.
Final answer

A

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
25 of 65, printed as CS Q.25
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.