Question: 5. In this modified version of the longest increasing subsequence algorithm, we use D[i] to store the length of the longest increasing subsequence beginning with

5. In this modified version of the longest increasing subsequence algorithm, we use D[i] to store the length of the longest increasing subsequence beginning with A[i]. Will the algorithm find the length of the longest increasing subsequence correctly? LONGEST-SUBSEQUENCE (A) n = A.length Let D[1..n] be a new array D[n] = 1 for i = n - 1 downto 1 D[i] = 1 for j = i + 1 ton if A[i] D[i] D[i] = D[j] + 1 Print D[i] L = 0 for i = 1 ton if D[i] >L L = D[i] Print L For the following array: A[1] = 7, A[2] = 18, A[3] = 11, A[4] = 4, A[5] = 12, what will be the output of the algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
