Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread Jeeva A
yes it must go into hashSet ...You have got it right. On Tue, Jun 22, 2010 at 5:55 PM, sharad kumar wrote: > @ Jeeva...abt ur soln > when a[1] comes i.e 2 so i think according to algo 10-2 i.e 8 must go in > plzz correct me if i wrongly understood it > > -- > You received this message because you

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
thnx Raajay n Jeeva for giving so clear explainations bt actually my question is ...if i/p is 5 then u hve to print 1+4 1+1+3 1+1+1+2 1+1+1+1+1 1+2+2 1+4 2+3 and all such pairs giving 5 i hope i m clear this time -- You received this message because you are subscribed to the Google Groups "Algor

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
@ Jeeva...abt ur soln when a[1] comes i.e 2 so i think according to algo 10-2 i.e 8 must go in plzz correct me if i wrongly understood it -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegro

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread Jeeva A
First I will explain little bit about hashSet. look up in hashSet is very quick, hashSet always maintains only unique element. algo: sum = x; for i = 0 to array[arrayLength - 1] if array[i] in hashSet : return (array[i], sum - array[i]) else: hashSet.add (sum-a[

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread Raajay
Hi Sharad, I suppose this is what you are looking for. Assume non-negative integers. Otherwise, there are infinite possibilities. #include #include #include using namespace std; vector< vector > allCombinations; void findAllCombinations(vector elements, int left) { if(left < 0) return; else

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread sharad kumar
i knoe c++ well so i can understand java code bt i m not able to understand this code so pl explain it or give algo thnx in advance -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroup

Re: [algogeeks] find all the combination of number whose sum is n

2010-06-22 Thread Jeeva A
Here is the java code: public class allCombinationsSumIsN { public static void main(String args[]) { int array[] = {7,2,3,1,-5,8,15}; int sum=10; Set hashSet = new HashSet(); for (int i: array) { if (hashSet.contains(i)) { System.out.println(i+","+(sum-i));

[algogeeks] find all the combination of number whose sum is n

2010-06-21 Thread sharad
How will you find all the combination of number whose sum is n -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr.