Re: [algogeeks] Re: print vertical sums of a binary tree

2011-10-22 Thread ashish shukla
procedure visit(node root,int c) { if (root= null) return 0; S[c] += n.value; visit(root-left, c - 1) visit(root-right, c + 1) } On Fri, Oct 21, 2011 at 1:22 PM, Mohak Naik mohak...@gmail.com wrote: If we want to compute the sum of every column, we can use the following

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-22 Thread sunny agrawal
yea i know 1st Approach is much better and is Only O(N^2) for precomputing all the values for nck and then O(k) for finding no of bits set in The Kth number and another loop of O(k) to find the required number i posted 2nd approach in the context to vandana's tree approach of sorting 2^N numbers,

Re: [algogeeks] Re: print vertical sums of a binary tree

2011-10-22 Thread ashish shukla
initialize array with 0 and provide appropriate value to c otherwise it will be negative and here c is using as index for array. procedure visit(node root,int s[],int c) { if (root= null) return 0; S[c] += n.value; visit(root-left, c - 1) visit(root-right, c + 1) } On Fri,

[algogeeks] Re: Amazon Ques Suggest Algo

2011-10-22 Thread vasanthi emani
nice idea.. On Oct 20, 11:04 am, SUMANTH M sumanth.n...@gmail.com wrote: - Take another sum array which contains sums of original array at each index, here sum[0] = a[0]; sum[1] = a[0] + a[1] ;...sum[i]=a[0]+a[1]+...a[i]; - Traverse the sum array and search for duplicates.   ex: a[] =

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-22 Thread Ankur Garg
@Sunny Your technique of Inshuffle and Outshuffle are perfect. But how to translate into the code without using extra space or say even constant space On Tue, Oct 18, 2011 at 12:43 AM, Dan dant...@aol.com wrote: I have a hard copy of the book (years back, I implemented a fortran version of

Re: [algogeeks] Re: Modular arithmetic

2011-10-22 Thread Mad Coder
Can anyone explain why ((n%p)*(m%p))%p will give wrong answer ? -- 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

Re: [algogeeks] Re: finding anagrams in file

2011-10-22 Thread Siddhartha Banerjee
how about this O(nm) solution? first create a 26 length int array for each word, store the number of times each character appears in the word, in the above 26 length array O(m)... Insert this value in a trie (insertion=O(m))... example if the sorted string contains a-4times, b-3 times, c-2 times,

Re: [algogeeks] Re: Modular arithmetic

2011-10-22 Thread Aamir Khan
On Sat, Oct 22, 2011 at 9:04 PM, Mad Coder imamadco...@gmail.com wrote: Can anyone explain why ((n%p)*(m%p))%p will give wrong answer ? Lets say, n = 10^15 , m = 10^15 and p = 10^18 So, n%p = 10^15 m%p = 10^15 And the intermediate result (n%p)*(m%p) will overflow the long long range.