Skip to content
Official PYQ · 2011

GATE CS 2011 Q25 — Algorithm Design: Dynamic Programming

Explain with AI

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 \leq i \leq n-2

Li={1+Li+1if A[i] < A[i+1]1OtherwiseL_i = \begin{cases} 1+ L_{i+1} & \quad\text{if A[i] < A[i+1]} \\ 1 & \quad\text{Otherwise}\end{cases}

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

Which of the following statements is TRUE?

Choose one option
View worked solution

Answer: A

To determine the correct paradigm, let's analyze the given recurrence relation and algorithm:

  1. Subproblem Definition: Let LiL_i be the length of the longest monotonically increasing sequence starting at index ii.
  2. Overlapping Subproblems & Optimal Substructure: The value of LiL_i directly depends on the already computed value of Li+1L_{i+1}: 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} This demonstrates optimal substructure (the optimal solution to a larger problem incorporates the optimal solution to a smaller subproblem) and overlapping subproblems.
  3. Computation: We compute the values of LiL_i from right to left (starting from i=n−2i = n-2 down to 00) and store them in an array LL. This bottom-up tabulation is the hallmark of the Dynamic Programming paradigm.

Complexity Analysis:

  • The algorithm performs a single pass from n−2n-2 down to 00.
  • At each step ii, it does a constant number of operations (O(1)O(1)).
  • Thus, the time complexity is Θ(n)\Theta(n), which is linear.

Evaluating the Options:

  • Option A: Correct. The algorithm uses the dynamic programming paradigm.
  • Options B & C: Incorrect. Branch and bound is typically used for optimization problems in search spaces (like TSP or Knapsack) using a state-space tree, which is not the case here.
  • Option D: Incorrect. Divide and conquer divides the problem into independent subproblems (like Merge Sort), whereas here the subproblems are overlapping and solved sequentially.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Dynamic Programming questions