0

I am trying to figure out how to get the sub-sequences of

    {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};

I managed to find examples on how to get the length of a longest increasing sub-sequence. I have been trying to adapt the code to get which values actually make up the length.

The sequences I need in a array are: [0, 2, 6, 9, 13, 15] or [0, 4, 6, 9, 11, 15] or [0, 4, 6, 9, 13, 15]

My approach:

I pass the array in as a parameter(a), then I create a new array of the same size(s).

s[0] = a[0]; 

Then I used two loops

        for (int i = 1; i < a.length; i++) {
            for (int j = 0; j < i; j++) {

After that I ran a simple comparison:

if (a[j] < a[i])

My logic pretty much ends here because I do not know what else I can do. I do not mind pseudo-code at all.

Kendrick Lamar
  • 781
  • 2
  • 8
  • 18
  • 2
    I don't see any pattern in getting the sub-arrays. – Nikolas Charalambidis Nov 04 '16 at 20:42
  • 1
    There are examples and descriptions of algorithms that find _both_ the length and the actual sequence here: [How to determine the longest increasing subsequence using dynamic programming?](http://stackoverflow.com/q/2631726/6732794). –  Nov 04 '16 at 20:53
  • Well the question from my assignment states that if a[j] is less than any of the elements before it then it could possibly be the start of a new sub-array. – Kendrick Lamar Nov 04 '16 at 20:53

0 Answers0