1.3 mathematical prerequisites
A Set is a whole composed of Some deterministic members (Member) or elements. A member is taken from a larger range and is called a Base Type ). The number of members in a collection is called Cardinality ).
Set features:
1) certainty: Any object can be accurately determined to be an element or not in a set.
2) Interaction: Elements in the set cannot be repeated.
3) No sequence: the element in the set is irrelevant to the sequence.
1.3.4 Recursion
If an algorithm calls itself directly or indirectly, it is called a Recursive algorithm ). Depending on the call method, it can be divided into Direct Recursion and Indirect Recursion ).
Recursive Algorithms are generally not the most effective computer programs to solve the problem. Because recursion includes function calls, the time-space overhead of function calls is required.
Factorial (factorial) function:
C ++ Codes:
[Cpp] // Algri. h
# Ifndef ALGRI_H
# Define ALGRI_H
Int factorial (int n );
# Endif
// Algri. h
# Ifndef ALGRI_H
# Define ALGRI_H
Int factorial (int n );
# Endif [cpp] // Algri. cpp
# Include "Algri. h"
# Include "stdafx. h"
Int factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * factorial (n-1 );
}
// Algri. cpp
# Include "Algri. h"
# Include "stdafx. h"
Int factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * factorial (n-1 );
}
Python Codes:
[Python] "Algri. py"
Def factorial (n ):
If n <= 0:
Return-1;
Elif n = 1:
Return 1;
Else:
Return n * factorial (n-1 );
"Algri. py"
Def factorial (n ):
If n <= 0:
Return-1;
Elif n = 1:
Return 1;
Else:
Return n * factorial (n-1); [python] "Program. py"
From Algri import factorial
Print factorial (10)
"Program. py"
From Algri import factorial
Print factorial (10) C # codes:
[Csharp] class Program
{
Static void Main ()
{
Console. WriteLine (Factorial (10 ));
}
Static int Factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * Factorial (n-1 );
}
}
Class Program
{
Static void Main ()
{
Console. WriteLine (Factorial (10 ));
}
Static int Factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * Factorial (n-1 );
}
}
From. from the perspective of Net, the so-called set can be defined as an object, which provides a structured way to organize arbitrary objects and implements one or more icollections, IDictionary, and System. collections. IList interface. This definition divides the "built-in" set in the System. Collections namespace into three categories:
(1) Ordered Set: a set that only implements the ICollection interface. For example, Stack and Queue.
(2) index set: the set of IList is implemented, and its content is retrieved from digits starting from scratch. For example, ArrayList.
(3) Key set: the set that implements the IDictionary interface. The content of the IDictionary set is usually stored by pressing the key value. For example, Hashtable class.
From xufei96's column