Thursday, 23 July 2015

Factorial (n!) - Symmetry in nature II

Factorials are very simple things. They're just products, indicated by an exclamation mark. For instance, "four factorial" is written as "4!" and means 1×2×3×4 = 24
For n=0,
0! = 1

The factorial operation is encountered in many areas of mathematics, notably in combinatoricsalgebra, and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of the set of objects). This fact was known at least as early as the 12th century, to Indian scholars.

Factorial definition formula

n!=\begin{Bmatrix}1 & ,n=0 \\ \prod_{k=1}^{n}k & ,n>0\end{matrix}
Examples:
1! = 1
2! = 1×2 = 2
3! = 1×2×3 = 6
4! = 1×2×3×4 = 24
5! = 1×2×3×4×5 = 120

Recursive factorial formula

n! = n×(n-1)!
Example:
5! = 5×(5-1)! = 5×4! = 5×24 = 120

Applications : 

Permutation Formula

A formula for the number of possible permutations of k objects from a set of n. This is usually written

nPr = n(n - 1)(n - 2) ... (n - r + 1) =n!(n - r)!



Example : How many ways 4 students from a group of 15 be lined up for a photograph ?

Answer :  There are 15P4     possible permutations of 4 students from a group of 15.
                        15P4  = 15! / 11! = 15 * 14 * 13 * 12 = 32760 different lineups.

 Combination Formula

A formula for the number of possible combinations of r objects from a set of n objects. This is written in any of the ways shown below

nCr =n!=n(n - 1)(n - 2) ... to r factors.(r!)(n - r)!r!

Note:
  1. nCn = 1 and nC0 = 1.
  2. nCr = nC(n - r)
 ExampleHow many different committees of 4 students can be chosen from a group of 15?
 AnswerThere are  possible combinations of 4 students from a set of 15
 = 15! / 4!11! = (15 * 14 *3) / (4 * 3 *2  *1 ) = 1365 





  public static long dnrFactorial(int n)  
       {  
         int c;    
         long result = 1;  
         for( c = 1 ; c <= n ; c++ )  
              result = result*c;  
              return ( result );  
       }  


Recursive Function : 


  public static long dnrFactorialRecursive(int n)  
       {  
            if (n == 0)  
                 return 1;  
            else  
                 return n * dnrFactorialRecursive(n-1);  
       }  

No comments:

Post a Comment