Data Structures & AlgorithmsHardGATE CS · ICPC regional

Which algorithm computes the length of the longest increasing subsequence in O(n log n) time?

  1. A. Floyd-Warshall on the index graph
  2. B. Kruskal's minimum spanning tree
  3. C. Naive pairwise DP over all subsequences
  4. D. Patience sorting with binary search on the tails array

Correct answer: D. Patience sorting with binary search on the tails array

Maintain the smallest possible tail for each length and binary-search where a new value goes; the tails array's length is the LIS length.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic