answersLogoWhite

0


Best Answer

Each element of C can either be in a particular subset or not in it - two options for each element of C. So if there are n elements in C, then the number of subsets of C is 2n. These include the null set and C itself.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is code of finding all subset in a set in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is every subset of a finite set is a finite?

prove that every subset of a finite set is a finite set?


How do you enumerate all the possible subsets of x y z in C plus plus?

Enumerating subsets requires that each element in the set be mapped to a bit value. Combining these bit values (with logical OR) gives you the subset. Each subset will then have a value in the range 0 to 7, giving 8 subsets in all: {}, {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, {x, y, z}. However, you cannot simply count from 0 to 7 to enumerate these subsets because this is highly inefficient. In a set of 3 it's not a significant loss, but in a larger set the inefficiency is substantial. For instance, in a set of just 64 elements, you must count from 0 to 9,223,372,036,854,775,809 in order to enumerate the 64 subsets that have just one element. If that doesn't drive the point home, then nothing will.In order to correctly enumerate subsets you must use the Banker's sequence. Each sequence varies depending upon how many elements are in the set, however the sequence allows you to quickly enumerate one set after another in a logical sequence. It also allows you to start from anywhere in the sequence and continue from that point on, thus making it possible to quickly enumerate all sets with a specific number of elements.The following code is quite involved but includes several auxiliary functions that help speed up the main code at the bottom. Some examples are included to demonstrate different usages, including the enumeration of subsets of {x, y, z}, subsets of a set of 5 elements and subsets of a subset of a 9 element set. Note that the final example (all subsets of a 32 element set) is commented out because it will take a seriously long time to enumerate all the possible subsets. However, the code is flexible enough to allow you to narrow the search down to just those subsets with a specific number of elements.Note that the two main functions to focus upon are the find_first_subset() and find_next_subset() functions. These two functions are the driving force behind the Banker's sequence.#include // Returns the count of set bits in the given subset.// E.g., 01010010 returns 3.unsigned int count_set_bits( register unsigned int subset ){// An alternative method is to logical AND the bitset with 0x1// then right shift the bitset by 1 bit. That requires an average// of 32 separate operations (worst case is 64). This method always// uses 17, thus always returns in constant time. For unsigned// short, eliminate the last shift. For char, eliminate the last// two shifts.subset -= (( subset >> 1 ) & 0x55555555 );subset = ((( subset >> 2 ) & 0x33333333 ) + ( subset & 0x33333333 ));subset = ((( subset >> 4 ) + subset ) & 0x0f0f0f0f );subset += ( subset >> 8 );subset += ( subset >> 16 );return( subset & 0x0000003f );}// Returns all set bits from the given subset's MSB down.// E.g., 00100010 returns 00111111.// The inversion of the return value can be used to mask// bits that are greater than the MSB in another subset.unsigned int fill_down( register unsigned int subset ){subset |= ( subset >> 1 );subset |= ( subset >> 2 );subset |= ( subset >> 4 );subset |= ( subset >> 8 );subset |= ( subset >> 16 );return( subset );}// Returns the least-significant set bit in the given subset.// E.g., 00100110 returns 00000010.unsigned int get_LSB( register unsigned int subset ){return( subset ^ ( subset & ( subset - 1 )));}// Returns the most-significant set bit in the given subset.// E.g., 00100110 returns 00100000.unsigned int get_MSB( register unsigned int subset ){subset = fill_down( subset );return( subset & ~( subset >> 1 ));}// Returns the first subset of subset_count within the given set.// The return value can be passed to get_next_subset().unsigned int get_first_subset( const unsigned set, unsigned int subset_count ){// Initialise the subset.unsigned int subset = 0;// Check validity of parameters.if( subset_count && subset_count


What is the difference between profiling and debugging?

Profiling is about executing a program and finding out how much time it spends in each routine. The goal of profiling is often finding slow routines in a program and optimizing them. Profiling is done on working code. Debugging is about finding code that is not working, i.e. has some kind of defect. The program is known to have a defect because some set of inputs causes a set of outputs that are known to be wrong. Debugging is the process of finding the source of the defect in the code and fixing that location and any other downstream locations so that the set of inputs is correctly rendered into the set of outputs.


What does Error code 80072F8F mean for windows vista?

All you have to do is set your computer's time and date.


What is the correct jQuery code to set the background color of all p elements to red?

$(this).css("background-color");

Related questions

What the meaning of subset?

A subset is a division of a set in which all members of the subset are members of the set. Examples: Men is a subset of the set people. Prime numbers is a subset of numbers.


What is improper subset?

A proper subset B of a set A is a set all of whose elements are elements of A nad there are elements of A that are not elements of B. It follows, then, that an improper subset must be the whole set, A. That is, A is an improper subset of A


How do you put subset in a sentence?

The set of all positive integers is a subset of the set of all integers.


What is a universal subset?

The universal subset is the empty set. It is a subset of all sets.


What do you call sets within another set?

If all elements of set A are also elements of set B, then set A is a subset of set B.


Which set is a subset of every set?

The empty set is a subset of all sets. No other sets have this property.


What are the subset of a set?

The subset of a set S is a set containing none, some or all of the elements of S.


What is a subset in mathematics?

If all elements in set "A" are also elements of set "B", then set "A" is a subset of set "B". If the sets are not equal (set "B" also has some elements that are not in set "A"), then set "A" is a PROPER subset of set "B".Answer:In simple words: a subset is a set (a group) that is within another set. For example, the set of odd integers (odd numbers) is a subset of the set of all integers.A non-math example: the set of urbanites is a subset of the set of all people.See the first Answer (above) for more detail.


What is a different from subset and proper subset?

If set A and set B are two sets then A is a subset of B whose all members are also in set B.


What is mean by Subset in Mathematics?

If all the elements in set A are also elements of set B, then set A is a subset of set B.


What is a subset and a proper subset?

A set is a subset of a another set if all its members are contained within the second set. A set that contains all the member of another set is still a subset of that second set.A set is a proper subset of another subset if all its members are contained within the second set and there exists at least one other member of the second set that is not in the subset.Example:For the set {1, 2, 3, 4, 5}:the set {1, 2, 3, 4, 5} is a subset set of {1, 2, 3, 4, 5}the set {1, 2, 3} is a subset of {1, 2, 3, 4, 5}, but further it is a proper subset of {1, 2, 3, 4, 5}


When is a set a subset of another set?

For example the set of all numbers which are integer multiples of 4 is a subset of all the numbers exactly divisible by 2.