About factorial Here's a quick explanation.
What is factorial?1X2X3X4X3 {5! Here's5! is calledThe factorial of 5, which is called Factorial, is named because the multiplier is descending in a ladder form, as follows:5! = 5x4x3x2x1 = -4! =4X3X2X1 =243! =3X2X1 =62! =2X1 =21! =1 =10! =1 noteFactorial of 00! is defined as1, this is the rule in mathematics.The factorial of n is as follows:N!=NX (N-1)X (N-2)X...X2X1 obviously n! is a recursive formula that also conforms to recursive thinking, so there is: when n=0 o'clock,n! = 1; when n>=1 o'clock,n x (N- 1) you can see that it uses factorial (n1)! To define factorial n! Is it similar to Hanoi? Yes, it is indeed the embodiment of recursive thinking. ok~, we have a simple understanding of the factorial.
?? The definition of a recursive algorithm (from the point of view of the program): Any procedure that invokes its own function can be called a recursive algorithm (the Hanoi program implemented earlier is a good example). It is important to note that the following two conditions must be met for recursion:
- ① boundary Condition: At least one of the initial definitions is non-recursive, such as Hanoi's H (0) = 0, factorial 0!=1.
- ② Recursive general formula: The value of the unknown function is calculated gradually by the known function value, such as the H (0) = 0 of the Hanoi, can be deduced H (1) =h (0) +1+h (0).
Boundary condition and recursive general formula are the two basic elements of recursive definition, and the recursive formula must achieve the boundary condition in the finite number of times to ensure the normal end of recursion and get the result of operation. Well, the above is the definition of recursion, or that sentence to understand good recursive thinking (complex problem simplification) is the focus!
---factorial algorithm of recursive thought