UGC-NET Sep 2013 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0016

The time complexity of an efficient algorithm to find the longest monotonically increasing subsequence of n numbers is
  1. A
    $\text{O(n)}$
  2. B
    $\text{O(n Ig n)}$
  3. C
    $\text{O(n$^2$)}$
  4. D
    None of the above

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionThe efficient method keeps an array \(\text{tail}[k]\): the smallest possible last element of an increasing subsequence of length \(k\). This array stays sorted. For each of the \(n\) numbers, binary search finds the first entry \(\ge\) it and replaces that entry (or appends).\[n\ \text{elements}\times O(\lg n)\ \text{binary search}=O(n\lg n).\]The plain dynamic program is \(O(n^2)\), so it is not the efficient one.Answer: B

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com