Re: [algogeeks] zig zag problem

2011-12-19 Thread atul anand
@Ankur : yeah rite it wont work i have modified my algo and used many test cases , it is giving rite output. could you catch any test case for which it would fail. here is the updated code :- #includestdio.h int findSeqLen(int arr[],int len,int subseq) { int i=0,flag1,flag2,toggle; int

Re: [algogeeks] zig zag problem

2011-12-19 Thread atul anand
@UTKARSH : it should be 1 4 3 7 6 why are you skipping 3 even when 143 is in zig zag sequence. On Tue, Dec 20, 2011 at 11:26 AM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: hi i want to know whether this is right suppose array is : 1,4,3,2,7,8,6,2 we just find where sign changes and

Re: [algogeeks] zig zag problem

2011-12-18 Thread atul anand
complexity of this algo is O(n) ..I guess it is better than dynamic programming approach which is O(n^2). On Sat, Dec 17, 2011 at 6:28 PM, atul anand atul.87fri...@gmail.com wrote: please see the algo and let me know if i am doing it wrong:- toggle= arr[i+1] arr[i]; subseq=0; for( i=0 ;

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
a linear solution for this problem . although its more than O(n) but will never be O(n*2)..used DP to solve it space used -O(2n) int ZigZagLength(vectorint a){ int n=a.size(); int DP[n][2]; DP[0][0]=1; DP[0][1]=0; DP[1][0]=2; DP[1][1]=0; int j; for(int i=2;in;i++){

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
@Atul ur solution is wrong It seems u r comparing just the neighbouring elements . The question is not to find the contiguous zig-zag sequence but longest subsequence Also even in case of contiguous sequence ur solution will not print the correct length like for 6 7 4 ur solution will print answer

Re: [algogeeks] zig zag problem

2011-12-17 Thread atul anand
please see the algo and let me know if i am doing it wrong:- toggle= arr[i+1] arr[i]; subseq=0; for( i=0 ; ilen ;i++) { if ( toggle == 1) { if( arr[i+1] arr[i]) { subseq=subseq+2; }

[algogeeks] zig zag problem

2011-12-15 Thread Sangeeta
Problem Statement A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a

Re: [algogeeks] zig zag problem

2011-12-15 Thread Azhar Hussain
It is dynamic programming. Search in topcoder algo tutorials On Dec 16, 2011 10:33 AM, Sangeeta sangeeta15...@gmail.com wrote: Problem Statement A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative.

[algogeeks] zig zag

2011-10-02 Thread Anika Jain
only possible for continuous disctees attributes. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Zig Zag tree traversal

2011-08-28 Thread Navneet Gupta
Print tree in zig zag manner 1 / \ 23 / \ / \ 4 56 7 O/P: 1 3 2 4 5 6 7 -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Zig Zag tree traversal

2011-08-28 Thread Yuchen Liao
You can use two stacks(A, B) when traversal. Use A as the stack when traveling the odd levels. B as the even levels. A.push(1); A.pop(); //1 //push the son of the node 1, from left to right; B.push(2); B.push(3); B.pop(); // 3 //push the son of the node 3, from right to left A.push(7);

Re: [algogeeks] Zig Zag tree traversal

2011-08-28 Thread KARTHIKEYAN V.B.
use one queue Enqueue all the nodes in normal level order traversal in the queue as 1 2 3 4 5 6 7 Each level contains 2 to the power n nodes in the queue. have two pointers ptr1 and ptr2 point ptr1 to the start node of 2 power n nodes range and ptr2 to the last node of this range. For odd

Re: [algogeeks] zig zag

2011-01-21 Thread nishaanth
How about this dp solution? Let dp[i][j][k] be the lookup table. It is defined as the longest zigzag sequence in the range i and j. k is either 0 or 1. 0- if the sequence ends with a positive difference, i.e last element is greater than the last to one. 1- if the sequence ends with a negative

[algogeeks] zig zag

2011-01-20 Thread snehal jain
A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a zig-zag sequence. For

Re: [algogeeks] zig zag

2011-01-20 Thread radha krishnan
See Topcoder Dynamic Programming Tutorials :) On Fri, Jan 21, 2011 at 12:48 PM, snehal jain learner@gmail.com wrote: A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if

[algogeeks] Zig-zag subsequence

2009-04-09 Thread Vladimir Reshetnikov
Please help me to write the following algorithm: Call a sequence of integers a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative (for example, 5, 7,3,9,-1,4,3,6,0). The first difference may be either positive or negative. Given a