0

Problem is to find LIS(Longest Increasing Subsequence) of any given array. Ex. a[]={10,9,7,8,9}; length=3; {7,8,9}

So one way of doing in nlogn is

  1. Sort the array
  2. Take LCS of the the two Resulting is LIS.

Now I understood how to do it. But how do I prove it is correct. How to apply MI here?

Jongware
  • 22,200
  • 8
  • 54
  • 100
sandy
  • 509
  • 1
  • 6
  • 23

1 Answers1

0

In your case there is no need for induction, you have to show three things:

  • resulting method captures increasing sequence - comes directly from the fact that it is a part of sorted array
  • resulting subsequence exists in the input array - comes directly from the definition of LCS (common subsequence)
  • there is no longer increasing subsequence - you can easily show that the longest sequence has to be present in both input sequence (by definition) and in sorted array, so it would be also analyzed by LCS, thus it cannot be longer then the one returned by LCS.
lejlot
  • 64,777
  • 8
  • 131
  • 164
  • Are you absolutely sure this is correct? From what I remember, the LIS problem is solvable in O(nlog(n)) and also I don't think your solution gives to correct answer for the array {10,9,4,5,8,6,7} - the answer is {4,5,6,7} but yours would find {4,5,8}, which is the wrong length. You're not supposed to search for an increasing block, but for a subsequence of elements, not necessarily next to each other. See example on the wiki: https://en.wikipedia.org/wiki/Longest_increasing_subsequence – Piotr Pytlik Nov 29 '15 at 13:39
  • This finds the longest increasing contuguous subsequence, which is quite a bit simpler than finding the longest increasing subsequence. – n. m. could be an AI Nov 29 '15 at 13:47
  • @n.m. I agree it finds the longest increasing contiguous subsequence, but that isn't the LIS problem. And yes, it's quite a bit simpler, but still a different question, perhaps the question itself should be changed to LICS instead of LIS, because from the question i'm guessing that was the intention – Piotr Pytlik Nov 29 '15 at 13:50
  • @PiotrPytlik no, if you change the question this way it would become incorrect (that is, would ask to prove a falsehood). – n. m. could be an AI Nov 29 '15 at 13:53
  • @PiotrPytlik my intention is to find LIS only, not LICS. – sandy Nov 29 '15 at 13:56
  • I was a bit hooked because of the code that @lejlot presented. This answer is correct for LIS. I made an incorrect assumption because of an incomplete example in the question (which would return the same answer for LIS and LICS). Sorry for the discussion. – Piotr Pytlik Nov 29 '15 at 14:23