[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@atul.. I missed a question asked by u above. The answer to it as follows: /* bcozz every node should have single child then how should i interpret mid,left,right ?? */ Say the given sequence is 10,19,17,14,15,16, the corresponding BST would be : 10

[algogeeks] Programming Pearls Soft copy

2011-12-30 Thread Ashish Goel
How to get the soft copy of this book? Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 -- 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

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@topcoder.. As pointed u by earlier that 4 ,2, 6 doesn't work for the initial code.. The 1st solution that i gave to resolve it is still faulty.. it will fail for 4 3 2 1.. basically increasing or decreasing set of nos.. // The second and 3rd approach would work fine.. i.e (-INF, +INF) and (small

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@above format got messed up and re-posting.. while ( ++i < N) { if (A[i] <= mid && A[i] > left) { right = mid; mid = A[i]; } else if (A[i] > mid && A[i] <= right) { left = mid; mid = A[i]; } else break; } On 31 Dec, 10:17, Lucifer wrote: > @at

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@atul.. thanks for pointing out the editing mistake.. I have fixed the while loop below: while ( ++i < N){   if (A[i] <= mid && A[i] > left)   {      right = mid; mid = A[i];   }   else if (A[i] > mid && A[i] <= right)   {      left = mid; mid = A[i];   }   else      break;} On 31 D

Re: [algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread atul anand
while ( ++i < N) { if (A[i] <= mid && A[i] > left) { *mid = A[i]; // both mid and right will contain same value** right = mid;* // right=mid; /* i guess this is what you want*/ // mid=A[i] * * } else if (A[i] > mid && A[i] <= right) { *mid = A[i];

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@shady.. Correction.. palindromes are not always of even length.. For ex- abcdcba is a palindrome and not of even length... On 30 Dec, 22:14, shady wrote: > ya, you are right... > btw, palindromes are always of even length so basically it is like finding > the maximum length palindrome from a

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread shady
ya, you are right... btw, palindromes are always of even length so basically it is like finding the maximum length palindrome from a string such that it is a substring(continuous in nature) On Fri, Dec 30, 2011 at 10:15 PM, atul anand wrote: > @shady :- > > correction:- > input

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
@shady :- correction:- input output aaggaa aaggaa On Fri, Dec 30, 2011 at 9:57 PM, shady wrote: > lucifier question is to find an even length substring which is a > palindrome, and your algorithm is correct, i didn't go into implementation > deta

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
yup its working fine... i coded for finding first even length palindrome found...but was searching for longest even length palindrome found. my bad!... its working :) :) sorry... On Fri, Dec 30, 2011 at 9:57 PM, shady wrote: > lucifier question is to find an even length substring which is a > p

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread shady
lucifier question is to find an even length substring which is a palindrome, and your algorithm is correct, i didn't go into implementation details input output aabbaaaabbaa aaaggaaa aaaggaaa aa

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@editing mistake above.. ur just trying to find an even palindrome and *not longest one On 30 Dec, 21:21, Lucifer wrote: > @atul.. > > R u trying. to find the longest even palindrome or just an even > palindrome ? > > If ur looking for the longest even palindrome then it be and the > size r

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@atul.. R u trying. to find the longest even palindrome or just an even palindrome ? If ur looking for the longest even palindrome then it be and the size returned would be 4. If ur looking for just an even palindrome and want break out as per my comments given then it will be "bb" and size

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@atul, I don't have a break condition.. Can u be more specific.. On 30 Dec, 21:07, atul anand wrote: > @Lucifier : > > your 1st approach fails for the following cases:- > > ** > *aa*bb*aa* > *aaa*gg*aaa* > > etc > > basically for cases where the 1st two and last two character of the even

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
@Lucifier : your 1st approach fails for the following cases:- ** *aa*bb*aa* *aaa*gg*aaa* etc basically for cases where the 1st two and last two character of the even palindrome are same. for eg:- 1 2 3 4 -- b b b b 1st iteration :- X = 1 1 1 1 2nd iteration :- X= 1 1 1 2

[algogeeks] Re: Kth element of the Increasing Sequence

2011-12-30 Thread Lucifer
@All.. By quadratic did u mean K*N worst case ?... basically its K*(size of int generated)...? On 21 Dec, 22:52, SAMMM wrote: > Yes Quadratic approach will be naive . I thought initially to take the > input from the Liveware , and do the below :- > > And we will computer for the number of unique

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
@praveen : question is to find longest even length pallindrome. there was some misunderstanding earlier. so if input is output string is = check lucifier post above. we discussed another question in the same post bcoz of initial misunderstanding :- Q) Given a string of length N, find

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread praveen raj
The Question is: whther there exist a even length pallindrome or not since for even ... the two consecutive character will be equal... so find two character which are equal.. consecutively.. PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- You received this message because you are subscrib

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@atul Yup.. Thanks .. :) On 30 Dec, 19:41, atul anand wrote: > very minute error in lucifier 1st approach , i guess you all have noticed > it... > > while ( pRev > 0) > { >  for ( pStrt = N; pStrt >=1 ; *--i*) >  { > > // *do  --pStrt instead of --i* -- You received this message because you ar

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
very minute error in lucifier 1st approach , i guess you all have noticed it... while ( pRev > 0) { for ( pStrt = N; pStrt >=1 ; *--i*) { // *do --pStrt instead of --i* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this grou

[algogeeks] Re: Find even length palindrome.

2011-12-30 Thread Lucifer
@shady Just an addition to the previous solution, in case u are not concerned about overlapping string i.e orig and rev strs overlap then all you need to do is remove the following condition and it shall work fine: *(pStrt < pRev) // remove this condition.. On 30 Dec, 15:03, atul anand wrote:

Re: [algogeeks] Re: Find even length palindrome.

2011-12-30 Thread atul anand
@shady : for this question Given a string of length N, find whether there exits an even length reverse substring of a substring. you can use hastable , as i have mentioned above. On Thu, Dec 29, 2011 at 5:50 PM, shady wrote: > oh, i didn't read all the posts, anyway i have understood lucifie

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@topcoder 1) For N <= 2 and not 3 its always a "YES".. 2) Also if u are OK with traversing the array twice i.e instead of a single run N we can do it 2*N.. Then we can do the following to intialize left and right properly instead of -+INF : 1) Scan the array to get the smallest and the gr

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
Actually, the initial code that i have written could have written as follows: int left = -INF; // or smallest integral value int mid = 10; // greatest integral value int right = +INF; int i = 0; while (++i < N) { // Same as the previous code.. } I didn't take the above initialization approach

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@topcoder.. You are correct.. I just figured out that the N<=3 condition is not always correct.. Below i have explained with example the code that will fix it: Basically for N=3 , say the sequence is a , b, c.. Then the valid cases would be: a < b < c a >= b >= c a < b , (b>=c and a < c) a >=

Re: [algogeeks] Re: Generate all possible binary trees given in-order traversal

2011-12-30 Thread praveen raj
yes... right... i forget to remove this statement.. PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING On Fri, Dec 30, 2011 at 2:17 PM, Lucifer wrote: > @praveen > > I think what u are doing above is the following: > Say, F(n) denotes the no. of binary trees that can be formed using N > elements g

[algogeeks] Re: Generate all possible binary trees given in-order traversal

2011-12-30 Thread Lucifer
@praveen I think what u are doing above is the following: Say, F(n) denotes the no. of binary trees that can be formed using N elements given the inorder sequence.. F(n) = SumOver(i= 1 to N) { F(i-1) * F(N-i) } which is nothing but.. F(N) = (2n C n)/ (n+1) i.e. catalan's no. Also, i would like

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread top coder
@Lucifer Looks like Your algo works for all of the my test cases. I am not able to find counter case. Also we should not Print "Yes" for N<=3 For eg: A = 4,2,6 Then 2 is a root with 4 as left child and 6 as right child. It contains two childs and fails the case. On Dec 30, 1:26 pm, Lucifer

Re: [algogeeks] Re: Generate all possible binary trees given in-order traversal

2011-12-30 Thread praveen raj
int countBT(int N) { int count =0; int count1; if(N==0) return 0; if(N<=1) return 1; else { for(int j=1;j<=N;j++) { count1 = countBT(j-1) count2 =countBT(N-j); count+=(count1*count2); } return (count); } }

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@above Also i would like to mention that the above algo considers equal valued elements and assumes that the BST should have the following property: 1) leftChild < = root 2) rightChild > root On 30 Dec, 13:24, Lucifer wrote: > @An idea... > > Let the array of integers be A[N].. > > If N < = 3,

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread Lucifer
@An idea... Let the array of integers be A[N].. If N < = 3, then the answer would be YES. If N > 3, then the following algo will follow: // The algo is self explanatory as its just ensuring BST property keeping in mind that a parent node has only one child... int left = smallest(A[0], A[1], A[