in reply to Items in Order

Hi,
I appreciate the responses and making my question more clear, as needed from the assumption in the responses made. All the data I have provided is correct, requires a bit clarification though.
Ordered Array: (1,2,3,8,4,5,6)
I know that 8 is there in the middle and it is correct. It is just a sample of some items which are represented by let's say symbols (here integer numbers) and the provided is let's say the current order of items arrangements.
Given Array: (2,1,4,3,5) 
Looking at the common maximum length 'ordered subsets' of both the array.
(2,3,5)
(1,3,5)  
(2,4,5)  
(1,4,5)
Thus maximum length subset I can find here is '3' and above 4 are such subsets.
I am looking for answer such as length '3' and above found subsets. '3' is part of the answer here and not the input.
Other Subsets could be:
(1,2,3,8,5)
(1,2,8,4,6)
etc.. But it's not part of the given array.
Other sets such as
(1,4)
(8,6)
(2,3)
Are there and is also part of the given array but small in length (2) compared to what we found earlier.
It's really not an attempt to find the max length of increasing integers slice as answered. (Thanks for the attention)
I hope it makes sense now.

Thanks,
Artist

Replies are listed 'Best First'.
(tye)Re2: Items in Order
by tye (Sage) on Dec 11, 2002 at 23:35 UTC

    This returns all maximal ordered subsets:

    sub MaxOrderedSubList { my @order= @{ shift @_ }; my %order; @order{@order}= 0..$#order; my @list= @{ shift @_ }; my @wins= ( [] ); my @idx= ( -1 ); my $i= 0; while( 1 ) { do { ++$idx[$i]; if( $#list < $idx[$i] ) { if( --$i < 0 ) { return @wins; } redo; } } while( 0 < $i && $order{$list[$idx[$i]]} <= $order{$list[$idx[$i-1]]} ); if( $#{$wins[0]} <= $i ) { @wins= () if $#{$wins[0]} < $i; push @wins, [ @list[@idx[0..$i]] ]; } $idx[$i+1]= $idx[$i]; ++$i; } } for my $win ( MaxOrderedSubList( [1,2,3,8,4,5,6], [2,1,3,5,4] ) ) { print "@$win\n"; } for my $win ( MaxOrderedSubList( [qw( t h i s w o r k a )], [qw( w h a t i s o k )] ) ) { print "@$win\n"; }
    Output:
    2 3 5 2 3 4 1 3 5 1 3 4 h i s o k t i s o k
    The maximum size for ordered subsets would be 0 + @{( MaxOrderedSubList( [...], [...] ) )[0]} (updated)

            - tye