Hi
The solution in the link is of complexity (n*2^n))
Does anyone know any better solution ?
Regards
Ankur
On Tue, Jul 26, 2011 at 11:10 PM, rajeev bharshetty wrote:
> @Ankur The link does has a very good explanation. Nice solution :)
>
>
> On Tue, Jul 26, 2011 at 10:47 PM, Kunal Patil wrote:
@Ankur The link does has a very good explanation. Nice solution :)
On Tue, Jul 26, 2011 at 10:47 PM, Kunal Patil wrote:
> @Ankur Garg: Nice explanation at the link given by u...
>
>
> On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg wrote:
>
>> Check this
>>
>> http://codesam.blogspot.com/2011/03/f
@Ankur Garg: Nice explanation at the link given by u...
On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg wrote:
> Check this
>
> http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
>
>
> On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:
>
>> Here is the working code..
>>
>> #i
Check this
http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:
> Here is the working code..
>
> #include
> #include
> int a[] = {1,2,3,4,5};
> #define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
> void print_comb(int len)
> {
>
Here is the working code..
#include
#include
int a[] = {1,2,3,4,5};
#define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
void print_comb(int len)
{
int tlen = len;
int i, j, k;
int al = ARRLEN(a);
for (i = 0; i < al; i++) {
for (j=i+len-1; j wrote:
>
> check
check this link:
*http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
On Tue, Jul 26, 2011 at 11:59 AM, sumit wrote:
> Given an array of size n, print all the possible subset of array of
> size k.
> eg:-
> input:
> a[]={1,2,3,4}, k = 2
> output:
> 1,2
> 1,3
> 1,4
> 2,3
> 2,4
> 3,4
>
int main()
{
buildsubsets(0,0,"");
}
void buildsubsets(int i,int j,String subset)
{
if(j==k)
{
cout< wrote:
> Given an array of size n, print all the possible subset of array of
> size k.
> eg:-
> input:
> a[]={1,2,3,4}, k = 2
> output:
> 1,2
> 1,3
> 1,4
> 2
#include
#include
#include
#include
int main() {
using namespace std;
int arr[] = {1,2,3,4};
int k = 2;
int n = sizeof(arr)/sizeof(int);
vector v(arr, arr+n);
int l = pow(2.0, n);
for (int i = 0; i < l; ++i) {
bitset<32> b(i);
if (b.count() != k)
continue;
for (int j = 0; j < n; ++j) {
if (b[j
anyway, the code i posted is buggy.. doesn't work for "k=3".. don't use it :)
On Tue, Jul 26, 2011 at 1:02 PM, Vishal Thanki wrote:
> @ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
> following is the code..
>
> #include
> #include
>
> void print_comb(int *a, int len)
> {
>
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..
#include
#include
void print_comb(int *a, int len)
{
int tlen = len;
int i, j, k;
for (i=0;i<5;i++) {
for (j=i+1; j<4;j++) {
printf("
Hi
Dont u think the subsets will also be
{2,1}
{3,1}
{3,2}
{4,1}
{4,2}
{4,3}
On Tue, Jul 26, 2011 at 11:59 AM, sumit wrote:
> Given an array of size n, print all the possible subset of array of
> size k.
> eg:-
> input:
> a[]={1,2,3,4}, k = 2
> output:
> 1,2
> 1,3
> 1,4
> 2,3
> 2,4
> 3,4
>
> -
11 matches
Mail list logo