GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The O(n log n) LIS algorithm keeps an array t where t[k] is the smallest tail of an increasing subsequence of length k + 1; each element x replaces the first t[k] ≥ x or is appended. After processing [2, 5, 3, 7, 11, 8, 10, 13, 6, 9, 4, 12], what is t?

  1. A. [2, 3, 7, 8, 10, 13]
  2. B. [2, 3, 4, 6, 9, 12]
  3. C. [2, 5, 7, 8, 10, 12]
  4. D. [2, 3, 4, 8, 9, 12]

Correct answer: D. [2, 3, 4, 8, 9, 12]

Tracing the replacements: after 13 the array is [2, 3, 7, 8, 10, 13]; 6 → [2, 3, 6, 8, 10, 13]; 9 → [2, 3, 6, 8, 9, 13]; 4 → [2, 3, 4, 8, 9, 13]; 12 → [2, 3, 4, 8, 9, 12]. The first distractor is a genuine LIS, but t holds the smallest tails and need not itself be a subsequence of the input.

More Algorithms questions

Exams that ask this topic