FACTOID # 33: Kenyan women work 35% longer than their menfolk.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Longest increasing subsequence problem

The longest increasing subsequence problem is to find the longest increasing subsequence of a given sequence. It also reduces to a graph theory problem of finding the longest path in a directed acyclic graph. In mathematics, a subsequence of some sequence is a new sequence which is formed from the original sequence by deleting some of the elements without disturbing the relative positions of the remaining elements. ... A diagram of a graph with 6 vertices and 7 edges. ... A simple directed acyclic graph In computer science and mathematics, a directed acyclic graph, also called a dag or DAG, is a directed graph with no directed cycles; that is, for any vertex v, there is no nonempty directed path starting and ending on v. ...

Contents


Overview

Formally, the problem is as follows:


Given a sequence a_0,a_1,a_2,ldots,a_n, find the longest subset such that for every i < j, ai < aj.


Techniques

Longest Common Subsequence

A simple way of finding the longest increasing subsequence is to use the longest-common subsequence problem (dynamic programming) algorithm. The longest-common subsequence problem is the search for an efficient method of finding the longest common subsequence (LCS). ... In computer science, dynamic programming is a method for reducing the runtime of algorithms exhibiting the properties of overlapping subproblems and optimal substructure, described below. ...

  1. Make a sorted copy of the sequence A, denoted as B. O(nlg(n)) time.
  2. Use longest-common subsequence problem on with A and B. O(n2) time.

Sorting refers to a process of arranging items in some sequence and/or in different sets, and accordingly, it has two common, yet distinct meanings: ordering: aranging items of the same kind, class, nature, etc. ... The longest-common subsequence problem is the search for an efficient method of finding the longest common subsequence (LCS). ...

Dynamic Programming

There is a straight-forward dynamic programming solution in O(n2) time. Though this is asymptotically equivalent to the longest-common subsequence version of the solution, the constant is lower, as there is less overhead. In computer science, dynamic programming is a method for reducing the runtime of algorithms exhibiting the properties of overlapping subproblems and optimal substructure, described below. ... The longest-common subsequence problem is the search for an efficient method of finding the longest common subsequence (LCS). ...


Given the sequence a_0,a_1,a_2,ldots,a_k, the optimal way to add ak + 1 would simply be the longest of the longest subsequence from ai to ak + 1, adding it to each list if needed. For each ak + 1, there are two possibilities:

  • The number is lower than the last number of the subsequence and greater than the second last. In this case the last number of the subsequence is replaced by the new number.
  • The number is greater than the last number of the subsequence: The number is appended to the subsequence and if this subsequence is the best subsequence with this length, it will be stored.

The pseudo-code is show below:

 func lis( a ) initialize best to an array of 0's. for ( i from 1 to n ) best[i] = 1 for ( j from 1 to i - 1 ) if ( a[i] > a[j] ) best[i] = max( best[i], best[j] + 1 ) return max( best ) 

There's also an O(nlgn) solution based on some observations. Let Ai,j be the smallest possible tail out of all increasing subsequences of length j using elements a_1, a_2, a_3, ldots, a_i.


Observe that, for any particular i, A_{i,1} < A_{i,2} < ldots < A_{i,j}. This suggests that if we want the longest subsequence that ends with ai + 1, we only need to look for a j such that Ai,j < ai + 1 < = Ai,j + 1 and the length will be j + 1.


Notice that in this case, Ai + 1,j + 1 will be equal to ai + 1, and all Ai + 1,k will be equal to Ai,k for k ne j + 1.


Furthermore, there is at most one difference between the set Ai and the set Ai + 1, which is caused by this search.


Since A is always ordered in increasing order, and the operation does not change this ordering, we can do a binary search for every single a_1, a_2, ldots, a_n.


External Links

Algorithmist's Longest Increasing Subsequence - Where this article was taken.



 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.