Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
@srikanth: can u frame out the recursive function for the solution proposed in DP . i was actually finding difficulty in this.. On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel wrote: > #include > > int main() > { >     int Seq[100],i,j,n,Max,tmp; >     int zzlen[100][2]; >     sc

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
#include int main() { int Seq[100],i,j,n,Max,tmp; int zzlen[100][2]; scanf("%d",&n); for(i = 0 ; i < n ; i++) { scanf("%d",&Seq[i]); zzlen[i][0] = 1;zzlen[i][1] = 0;} Max = 1; for(i = 1 ; i < n ; i++) { for(j = i-1 ; j >= 0 ; j--) { if(Seq[i]

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
we should use dp On Fri, Jun 8, 2012 at 5:39 PM, Ratan wrote: > Thats what the question is about to find the maximum subsequence. > i too tried your code with the sample "10,4,12,4,1,43,21,4,1,5,7,23,9" > ur code gave the result "10 12 4 43 21 23"; > but the cor

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
Thats what the question is about to find the maximum subsequence. i too tried your code with the sample "10,4,12,4,1,43,21,4,1,5,7,23,9" ur code gave the result "10 12 4 43 21 23"; but the correct optimized o/p should have been with length 7 as "4,12,1,43,21,23,9"

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ashish Goel
my solution will not provide the largest eg 2,4,6,5 should have largest as 2,6,5 not 2,4.. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel wrote: > O(n) is straight forward > > bool increase = true; > in

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ashish Goel
O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;ia[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to concep

[algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as "if the first number is increasing then the 2nd one should be decreasing or vice versa.. " for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag su