Saturday, 6 August 2016

Permutation & Combination

PERMUTATIONS & COMBINATION


Permutations 
Suppose we want to find the number of ways to arrange the three letters in the word CAT in different two-letter groups where CA is different from AC and there are no repeated letters.
Because order matters, we're finding the number of permutations of size 2 that can be taken from a set of size 3. This is often written 3_P_2. We can list them as:
    CA   CT   AC   AT   TC   TA
Now let's suppose we have 10 letters and want to make groupings of 4 letters. It's harder to list all those permutations. To find the number of four-letter permutations that we can make from 10 letters without repeated letters (10_P_4), we'd like to have a formula because there are 5040 such permutations and we don't want to write them all out!
For four-letter permutations, there are 10 possibilities for the first letter, 9 for the second, 8 for the third, and 7 for the last letter. We can find the total number of different four-letter permutations by multiplying 10 x 9 x 8 x 7 = 5040. 
To arrive at 10 x 9 x 8 x 7, we need to divide 10 factorial (10 because there are ten objects) by (10-4) factorial (subtracting from the total number of objects from which we're choosing the number of objects in each permutation). You can see below that we can divide the numerator by 6 x 5 x 4 x 3 x 2 x 1:
           10!     10!    10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1
10_P_4 = ------- = ---- = --------------------------------------
        (10 - 4)!   6!                     6 x 5 x 4 x 3 x 2 x 1

                        = 10 x 9 x 8 x 7 = 5040          
From this we can see that the more general formula for finding the number of permutations of size k taken from n objects is:
           n! 
n_P_k = --------  
        (n - k)! 
For our CAT example, we have:
          3!     3 x 2 x 1
 3_P_2 = ---- = ----------- = 6
          1!         1
We can use any one of the three letters in CAT as the first member of a permutation. There are three choices for the first letter: C, A, or T. After we've chosen one of these, only two choices remain for the second letter. To find the number of permutations we multiply: 3 x 2 = 6.
Note: What's a factorial? A factorial is written using an exclamation point - for example, 10 factorial is written 10! - and means multiply 10 times 9 times 8 times 7... all the way down to 1.


Combinations

When we want to find the number of combinations of size 2 without repeated letters that can be made from the three letters in the word CAT, order doesn't matter; AT is the same as TA. We can write out the three combinations of size two that can be taken from this set of size three:

    CA   CT   AT
We say '3 choose 2' and write 3_C_2. But now let's imagine that we have 10 letters from which we wish to choose 4. To calculate 10_C_4, which is 210, we don't want to have to write all the combinations out!
Since we already know that 10_P_4 = 5040, we can use this information to find 10_C_4. Let's think about how we got that answer of 5040. We found all the possible combinations of 4 that can be taken from 10 (10_C_4). Then we found all the ways that four letters in those groups of size 4 can be arranged: 4 x 3 x 2 x 1 = 4! = 24. Thus the total number of permutations of size 4 taken from a set of size 10 is equal to 4! times the total number of combinations of size 4 taken from a set of size 10: 10_P_4 = 4! x 10_C_4.
When we divide both sides of this equation by 4! we see that the total number ofcombinations of size 4 taken from a set of size 10 is equal to the number of permutations of size 4 taken from a set of size 10 divided by 4!. This makes it possible to write a formula for finding 10_C_4:
               10_P_4      10!         10!
     10_C_4 = -------- = ------- = ----------
                 4!      4! x 6!    4!(10-4)!


               10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1
            =  --------------------------------------
                4 x 3 x 2 x 1  (6 x 5 x 4 x 3 x 2 x 1)


              10 x 9 x 8 x 7    5040
            = -------------- = ------ = 210
               4 x 3 x 2 x 1     24 

More generally, the formula for finding the number of combinations of k objects you can choose from a set of n objects is:

            n!
n_C_k = ----------
        k!(n - k)!
For our CAT example, we do the following:

          3!      3 x 2 x 1     6 
3_C_2 = ------ = ----------- = --- = 3
        2!(1!)    2 x 1 (1)     2


Pascal's Triangle

We can also use Pascal's Triangle to find combinations:
   Row 0                   1
   Row 1                 1   1
   Row 2               1   2   1
   Row 3             1   3   3   1
   Row 4           1   4   6   4   1
   Row 5         1   5  10   10  5   1
   Row 6       1   6  15  20   15  6   1

Pascal's Triangle continues on forever - it can have an infinite number of rows. Each number is the sum of the two numbers just above it. For the 1 at the beginning of each row, we imagine that Pascal's triangle is surrounded by zeros: to get the first 1 in any row except row 0, add a zero from the upper left to the 1 above and to the right. To get the 3 in row 4, add the 1 left and above to the 2 right and above.
To find the number of combinations of two objects that can be taken from a set of three objects, all we need to do is look at the second entry in row 3 (remember that the 1 at the top of the triangle is always counted as row zero and that a 1 on the lefthand side of the triangle is always counted as entry zero for that row).
Looking at the triangle, we see that the second entry in row 3 is 3, which is the same answer we got when we wrote down all the two-letter combinations for the letters in the word CAT.
   Row 0                   1
   Row 1                 1   1
   Row 2               1   2   1
   Row 3             1   3   3   1

Suppose we want to find 10_C_4? To use Pascal's Triangle we would need to write out 10 rows of the triangle. This is a good time to use a formula.
More generally, to find n_C_k ("n choose k"), just choose entry k in row n of Pascal's Triangle.


One of the hardest parts about doing problems that use permutations and combinations is deciding which formula to use.



DONE BY: IMZ 

1 comment: