int main()
{
buildsubsets(0,0,"");
}
void buildsubsets(int i,int j,String subset)
{
if(j==k)
{
cout<<subset+" ";
return ;
}
for(;i<n;++i)
buildsubsets(i+1,j+1,subset+arr[i]);
}
assume that given arr[] is a character array i.e. arr[]={'1','2','3'}. for
any value of k it works
On Tue, Jul 26, 2011 at 11:59 AM, sumit <[email protected]> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.