Click to See Complete Forum and Search --> : Generating an Elementary set E


santosh311
October 22nd, 2004, 01:18 PM
Can anybody help me in generating an elementary set E.

Notations:

m = no. of edges

Elementary set consists of 2^m no. of elements
The Elementary set should look like,
{1}, {2}, {3}, ..., {1,2}, {1,3}, {1,4},{1,5},{2,3} ...., {1,2,3,4,5}

This example I have shown it for m = 5
I want to write the code in C

I would be very much grateful, if anybody could provide me with the source code.

mehdi62b
October 22nd, 2004, 03:28 PM
Hi santosh311,

its better to solve it yourself,not looking for the code,
you can do it like the the following way,
consider 1,2,3,4,5 now(for m=5)
just generate binary numbers from 0(00000) to 31(111111)
then for example

00000 <---->{}
00001 <---->{5}
00010 <---->{4}
00011 <---->{4,5}
.
.
.
10101 <---->{1,3,5}
.
.
.
11111 <---->{1,2,3,4,5}

so you generate all subsets in this way according to the binary numbers
Hope I gave you the idea ....

santosh311
October 22nd, 2004, 08:01 PM
hi,
Thanks for the reply.

But in my code it is not restricted to just m=5, it could be anything. I will give you the idea of how the entire set should look like.
For example if m = 5

{1},{2},{3},{4},{5},{1,2},{1,3},{1,4},{1,5},{2,3},{2,4},{2,5},{3,4},{3,5},{4,5},{1,2,3},{1,2,4},{1,2,5},{1,3,4},{1,3,5},{1,4,5},{2,3,4},{2,3,5},{3,4,5},{1,2,3,4},{1,2,3,5},{1,2,4,5},{1,3,4,5},{2,3,4,5},{1,2,3,4,5}

If you can just tell me the logical part as to how to get the sequence i would be grateful. I can try to code it once I get the logic.

Thanks in advance
With regards

mehdi62b
October 23rd, 2004, 12:56 PM
I know it is not restricted to 5,
I just gave you the example for m=5
you should generate the numbers from 0 to 2^m-1(in binary)
i.e for m=3,
from 0(000) to 7(111)

000 <--->{}
001 <--->{3}
010 <--->{2}
011 <--->{2,3}
100 <--->{1}
101 <--->{1,3}
110 <--->{1,2}
111 <--->{1,2,3}

Did it clarify?

santosh311
October 23rd, 2004, 01:42 PM
Hi Mehdi,


Thanks a lot for the logic you have provided to me. It helped me a lot and thanks once again for your help.

If any queries I hope you would not mind me asking you any questions.

With regards

mehdi62b
October 23rd, 2004, 03:48 PM
surely,
(here,someone should help me !!! :D)

hritupon
October 25th, 2004, 03:54 AM
hi...hritupon here
i think this code should work

#include<stdio.h>
int main(void)
{
int num,value,base=8,max=1,i=1,j,decider;
printf("\n Enter the number:::");
scanf("%d",&num);
base=num;
while(i<=num)
{
max=2*max;
i++;
}
for(i=0;i<max;i++)
{
printf("\n{ ");
for(j=(base-1);j>=0;j--)
{
value=1<<j;
decider=i & value;
if((decider!=0)&&(j!=num))
printf(" %d ",j+1);
}
printf(" },");
}
}