MTH 225 Lecture-Module #14:
Counting





counting is considered a topic worth studying
because CS and IS people have found that determining extents of some things
    such as times to run some algorithms,
    "heights" of "trees" used for data structures
can be tricky

to begin, something basic (or is it so basic?):

fundamental product rule for counting

|S1 × S2 × ··· × Sn| := |S1| * |S2| * ··· * |Sn|
e.g.s in preceding lecture module:
{red,green,blue} × {t,f}  :=
   
and 
{red,green,blue} × {t}  := 
and 
{red,green,blue} × {}  := 
and 
{t,f} × {t,f} := 
and 

another e.g. the set of North American telephone numbers is
NA := {1} × (T×D×D) × (T×D×D) × (D×D×D×D)
where T is {2,3,4,5,6,7,8,9} and D is {0,1,2,3,4,5,6,7,8,9}
using product rule,
|NA| :=  |{1}| * (|T|*|D|*|D|) * ···
        :=  1 * (8*10*10) * (8*10*10) * (10*10*10*10)
        :=  6,400,000,000

the sum rule

if some finite sets S1,S2,S3,... are all pairwise disjoint,
then  |Si| :=  |S1| + |S2| + |S3| + ...
e.g. the number of people in this room who own cars equals
|S1| the number of people in this room who own 1 car
+ |S2| the number of people in this room who own 2 cars
+ |S3| the number of people in this room who own 3 cars
etc.
kind of obvious, eh?
or if a restaurant offers 12 regular entrées and 3 special entrées,
how many different options do you have for ordering there? 

but (just in case) note the difference between that last example
and the following question:
if you have  different main things to order
and  different desserts you could order also,
then the total number of options is 


but what is the cardinality of a union if the sets are not disjoint,
i.e. if they share some elements in common?

inclusion-exclusion rule for counting

|S1 ∪ S2|  :=  |S1| + |S2| – |S1 ∩ S2|

e.g. (using material from earlier lecture module)
suppose B is {a,b,c,d,e} and V is {a,e,i,o,u}
then  |B| := ,  |V| := ,
|B ∩ V|  :=  |{}|  := ,
|B| + |V| – |B ∩ V|  :=    := 
and  |B ∪ V|  :=  |{}|  := 

another e.g. rem. function φ() used regarding numbers' relative primality
    needed for RSA encryption
φ(x) := |RP(x)|
where  RP(x) :=  { i : 1 ≤ i ≤ x  and  gcd(i,x) := 1 }
e.g. φ(5) := 
e.g. φ(9) := 

can φ(x) be calculated without 'running through numbers 1..x'?
e.g. what is φ(1000)?
well, another way to view RP(x) is as follows:
    RP(x) :=  { i : 1 ≤ i ≤ x } – CD(x)
where:
    CD(x) :=  { i : 1 ≤ i ≤ x  and  gcd(i,x) > 1 }
now, gcd(i,x) > 1 iff at least one prime divides both i and x
so if x's prime factorization
is p1e1*p2e2*···*pkek
then  CD(x) :=  { i : 1 ≤ i ≤ x
                                         and  (p1|i or p2|i or ... or pk|i) }
                :=  { i : 1 ≤ i ≤ x  and  p1|i }
                        ∪ { i : 1 ≤ i ≤ x  and  p2|i }
                        ∪ . . .
                        ∪ { i : 1 ≤ i ≤ x  and  pk|i }
e.g.  CD(1000) :=  { i : 1 ≤ i ≤ 1000  and  2|i }
                                        ∪ { i : 1 ≤ i ≤ 1000  and  5|i }
let S2 be { i : 1 ≤ i ≤ 1000  and  2|i }
and let S5 be { i : 1 ≤ i ≤ 1000  and  5|i }
so  CD(1000) == S2 ∪ S5

rem. we want φ(1000) which is |RP(1000)| which is |{i : 1 ≤ i ≤ x}| – |CD(1000)|
well, by the inclusion-exclusion rule for counting,
|CD(1000)| :=  |S2| + |S5| - |S2 ∩ S5|

so what is |S2| i.e. |{ i : 1 ≤ i ≤ 1000  and  2|i }|?
well, 2 divides half the numbers i in the range 1≤i≤1000
so  |S2| :=  := 
similarly 5 divides one-fifth of the numbers i in the range 1≤i≤1000
so  |S5| :=  := 
the fraction of numbers i in the range 1≤i≤1000
divisible by both 2 and 5 is one-tenth
so  |S2 ∩ S5| :=  := 

therefore,
φ(1000) := |RP(1000)|
        :=  |{i : 1≤i≤1000}| – |CD(1000)|
        :=  
        :=  

difference rule for counting

|S1 – S2|  :=  |S1| – |S1 ∩ S2|

e.g. (using material from earlier lecture module)
suppose B is {a,b,c,d,e} and V is {a,e,i,o,u}
then  |B| := ,  |B ∩ V|  :=  |{}|  := ,
|B| - |B ∩ V|  :=    := 
and  |B - V|  :=  |{}|  := 

e.g. (using material from earlier lecture module)
suppose V is {a,e,i,o,u} and E is {x,y,z}
then  |V| := ,  |V ∩ E|  :=  |{}| i.e. ||  := ,
|V| - |V ∩ E|  :=    := 
and  |V - E|  :=  |{}|  := 

complement rule for counting

|S| a.k.a. |~S| :=  |U| - |S|

e.g. (using material from earlier lecture module)
suppose U is {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}
and V is {a,e,i,o,u}
then  |U| := ,  |V|  :=  ,
|U| - |V|  :=    := 
and |V| a.k.a. |~V| :=  |{}|  :=  



the pigeonhole principle

suppose we have n objects in a set S
    so |S| := 
and suppose we partition S into k subsets {S1,S2,...,Sk}
    so Si  := S
then it must be true that for at least one of the little sets, say Sx,
|Sx| ≥ ⌈n/k⌉.

in particular if  k := n-1,
then at least one of the little sets contains
at least  ⌈n/(n-1)⌉ :=  elements
e.g. if 9 pigeons are in 8 boxes,
then at least one of the boxes contains at least  pigeons
e.g.:
       
or:
       
or:
       

another e.g. but with k different from n-1:
if k:= sheets of paper distributed
and n:= names written on them,
then it must be true that at least one sheet (set of names)
contains at least  ⌈/⌉ :=  names written on it

explanation of pigeonhole principle
suppose the pigeonhole principle wasn't true:
suppose some n-element set S could be partitioned into {S1,S2,...,Sk} with none of these |Sx| ≥ ⌈n/k⌉
then for each of these subsets S1,S2,...,Sk,
|Si| < ⌈n/k⌉
then if n/k is an integer, |Si| < n/k
and actually if n/k is not an integer, |Si| < n/k
so either way, each |Si| < n/k
then by the sum rule,
|Si| :=      |S1| + |S2| + |S3| + ... + |Sk|

then by transitivity, |Si|  <  n.
but then we have a contradiction:
{S1,S2,...,Sk} was supposed to be a partition of S
i.e. all the n elements of S were supposed to appear somewhere in S1,S2,...,Sk
but adding together the sizes of S1,S2,...,Sk yields a value less than n!?! ridiculous!
therefore that hypothetical situation in which the pigeonhole principle doesn't hold can't happen,
i.e. the pigeonhole principle must always be true.



another e.g. 'fun' application of pigeonhole principle: Ramsey number R(3,3):
each person write name in one of slots on form
and then draw either a blue line or a green line between each pair of names
you choose which color
(if you can't decide any other way, try flipping coin ;-)
please not all lines on form same color: that would be boring



here  is the minimum number of people or points
for which it must be true that
if they're all connected by lines which are one of two colors,
then there are at least 3 items for which
all the lines connecting these 3 items are all the same color;
if the number of points is less than 6,
then can choose one of two colors for each line between points while avoiding having any all-one-color triangle using the points
you can try this here (to change an individual line's color, click it):


the notation for this is R(3,3) := 
and 6 is called a "Ramsey number"

the ≈next Ramsey number is as follows:
is the minimum number of points
for which it must be true that
if they're all connected by lines which are one of two colors,
then there are at least 4 points for which
all the lines connecting these 4 points are all the same color
i.e. R(4,4) := 
try here

the ≈next Ramsey number after that is :
is the minimum number of points
for which it must be true that
if they're all connected by lines which are one of two colors,
then there are at least 5 points for which
all the lines connecting these 5 points are all the same color
i.e. R(5,5) := 
(we do know that the value is between  and )

if you calculate R(5,5), the world would be impressed

(see also MTH 325)

permutations

i.e. order-rearrangements

one application: analyzing sorting — determining space of alternatives

the basic question here is as follows:
suppose have n distinct objects,
say {a,b,c,...} with |{a,b,c,...}| := n,
in how many different orders i.e.  can such n distinct objects be placed?
e.g. what are the different unsorted orders in which n objects to be sorted might be given to sort in array  A[]'s slots A[0],A[1],A[2],...,A[]?
e.g. if the n people in this room were supposed to stand in a line
(by the way not allowing repetition e.g. not h,h,h,...)
well, there are  choices for item placed in slot  A[0]:
    any one of {a,b,c,...}; say 
then, there are  choices for item placed in next slot  A[1]:
    any one of  ({a,b,c,...} – {}) ; say 
then, there are  choices for item placed in next slot  A[2]:
    ({a,b,c,...} – {,})
then, there are  choices for item placed in next slot  A[3]
and so on...
there are  choices for item placed in slot  A[i]
. . .
near the end of the process,
there are  choices for item placed in slot  A[n-2]
and finally, there is  choice for item placed in last slot  A[n-1]
then by fundamental product rule for counting,
total num. choices is n*(n-1)*(n-2)*···*3*2*1
the expression    represents that product

e.g. when my wife and I were shopping for our house here in the Grand Rapids area,
our realtor chose 7 houses for us to see one day;
we met near one of them, and then drove around checking them
in an order that our realtor had mapped out
hopefully in an efficient route;
technically, how many different orderings of these 7 houses might be considered to find the most efficient route? 
is there a way to find the most efficient route
faster than considering all  orderings?


what if the number of slots to fill is a number k that may be smaller than the number of objects, n?
same objects |{a,b,c,...}| := n,
but slots only  A[0],A[1],A[2],...,A[], not necessarily all the way to n-1
e.g. if at some point I call on k:=5 of the say n:=24 students in this class,
(by the way discounting repetition e.g. not h,h,h,h,h)
how many different sequences/lists of k=5 might arise?
e.g.  or  or  or  or ...
called "k-permutations of n elements"
well, there are  choices for item placed in slot  A[0]:
    any one of {a,b,c,...}; say 
then, there are  choices for item placed in next slot  A[1]:
    any one of  ({a,b,c,...} – {}) ; say 
then, there are  choices for item placed in next slot  A[2]
    ({a,b,c,...} – {,})
then, there are  choices for item placed in next slot  A[3]
and so on...
there are  choices for item placed in slot  A[i]
. . .
and processing stops with  choices for item placed in slot  A[k-1]
then by fundamental product rule for counting,
total num. choices here is
we use notation "P(n,k)" for this number of k-permutations of n elements
e.g. P(24,5) := 
another e.g. (using numbers more tractable than  ;-)
    P(7,4) := 
                := 
                := 
                := 

for any n, P(n,1) := 
for any n, P(n,0) := 
for any n, P(n,n) := 


incidentally the case with rep. allowed yields 

combinations

is a set S whose cardinality |S| is k
e.g.  or  or  or ...
but note {a,b,c,e,d} same combination as {a,b,c,d,e}
    though different permutations

Definition
"C(n,k)" a.k.a. "n choose k" a.k.a. "nCk" a.k.a. "(nk)"
is supposed to be the count of how many k-combinations there are using n elements
    say a1,a2,a3,...,an
i.e., C(n,k) :=  |{ S :  S ⊆ {a1,a2,...,an}  and  |S| == k }|
e.g. for C(5,3), using total n:=5 elements {a1,a2,a3,a4,a5},
    count 3-combinations of those, i.e. sets containing 3 of them:
    C(5,3) :=  |{ {a1,a2,a3}, {a1,a2,a4}, {a1,a2,a5},
                                {a1,a3,a4}, {a1,a3,a5}, {a1,a4,a5},
                                {a2,a3,a4}, {a2,a3,a5}, {a2,a4,a5},
                                {a3,a4,a5} }|
                  :=  
e.g. for C(4,2), using total n:=4 elements {a1,a2,a3,a4},
    count 2-combinations of those, i.e. sets containing 2 of them:
    C(4,2) :=  |{ {a1,a2}, {a1,a3}, {a1,a4},
                                {a2,a3}, {a2,a4}, {a3,a4} }|
                  :=  
e.g. for C(4,1), using total n:=4 elements {a1,a2,a3,a4},
    count 1-combinations of those, i.e. sets containing 1 of them:
    C(4,1) :=  |{ {a1}, {a2}, {a3}, {a4} }|
                  :=  
e.g. for C(4,4), using total n:=4 elements {a1,a2,a3,a4},
    count 4-combinations of those, i.e. sets containing 4 of them:
    C(4,4) :=  |{ {a1,a2,a3,a4} }|
                  :=  
e.g. C(3,2) :=  |{ S :  S ⊆ {a1,a2,a3}  and  |S| == 2 }|
                        :=  
e.g. C(3,3) :=  |{ S :  S ⊆ {a1,a2,a3}  and  |S| == 3 }|
                        :=  
e.g. C(3,1) :=  |{ S :  S ⊆ {a1,a2,a3}  and  |S| == 1 }|
                        :=  
e.g. C(3,0) :=  |{ S :  S ⊆ {a1,a2,a3}  and  |S| == 0 }|
                        :=  

Proposition:
C(n,k)
can be calculated as follows:
           ⌈ 1   if  k == 0 or k == n
C(n,k) :=  |   or
           ⌊ C(n-1, k-1) + C(n-1, k)   otherwise
called "Pascal's Identity"

e.g. C(4,2) :=  C(,) + C(,)  :=  := 
e.g. C(3,1) :=  C(,) + C(,)  :=  := 
e.g. C(4,3) :=  C(,) + C(,)  :=  := 
e.g. C(5,3) :=  C(,) + C(,)  :=  := 

Explanation     // for certification as well as deeper understanding
  • when k = 0 or k = n,
    C(n,0) or C(n,n) should be clearly 1 (considering examples above)

  • otherwise, when 0 < k < n,
    by definition C(n,k) is |C| where C is
    { S :  S ⊆ {a1,a2,...,an}  and  |S| = k }
    well,
    let C1 := { S :  S ⊆ {a1,a2,...,an}  and  |S| = k  and  an ∈ S }
    and C2 := { S : S ⊆ {a1,a2,...,an}  and  |S| = k  and  an ∉ S }
    e.g. C(5,3) is |C|
        where  C := |{ S :  S ⊆ {a1,a2,a3,a4,a5}  and  |S| = 3 }|
        in which case
        C1 := { {a1,a2,a5}, {a1,a3,a5}, {a3,a4,a5}, {a2,a4,a5},
                        {a1,a4,a5}, {a2,a3,a5} }
        C2 := { {a1,a2,a3}, {a2,a3,a4}, {a1,a3,a4}, {a1,a2,a4} }
    then clearly  C == C1 ∪ C2  and  C1 ∩ C2 == ∅
    so  |C| := |C1| + |C2|  // by inclusion-exclusion or sum rule
    further,
    the specification for C1 (above) implies
    C1 == { S :  S = S' ∪ {an} where S' ⊆ {a1,a2,...an-1} and |S'| == k-1 }
        e.g. C1 == { {a1,a2}∪{a5}, {a1,a3}∪{a5}, {a3,a4}∪{a5}, {a2,a4}∪{a5}, {a1,a4}∪{a5}, {a2,a3}∪{a5} }
    which implies
    |C1| := | { S' :  S' ⊆ {a1,a2,...an-1}  and  |S'| == k-1 } |
        e.g. |C1| := | { {a1,a2}, {a1,a3}, {a3,a4}, {a2,a4}, {a1,a4}, {a2,a3} } |
    but  is defined to be precisely that value on the right
        e.g. C(4,2)

    similarly,
    the specification for C2 (above) implies
    C2 := { S :  S ⊆ {a1,a2,...,an-1} and |S| = k }
    which implies
    |C2| := |{ S such that S ⊆ {a1,a2,...,an-1} and |S| = k }|
    and  is defined to be precisely that size on the right
        e.g. C(4,3)

    summarizing, when 0 < k < n,
    C(n,k) := |C| :=  |C1| + |C2|  :=  C(n-1,k-1) + C(n-1,k)

    Q.E.D.

    (incidentally, an adjective used to describe explanations like this
    is )

    using Pascal's Identity,
    can make chart of values of C(n,k) as follows:
                                  C(0,0):=1
    
                            C(1,0):=1       C(1,1):=1
                                     \  +  /
                      C(2,0):=1       C(2,1)      C(2,2):=1
                               \  +  /     \  +  /
                C(3,0):=1       C(3,1)      C(3,2)      C(3,3):=1
                         \  +  /     \  +  /     \  +  /
          C(4,0):=1       C(4,1)      C(4,2)      C(4,3)      C(4,4):=1
                   \  +  /     \  +  /     \  +  /     \  +  /
    C(5,0):=1       C(5,1)      C(5,2)      C(5,3)      C(5,4)      C(5,5):=1
    
    and so on
    where each C(n,0):=1, each C(n,n):=1,
    and every other C(n,k) is obtained by adding the two entries to the left and right above C(n,k)

    called Pascal's Triangle

    incidentally,
    people have connected number theory with mysticism for thousands of years
    you may know name "Pythagorean" just re property of right-angle triangles
        *
        |\
       b| \c
        |  \
        +---*
          a
    
    a2 + b2 == c2
    e.g. 52 + 122 == 132
    but Pythagoreans were a 


    similarly intriguing properties of Pascal's triangle:

    e.g. add a line of entries for a while
        e.g. 1 + 3 + 6 + 10 := 
        e.g. 1 + 5 + 15 := 


    another e.g. intriguing property: consider any entries that form a hexagon
    e.g. as follows:
          6*   4  
    
       10  (10)  5* 
    
          20*  15
    
    the hexagon's perimiter's numbers can be considered as forming two triangles —
    here one triangle comprising the numbers marked with "*",
    the other triangle comprising the numbers not marked with "*"
    then consider the products of the triangles' numbers:


    called the "hexagon identity" in our textbook's Exercise 5.4.20
    or called the "star" property by David Logotheti, the mathematician who showed this property to me

    another e.g. property of Pascal's Triangle:
    1  := 
    1 + 1  := 
    1 + 2 + 1  := 
    1 + 3 + 3 + 1  := 
    1 + 4 + 6 + 4 + 1  := 
    1 + 5 + 10 + 10 + 5 + 1  := 
    1 + 6 + 15 + 20 + 15 + 6 + 1  := 
    
    another e.g. property of Pascal's Triangle:
     
    / 
     / 
    1 / 
     / / 
    1 1 / 
     / / / 
    1 2 1 / 
     / / / /
    1 3 3 1
     / / /
    1 4 6 4 1
     / /
    1 5 10 10 5 1
     /
    1 6 15 20 15 6 1
    
    (will discuss later in this course)



    anyway,
    how might one calculate C(17,4)?
    if use Pascal's identity straightforwardly:
    C(17,4) := C(16,3) + C(16,4)
            := [C(15,2) + C(15,3)] + [C(15,3) + C(15,4)]
            := ([C(14,1) + C(14,2)] + [C(14,2) + C(14,3)]) + ([C(14,2) + C(14,3)] + [C(14,3) + C(14,4)])
               /      \
            C(13,0) + C(13,1)
               1     /      \
                  C(12,0) + C(12,1)
                     1        .             .
                              .             .               .
                              .             .               .
    


    yes:
                  n*(n-1)*(n-2)*...*(n-(k-1))  } #factors is k
       C(n,k) :=  ---------------------------
                  k*(k-1)*(k-2)*...*  1
    
                                   n!
    which also happens to equal ---------
                                k!*(n-k)!
    
    e.g. according to this formula,
               9*8*7     504
    C(9,3) :=  -----  := --- := 84
               3*2*1      6
    
    or more 'intelligently' a.k.a. lazily (;-) :
               3 4
               9*8*7   
    C(9,3) :=  -----  := 3*4*7 := 84
               3*2*1  
    
    another e.g.
                    4  5  7
                17*16*15*14
    C(17,4) :=  -----------  := 17*4*5*7 := ...
                  4*3*2*1  
    
    justification of this formula for C(n,k):
    again, what is C(n,k)? the number of ways of making sets of size k from among n things
    well, think about the process of making a set of size k
    from among n things {a,b,c,d,e,...,n}:
    { _ , _ , _ , ..., _ }
     1st 2nd 3rd      k-th
    
    from earlier discussion of permutations (above),
    if choose the k things in order and maintain the order,
    the number of choices is P(n,k) which is
    n*(n-1)*(n-2)*...*(n-(k-3))*(n-(k-2))*(n-(k-1))
    but here we'd be counting some sets more than once
    e.g. {d,b,e,c,a} and {b,d,e,c,a} and {e,b,c,d,a} and {a,b,c,e,d}
        getting same set but with elements in different orders
    to handle this issue,
    divide P(n,k) by the number of multiples of each k-combination set
    which is the number of different orders of k things
    which (from earlier earlier discussion above) is k!
    // each k-combination set arises k! multiple times
    which is k*(k-1)*(k-2)*...*1
    thus result is
    n*(n-1)*(n-2)*...*(n-(k-1))
    ---------------------------
    k*(k-1)*(k-2)*...* 1
    
    and (as mentioned earlier) that happens to equal n!/(k! * (n-k)!)
    shown as follows:
    
        n!          n*(n-1)*(n-2)*...*(n-(k-1))*(n-k)*(n-(k+1))*(n-(k+2))*...*3*2*1
     ---------  :=  ---------------------------------------------------------------
     k!*(n-k)!      [k*(k-1)*(k-2)*...* 1]  * [(n-k) * (n-k-1) * (n-k-2) *...*3*2*1
    
        n!          n*(n-1)*(n-2)*...*(n-(k-1))*(n-k)*(n-(k+1))*(n-(k+2))*...*3*2*1
     ---------  :=  ---------------------------------------------------------------
     k!*(n-k)!      [k*(k-1)*(k-2)*...* 1]  * [(n-k) * (n-k-1) * (n-k-2) *...*3*2*1
    
                    n*(n-1)*(n-2)*...*(n-(k-1))
                :=  ---------------------------
                    k*(k-1)*(k-2)*...* 1
    


    which formula best for calculating actual value e.g. C(17,4)?

    e.g. done above



    ≈applications of the formula n!/(k! * (n-k)!) for C(n,k):

  • hexagon identity a.k.a. star-property
    look again at the example above:
            C(4,2):6*       C(4,3):4
    
        C(5,2):10   [C(5,3):10]     C(5,4):5*
    
            C(6,3):20*      C(6,4):15
    
    C(4,2):6 * C(5,4):5 * C(6,3):20  :=  600
        ==  C(4,3):4 * C(5,2):10 * C(6,4):15
    
    as stated this should occur with any hexagon of entries
    in general if the middle element is C(n,k), then the other relevant entries are as follows:
            C(n-1,k-1)*     C(n-1,k)
    
        C(n,k-1)    [C(n,k)]        C(n,k+1)*
    
            C(n+1,k)*       C(n+1,k+1)
    
    so the question is whether the following is true in general?
    C(n-1,k-1) * C(n,k+1) * C(n+1,k)
            =?= C(n-1,k) * C(n,k-1) * C(n+1,k+1) ?
    we can confirm that this is indeed true
    by using the formula for C(x,y) that involves factorials:
                      x!
       C(x,y) :=  -----------
                  y! * (x-y)!
    
    using that formula for C(n-1,k-1) etc. yields the following:
            (n-1)!                    n!                 (n+1)!
    ----------------------- * ------------------- * ---------------
    (k-1)! * [(n-1)-(k-1)]!   (k+1)! * [n-(k+1)]!   k! * [(n+1)-k]!
    
                  (n-1)!              n!                      (n+1)!
        =?=  --------------- * ------------------- * -----------------------  ?
             k! * [(n-1)-k]!   (k-1)! * [n-(k-1)]!   (k+1)! * [(n+1)-(k+1)]!
    
    this equation can be seen to hold because
    each side's numerator comprises the same factors (n-1)!, n!, and (n+1)!
    and each side's denominator comprise the following:
    * clearly (k-1)!, k!, and (k+1)!
    * [(n-1)-(k-1)]! which is (n-k)! which is [(n+1)-(k+1)]!
    * [n-(k+1)]! which is (n-k-1)! which is [(n-1)-k]!
    * [(n+1)-k]! which is (n-k+1)! which is [n-(k-1)]!


  • another confirmation of Pascal's Identity:
               ⌈ 1   if  k == 0 or k == n
    C(n,k) :=  |   or
               ⌊ C(n-1, k-1) + C(n-1, k)   otherwise
    
    well, first consider the value of n!/(k! * (n-k)!) when k = 0 or k = n:
        n!             n!
    -----------  :=  -------  :=  
    0! * (n-0)!       * n!
    
        n!              n!          n!
    -----------  :=  -------  :=  ------  :=  
    n! * (n-n)!      n! * 0!      n! * 1
    
    and otherwise, when 0 < k < n,
    want C(n,k) = C(n-1,k-1) + C(n-1,k)
    well:

    as desired


    the binomial theorem

    a further important property of values of C(n,k):
    (x + y)n := C(n,0)*xn-0y0 + C(n,1)*xn-1y1 + C(n,2)*xn-2y2 + ... + C(n,n)*xn-nyn

    e.g. (x+y)² := 
    e.g. (x+y)³ := 
    e.g. (x+y)4 := 

    applications of binomial theorem:

  • sum of values of row n of Pascal's triangle yields 2n
    (as considered above for first few rows)
    using binomial theorem,
    (1 + 1)n := C(n,0)*1n-010 + C(n,1)*1n-111 + C(n,2)*1n-212 + ... + C(n,n)*1n-n1n
                2n := C(n,0) + C(n,1) + C(n,2) + ... + C(n,n)

  • summing C(n,i)*2i across row n of Pascal's triangle yields 3n
    e.g. for row 4,  1*20 + 4*21 + 6*22 + 4*23 + 1*24 := 
    using binomial theorem,
    (1 + 2)n := C(n,0)*1n-020 + C(n,1)*1n-121 + C(n,2)*1n-222 + ... + C(n,n)*1n-n2n
                3n := C(n,0)*20 + C(n,1)*21 + C(n,2)*22 + ... + C(n,n)*2n


    (Copyright © 2009 by Hugh McGuire   — for thoughts about this, see   http://www.cis.gvsu.edu/~mcguire/teaching/copyright_thoughts.html .)