In computer science, the longest increasing subsequence problem aims to find a subsequence of a given sequence in which the subsequence's elements are sorted in an ascending order and in which the subsequence is as long as possible. This subsequence is not necessarily contiguous or unique. The longest increasing subsequences are studied in the context of various disciplines related to mathematics, including algorithmics, random matrix theory, representation theory, and physics. The longest increasing subsequence problem is solvable in time O ( n log n ) , {\displaystyle O(n\log n),} where n {\displaystyle n} denotes the length of the input sequence.
Example In the first 16 terms of the binary Van der Corput sequence
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 one of the longest increasing subsequences is
0, 2, 6, 9, 11, 15. This subsequence has length six; the input sequence has no seven-member increasing subsequences. The longest increasing subsequence in this example is not the only solution: for instance,
0, 4, 6, 9, 11, 15 0, 2, 6, 9, 13, 15 0, 4, 6, 9, 13, 15 are other increasing subsequences of equal length in the same input sequence.
Relations to other algorithmic problems The longest increasing subsequence problem is closely related to the longest common subsequence problem, which has a quadratic time dynamic programming solution: the longest increasing subsequence of a sequence S {\displaystyle S} is the longest common subsequence of S {\displaystyle S} and T , {\displaystyle T,} where T {\displaystyle T} is the result of sorting S . {\displaystyle S.} However, for the special case in which the input is a permutation of the integers 1 , 2 , … , n , {\displaystyle 1,2,\ldots ,n,} this approach can be made much more efficient, leading to time bounds of the form O ( n log log n ) . {\displaystyle O(n\log \log n).}
The largest clique in a permutation graph corresponds to the longest decreasing subsequence of the permutation that defines the graph (assuming the original non-permuted sequence is sorted from lowest value to highest). Similarly, the maximum independent set in a permutation graph corresponds to the longest non-decreasing subsequence. Therefore, longest increasing subsequence algorithms can be used to solve the clique problem efficiently in permutation graphs. In the Robinson–Schensted correspondence between permutations and Young tableaux, the length of the first row of the tableau corresponding to a permutation equals the length of the longest increasing subsequence of the permutation, and the length of the first column equals the length of the longest decreasing subsequence.
Efficient algorithms The algorithm outlined below solves the longest increasing subsequence problem efficiently with arrays and binary searching. It processes the sequence elements in order, maintaining the longest increasing subsequence found so far. Denote the sequence values as X [ 0 ] , X [ 1 ] , … , {\displaystyle X[0],X[1],\ldots ,} etc. Then, after processing X [ i ] , {\displaystyle X[i],} the algorithm will have stored an integer L {\displaystyle L} and values in two arrays:
L {\displaystyle L} — stores the length of the longest increasing subsequence found so far.
… excerpt ends here. Continue reading the full article.

