Re: [algogeeks] all subarray with sum zero

2012-09-17 Thread pankajsingh
it wud give u continuous...subarray...if u want non continuous..question shud be subsequence...and for that u need to all combination O(n^20..which is offcourse bruteforce... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] all subarray with sum zero

2012-09-17 Thread pankajsingh
make a sum array..such that..sum[i]=sum of number from 0 to i-1make a node which has 2 data..sum[i] and ith index itself..sort this node array according to sum[i]...now check for consecutive value which have same value...corresponding index i,j to that sum nodes will be start and end of

Re: [algogeeks] Suggest algo...

2012-08-28 Thread pankajsingh
Code:- #includeiostream #includevector using namespace std; void recursion(int sum,int i,vectorint v,int size) { vectorint v1=v; int size1=size; if(sum==0) { for(int k=0;ksize;k++) coutv[k] ; coutendl; } else { for(int j=i+1;j10;j++)

Re: [algogeeks] amazon Interview

2012-08-28 Thread pankajsingh
@atul-I think This Should work for n dimension- complexity O(n^no.of dimesions) :- have N-dimension check for which Tile can contain which Tile.i.e (3,3,4) can contain (2,3,4) . Now 1.Take the titles which cannot contain any-other tile set no-of tile if it is base =1; 2.now take tiles which can

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
Hope This will Work.. int Recursion(node *root) { if(root-left==Nullroot-right==Null) { return root-data; } int a=0,b=0; a=recursion(root-left); b=recursion(root-right); if(a+b+root-datamax) max=a+b+root-data; return max(a,b)+root-data; } -- You received this message because you are subscribed

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread pankajsingh
@all-This is almost the same question asked in facebook.. Dave sir is correct! Example-file contain only a b a c; Then step1: save a; step2: save b with probability of value 0 by rand()%2; therefore pr[1]=1/2;pr[2]=1/2; step3; save a with probability of value 0 by rand()%3; therefore

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
@vaibhav-yup :-) -- 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+unsubscr...@googlegroups.com. For more options, visit

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread pankajsingh
@Dave Sir-Got ur point..thnks!! -- 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+unsubscr...@googlegroups.com. For more

Re: [algogeeks] O(n) solution is there or not!!

2012-08-22 Thread pankajsingh
@Carl-At each step you are calculating lcp between the text and the last entry probably to compare ... lcp[i+1]..is it linear still -- 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] O(n) solution is there or not!!

2012-08-22 Thread pankajsingh
@Atul- can you explain ur approach a little more..What is A and B string wd reference to question..for each A and B string it will take O(n) time to make the table...ur approach is O(n)..dont think so..please explain may be i m wrong -- You received this message because you are subscribed to

Re: [algogeeks] O(n) solution is there or not!!

2012-08-21 Thread pankajsingh
@carl-Sorry was making suffix array by naive approx in the link http://en.wikipedia.org/wiki/Suffix_array .there are more optimized algos for it...!! thanks -- 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] O(n) solution is there or not!!

2012-08-20 Thread pankajsingh
Thanks.carl and atul.!!.@carl-i got lgn due to string comparison sort while making the suffix array..:) -- 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

Re: [algogeeks] O(n) solution is there or not!!

2012-08-19 Thread pankajsingh
@Carl- I didnt got ur point completely abt Lcp array..can you demonstrate on the below example... Example for ababaa answer shud be -11 suffix array wud be:- a aa abaa ababaa baa and Lcp array would be then 0 1 1 3 0 ..correct if wrong..whats next... -- You received this message because you

Re: [algogeeks] O(n) solution is there or not!!

2012-08-19 Thread pankajsingh
@carl- got ur point..but complexity is more..suffix array takes o(n^2lgn)..considering string comparisons. complexity to build...i already have o(n^2)..want o(n).. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Binomial Coefficients

2012-07-31 Thread pankajsingh
may be Lucas theorem will be helpful...google it!! -- 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] Partition-Efficient algorithm.

2012-06-05 Thread pankajsingh
What is the efficient algorithm to partition a big number like 1000 into 500 parts such that each part is=0,i need to know all the partition ;ex partition of 5 into 3,4 1 0,3 1 1,2 2 1,i know brute force methods..please provide some algorithm which is feasible to calculate all the partition upto

Re: [algogeeks] AllBinomialCoefficients

2012-03-04 Thread pankajsingh
@Dave- really nice , that will do,thnks a lot! -- 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] AllBinomialCoefficients

2012-03-03 Thread pankajsingh
I want to calculate all binomial coeffficient upto a particular number say 1000.,like 1000C1 100C2 1000C3...999C1,999C2..998C12C1 1C1. all possible binomial coefficient out of 1000*1000 modulo 17;I want a maximum complexity of o(n^2);for 1000,i had some code of mine

Re: [algogeeks] AllBinomialCoefficients

2012-03-03 Thread pankajsingh
@jai-thanks!!! , it worked...,is there any method for big numbers like 10,in my case 1000 so storing in array[10^3][10^3] worked but what if 10^5,storing will not work then??,anyway thanks a lot again -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] AllBinomialCoefficients

2012-03-03 Thread pankajsingh
@amrit- thnks!! -- 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+unsubscr...@googlegroups.com. For more options, visit

Re: [algogeeks] AllBinomialCoefficients

2012-03-03 Thread pankajsingh
@atul-its nice one, but its complexity is probably greater than o(n^2) just to calculate one mCk,i want a sequence of all mCk in a less complexity i tried for some code which calculate all mC1,mC2..mCk in less complexity.this works good till (100)Ck ; if while loop can be reduced i can get a

Re: [algogeeks] AllBinomialCoefficients

2012-03-03 Thread pankajsingh
@atul-its nice one, but its complexity is probably greater than o(n^2) just to calculate one mCk,i want a sequence of all mCk in a less complexity i tried for some code which calculate all mC1,mC2..mCk in less complexity.this works good till (100)Ck ; if while loop can be reduced i can get a

Re: [algogeeks] Re: sort 2D array

2012-01-12 Thread pankajsingh
@prakash...ya i realized that and it will be sorted row and column wise.which will become same as forming min-heapand my algo will become same what lucifer had already specified... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Re: sort 2D array

2012-01-11 Thread pankajsingh
I thought of a simpler algo, i m using the property of this matrix That is. a[i][0] is smallest of a[i][] and a[i+1][]so on,so to decide next smallest element i will only consider a[i][0]... i will swap element if required and sort the row(too by swapping) if element are changed. on the

Re: [algogeeks] Re: sort 2D array

2012-01-11 Thread pankajsingh
50 6 9--- 8 7 22 45 55--- 7 8 22.and so on... for swapping without space use a=a+b; b=a-b; a=a-b; it worked for examples i had takenpls notice me if any flaw with this.. On 1/11/12, pankajsingh psingh...@gmail.com wrote: srry some formatting problem...i will repost later

Re: [algogeeks] No of triangles

2011-12-04 Thread pankajsingh
sorryi was thinking n as number of nodes... -- 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] No of triangles

2011-12-04 Thread pankajsingh
yours question is slightly unclear.,if u need to count all possible number of triangle,why i need to divide in 3 parts...,what i think u r looking for is dividing in 3 parts which give me maximum number of possible triangleif it is so, divide in more or less equal parts...

[algogeeks] Problem of calculating large binomial coefficients which large base so lucas theorem cant be applied

2011-11-06 Thread pankajsingh
i want to calculate values like (100 C 1) %17,what would be better algorithm for it,i think lucas theorem cant be used in this case.want some efficent algorithm,actually i want to calculate mC1,mC2mC1000 %17,such that may is about 10^6 -- You received this message

Re: [algogeeks] Re: Problem of calculating large binomial coefficients which large base so lucas theorem cant be applied

2011-11-06 Thread pankajsingh
Thanks Dave, but i want some more efficient in my case, something like O(k) to calculate all mC1 mC2...mCk, i already had a worst time O(k^2), i.e for (long long int i1=1;i1=k;i1++) { while((result*(m-i1+1))%i1) { result=result+17; } result=(result*( m-i1+1)); result /= i1;