Jump to content

Combination

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Iridescent (talk | contribs) at 19:19, 26 May 2008 (Reverted edits by 67.49.95.176 (talk) to last version by Excirial). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In combinatorial mathematics, a combination is an un-ordered collection of unique sizes. (An ordered collection is called a permutation.) Given S, the set of all possible unique elements, a combination is a subset of the elements of S. The order of the elements in a combination is not important (two lists with the same elements in different orders are considered to be the same combination). Also, the elements cannot be repeated in a combination (every element appears uniquely once); this is often referred to as "without replacement/repetition". This is because combinations are defined by the elements contained in them, thus the set {1,1,2} is the same as {2,1,1}. For example, from a 52-card deck any 5 cards can form a valid combination (a hand). The order of the cards doesn't matter and there can be no repetition of cards.

A k-combination (or k-subset) is a subset with k elements. The number of k-combinations (each of size k) from a set S with n elements (size n) is the binomial coefficient (also known as the "choose function"):

where n is the number of objects from which you can choose and k is the number to be chosen, and denotes the factorial.

As an example, the number of five-card hands possible from a standard fifty-two card deck is:

The number of combinations with repetition can be calculated as:

For example, if you have ten types of donuts (n) on a menu to choose from and you want three donuts (k) there are (10 + 3 − 1)! / 3!(10 − 1)! = 220 ways to choose (see also multiset).

A combination is a special case of a partition of a set; specifically, a partition into two sets of size k and n − k.

Since it is impractical to calculate if the value of n is very large, a more efficient algorithm is

Example:

You get the same result for as for k. Therefore, when k  is more than half of n, it may be easier to compute using in place of k.

See also

Combination listing from a group. a SIMPLE one pass algorithm Theory ( origin not known ) The nCr elements of the group are represented by the n bit binary numbers that have r positive bits.

eg if we are selecting  4 from  7    ABCDEFG
   71  1000111  indexes  A  EFG
   29  0011101  indexes   CDE G

To generate these index numbers get a number to binary function and add a counter of the number of 1 's.

assuming n is the number in the group r is the number to be picked Generic type program outline for x = 0 to 2^n-1 if x mod 2 =1 then count=count+1 , inString =binstring +"1" else binstring=binstring +"0" if count > r then exit next x if count = r then 'this binstring is one if the indices index to the combinations from any LIST.'