# Thread: finding the largest ascending subsequence..

1. ## finding the largest ascending subsequence..

write a function called
int max_set(int arr[], int size, …………)
which gets an array of integers
and returns the length of the longest ascending subsequence.
you cant use loops or external functions.
you can add arguments to the signature.

for example:
for this array
arr = 45 1 21 3 33 6 53 9 18
we can have these subsequences.

45 53
1 21 33 53
1 3 33 53
1 3 6 53
1 3 6 9 18
1 33 53
1 6 53
1 6 9 18
1 53
1 9 18
1 18
21 33 53
…….
but the longest is
1 3 6 9 18
so it needs to return 5

i dont know what the algorithm here
i dont know where to start
??

2. any ideas??

3. Where to start would be to figure out the algorithm.

4. I dont know what is the algorithm here.

??

5. So think about it until you figure it out. Can you figure out how to find ascending subsequences? Do you know how to count numbers?

6. yep
i need to look for numbers bigger then the current one

but its a long way till translating into a recursion

7. Turn off your computer, get some paper and a pen and play with some examples until you find a method to solve the problem for any sequence without 'thinking'. Write down this method with words, the translation to a function will be a piece of cake.

8. i wrote this code that finds the number of members in the ascending sub sequence of the first cell(arr[0]).

and in that way i could find out the number of objects in every subsequence for evey cell

but i dont know how to compare each one of the results to find the biggest isnide this function.
??

i am allowed to enter parameters to the signature
Code:
```#include <stdio.h>
int max_set(int arr[], int size,int index,int bef);
int main()
{
int array[7] = {9, 1, 3,0,7,10,11};

printf("%d\n",max_set(array,7,0,array[0]));  //number of cells for ascending series of cell 0
return 0;
}

int max_set(int arr[], int size,int index,int bef)
{
int temp,bigger;
if (index==size)
{
return 1;
}
if (arr[index]>bef)
{
return 1+max_set(arr,size,index+1,arr[index]);
}
else
{
return max_set(arr,size,index+1,bef);
}

}//end of function```

9. You don't know how to compare numbers? I usually use "<" and ">" myself.

10. i dont know how to collect them
and compare each one of the results
to determine the biggest
within this recursive function
??

i can add variables to the signature

11. So you'll need to find the subsequences starting in every cell. You will reasonably necessarily need an array for that.

12. and how to do that inside a recurtsion

the recursion itself is built to return only one result for one cell

13. i think i shouldnt use array but an int variable
and i will compare each result for the previus cell
with the current one
and store the biggest on this variable

but i dont know how to do that

14. Originally Posted by transgalactic2
i think i shouldnt use array but an int variable
and i will compare each result for the previus cell
with the current one
and store the biggest on this variable

but i dont know how to do that
If you don't know how to do that, how do you write the previous four lines of the post (which is "how to do that")?

15. but its a plan
i dont have any idea of how to implement it
??