Open In App

Algorithms | Dynamic Programming | Question 3

Like Article
Like
Save
Share
Report

An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array A[0 :n-1] is given below. Let Li denote the length of the longest monotonically increasing sequence starting at index i in the array. 
 

Equation

Which of the following statements is TRUE?

(A)

The algorithm uses dynamic programming paradigm

(B)

The algorithm has a linear complexity and uses branch and bound paradigm

(C)

The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm

(D)

The algorithm uses divide and conquer paradigm.



Answer: (A)

Explanation:

The algorithm uses a dynamic programming paradigm. Dynamic programming is a technique for solving problems by breaking them down into smaller subproblems and using the solutions to the subproblems to solve the original problem. In this case, the algorithm breaks down the problem of finding the longest monotonically increasing sequence into subproblems of finding the longest monotonically increasing sequence starting at each index in the array. The algorithm then uses the solutions to these subproblems to find the solution to the original problem.

Here is the mathematical explanation:

Let L[i] denote the length of the longest monotonically increasing sequence starting at index i in the array A[0:n – 1]. Then, the algorithm can be written as follows:

L[n – 1] = 1

for i in range(n – 2, -1, -1):

L[i] = 1 if A[i] >= A[i + 1] else 1 + L[i + 1]

Hence Option(A) is correct.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 19 Nov, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads