Problem statement: Our aim here is to find out longest increasing subsequence from the given sequence/array of integers. Note that the increasing subsequence need not to be continuous. Let’s trace below scenario, If the original sequence is {15, 27, 14, 38, 26, 55, 46, 65, 85} then, possible increasing subsequence would be, Original Sequence. (Input) Increasing Subsequence. (output) Length 1. {15, 27, 14, 38, 26, 55, 46, 65, 85} {15, 27, 38, 55, 65, 85} 6. 2. {15, 27, 14, 38, 26, 55, 46, 65, 85} {14, 26, 46, 65, 85} 5. Approach: We can solve this problem using dynamic programming. I’m going to create two arrays. One to store reference of previous element(arr1), another will store temporary sequence of increasing elements(arr2). Case-I. Append current element to the subsequence only if the previous element is smaller than the current one. (Note: Current element is the element at the i th ...
Comments
Post a Comment