Efficient recursive approaches are also welcome.
On Mon, Jul 18, 2011 at 8:47 PM, saurabh singh <[email protected]> wrote:
> Excuse for the trivial question.I am trying to design an iterative approach
> for the same.
> My best shot has been.
> #include<iostream>
> #include<bitset>
> using namespace std;
> void printset(char a[],bitset<3> &ss)
> {
> cout<<"{ ";
> for(int i=0;i<3;i++) if(ss.test(i)) cout<<a[i]<<" ";
> cout<<" }"<<endl;
> }
> int main()
> {
> char a[]={'a','b','c'};
> unsigned j;
> for( j=0;j<=7;j++)
> {
> bitset<3> charset(j);
> printset(a,charset);
> }
> return 0;
> }
> http://www.ideone.com/8Q5jQ
> Its really an ugly code with lots of things hardcoded breaking all rules of
> aesthetic coding,excuse me for that.
> Can anyone suggest a better algorithm.Assuming the bitset operation to be
> o(1) {which may not be the case} my algo is o(2^n) {BAD :( }
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT ALLAHABAD
>
>
>
--
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD
--
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.