This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: L ( k ) = max( { 1 + L ( j ) : k + 1 ≤ j ≤ n,x j > x k } ∪ { 1 } ). If the maximum is achieved by 1 + L ( j ) for some j , save that value of j in S ( k ). If the maximum is 1, set S ( k ) to nil . Computing L ( k ) and S ( k ) for each k requires ﬁnding the maximum of at most nk + 2 elements, which can be done in time proportional to nk + 2. So ﬁlling in the L and S arrays takes O ( ∑ n1 k =1 nk + 3) = O ( n 2 ) time. To actually produce the longest increasing subsequence, we use the following recursive procedure. 1 printSequence(k) // prints longest increasing subsequence of [x_k,. ..,x_m] that starts at x_k print x_k if S(k) != nil then printSequence(S(k)) end printSequence The answer is obtained by calling printSequence(k) , where k is the index of the largest element of array L . This call requires O ( n ) time. 2...
View
Full
Document
This note was uploaded on 02/04/2010 for the course COMPUTER S cs300 taught by Professor Unkown during the Spring '08 term at Korea Advanced Institute of Science and Technology.
 Spring '08
 Unkown
 Algorithms

Click to edit the document details