Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Hello friend,

I have a problem which will store all the possible number of sets that are comming for given number of values. like if the input is 3. the 1,2,3 will form different combinations of sets.

like {{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}. the total number of sets is (2 to the power of n)-1. here n is 3.

I want to store all these distinct combinations in a two dimensional array. So please provide me the logic for this as quickly as possible.

yours sincerely,

ramu.

I have a problem which will store all the possible number of sets that are comming for given number of values. like if the input is 3. the 1,2,3 will form different combinations of sets.

like {{1},{2},{3},{1,2},{1,3},{

I want to store all these distinct combinations in a two dimensional array. So please provide me the logic for this as quickly as possible.

yours sincerely,

ramu.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

btw the code i wrote will be a tricky one..to understand which u'll have to put some effort..

What we do allow, for example, is general pointers, and showing where a mistake has been made.

If this is homework:

Please attempt to solve the problem yourself. If you have trouble with something *specific*, ask for help with that one issue.

If not, please demonstrate the need for this algorithm in your system.

Banath

EE Moderator

logic is pretty simple.. i'll give u something recursive..i hope u understand what recursion means..

here is pseudoCode

storageArrray can look like.

struct subsets{

char **subsets; //two dimensional array

int count;

};

subsets(storageArrayPointe

if n >1

calculate subsets(storageArrayPointe

for each subset in storageArrayPointer

make pair n,subset

increment storageArrayPointer->count

store the pair as subset

if n=1

increment storageArrayPointer->coute

store phy(null subset) as empty subset

increment storageArrayPointer->coute

store 1 as only non-empty subset

return

}

pair of n,given subset is defined as

suppose u have n =3 and current subsets are

{phy},1,2,12,

then pair are respectively

3,13,23,123

pair of n,{phy} is 'n'

so in the storageArrayPointer .. u'll get 2^n subsets .. 2^n-1 + 1(empty subset)

phy is univseral subset

in his question , i guess the asker mentioned that he needs the logic and not full source .. sorry for ignoring that comment..

>>> store the pair as subset

where ever i have said this .. u need to increase the size of

storageArrayPointer->subse

and then make space for the string that will depict ur subset..

like to depict the subset {1,2,3}

u can use string "1,2,3"

and store it in the newly re-allocated space at the end

#include<stdio.h>

#define n 5

int sets[50][5];

int initpos=0,finalpos=n,point

int length=2;

int base[n],i,j;

main()

{

initialize();

clrscr();

while(1)

{

while(initpos<finalpos-1)

{

copy_previous();

find_base_ptr(sets[finalro

while(1 && pointer<=n)

{

sets[finalrow][j]=base[poi

finalrow++;

if (pointer>=n)

break;

copy_previous();

}

initpos++;

if(sets[initpos][j]==base[

}

length++;

initpos=finalpos;

finalpos=finalrow;

if(length==n+1)

break;

}

print();

}

print()

{

for(i=0;i<finalrow;i++){

for(j=0;j<n;j++)

printf("%d",sets[i][j]);

printf("\n");

}

}

copy_previous()

{

j=0;

while(j<length-1)

sets[finalrow][j]=sets[ini

}

initialize()

{

for(i=0;i<n;i++)

base[i]=sets[i][0]=i+1;

}

find_base_ptr(int x)

{

for(i=0;i<n;i++)

if(base[i]==x)

pointer=i+1;

}

please try this.

and thanks to one and all who suggested me

My recommendation, which I will post in the Cleanup topic area, is to

PAQ, refund points.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg

EE Cleanup Volunteer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

"abcdef..z".. where u specify number of alphabets .. like if u input 3 u'll get a,b,c,ab,bc,ca,abc, and ofcourse NULL set..

u can modify that with just one string change..

i'll get u tomorrow . if by then u dont find any one..

right now away from my computer