0
Subsequnce or Subset of an array
How to find the subsequence or subset of an array that contain n elements? Can anyone explain me how to do. Preferably in C++
19 Answers
+ 1
Can you explain me with an example
+ 1
Oh let me see i will tell you in a minute
0
Are asking about how to get all the values from an array ??
0
I'm asking about subsequence or subset of an array Sahil Bhakat
0
If you have an array {1, 2, 3} then subsets are {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3} are subsets of that array
But I need subset that contain n elements. i.e If n=2 then subsets are {1, 2}, {2, 3}, {1, 3}.
0
There is one problem
0
What? Sahil Bhakat
0
If the array is {1,2,3,4}
Then the subsets you need are this - {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} right?
0
Similar to that but it's not necessarily 2 elements it may be of any number of elements less than the size of array
0
Yes for 2 elements is this correct ?
0
Yeah it's correct
0
Sorry i am going somewhere so you should put another question if you are in hurry or i will do it later
0
Keep me posted if you can
0
If you can complete it, I will leave it up to you.
0
Ok thanks
0
m=sizeof(a)/sizeof(a[0];
for(i=0;i<m-1;i++)
for(j=i,c=0;j<m-1;j++)
{
cout<<"{";
for(k=0;k<n;k++)
{
if(k=0)
cout<<a[i];
else
cout<<","<<a[i+c];
c++;
}
cout<<"}, ";
}
cout<<"\b";
0
Try this and tell me if it works or not
0
Not working
0
Ok let me check