Re: [algogeeks] subset of an array

2011-10-10 Thread abhishek sharma
yea DP will be O(given no * n) if all array entries are positive and the
given no is non negative.

On Mon, Oct 10, 2011 at 11:09 PM, anshu mishra wrote:

> the simplest code could be for this question is
>
> void printAllSubsetSum(int ar[], int n, int x)
> {
> for (i = 0; i < (1< {
> int sum = 0;
>  for (j = 0; j < n; j++)
>  {
> if ( (1 << j) && i) sum += ar[j];
>  }
>  if (sum == x)
>  {
> for (j = 0; j < n; j++)
>{
>if ( (1 << j) && i) printf("%d ", ar[j]);
>}
>   printf("\n");
>  }
> }
> }
>
> Time complexity O(2^n)
>
> this can be solved using DP in O(n * given number);
>
>  --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Nice Day

Abhishek Sharma
Bachelor of Technology
IIT Kanpur (2009)

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] subset of an array

2011-10-10 Thread anshu mishra
the simplest code could be for this question is

void printAllSubsetSum(int ar[], int n, int x)
{
for (i = 0; i < (1

Re: [algogeeks] subset of an array

2011-10-10 Thread Rashmi Jain
not necessary contiguous..
eg:
we are given with an array-1,4,2,26,8,3 and we need to find the subsets of
this having sum of its members as 11.
ans should be  1,2,8 and 8,3
i hope i am clear this time..

On Mon, Oct 10, 2011 at 9:38 PM, Hatta  wrote:

> is it a contiguous set, any sparse subset or what?
>
> if it's a subset of a set then it can be sparse, but when you say
> "array" you make it quite tricky to figure out.
>
> with all due respect sir,
> please mind that when you make a question you're taking peoples time
> to answer it
> therefore if the answer is useless to you  you'd have wasted someone
> else's time with no reason. so please, I gently ask you to make a
> clear question next time.
>
>
>
>
> On Mon, Oct 10, 2011 at 11:47 AM, Rashmi Jain 
> wrote:
> > algo to find subsets of an array whose sum is equal to a given number..?
> >
> > --
> > 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 this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> Hatta
>
> --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] subset of an array

2011-10-10 Thread Hatta
is it a contiguous set, any sparse subset or what?

if it's a subset of a set then it can be sparse, but when you say
"array" you make it quite tricky to figure out.

with all due respect sir,
please mind that when you make a question you're taking peoples time
to answer it
therefore if the answer is useless to you  you'd have wasted someone
else's time with no reason. so please, I gently ask you to make a
clear question next time.




On Mon, Oct 10, 2011 at 11:47 AM, Rashmi Jain  wrote:
> algo to find subsets of an array whose sum is equal to a given number..?
>
> --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Hatta

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] subset of an array

2011-10-10 Thread Rashmi Jain
algo to find subsets of an array whose sum is equal to a given number..?

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.