Outbound serialization:
1. randomization algorithm (1)-Random Number
2. randomization algorithm (2)-numerical probability algorithm
3. randomization algorithm (3)-Sherwood Algorithm
4. randomization algorithm (4)-Las Vegas Algorithm
Body:
Monte Carlo Method(Monte Carlo method) is a calculation method based on the theory and method of probability and statistics. It associates the problem solved with a certain probability model, statistical Simulation or sampling is implemented by using an electronic computer to obtain the approximate solution of the problem, which is also known as the statistical simulation method or statistical test method.
In general, the Monte Carlo algorithm can ensure that all instances of the problem are correctly resolved with a high probability, but it is usually impossible to determine whether a specific solution is correct.
Set p to a real number, and 1/2 <p <1. If a Monte Carlo algorithm returns a correct solution to any instance of the problem with a probability not less than p, the Monte Carlo algorithm is calledP correctAnd p-1/2 is the algorithm.Advantages. For the same instance, the Monte Carlo algorithm does not provide twoDifferentCorrect answer, the Monte Carlo algorithm isConsistent.
In addition to the input parameters that describe the problem instance, some Monte Carlo algorithms also have parameters that describe the acceptable probability of an error solution. The computing time complexity of these algorithms is generally described by the instance scale of the problem and the function of accepting the error solution probability. For a consistent p correct Monte Carlo algorithm, to increase the probability of obtaining the correct solution, you only need to execute the algorithm several times and selectHighest frequency.
For a Monte Carlo algorithm MC (x) that solves the given problem, if the subset X of the problematic instance causes:
(1) When x does not belong to X, the solution returned by MC (x) is correct;
(2) When x belongs to X, the correct solution is y0, but the solution returned by MC (x) is not necessarily y0.
The preceding algorithm MC (x) isBiasedY0Algorithm.
In this chapter, the Monte Carlo algorithm does not need to be discussed in detail, because Wang Xiaodong's book has a lot of details and concepts, and there are a lot of resources for this algorithm on the Internet. If I talk about it more, it's just a bit fascinating. In the Chinese community of mathematics, I saw this section called the Monte Carlo algorithm. You can check it out.
Here, I will only giveMain element problems:Set T [1: n] to an array containing n elements. When | {I | T [I] = x} |> n/2, the element x is of the array T.Main Element. The following code is used:
/*
* Author: Tanky woo
* Blog: www.WuTianQi.com
* Date: 2010.12.9
* The Monte Carlo algorithm solves the primary element problem.
* The Code comes to Wang Xiaodong's computer algorithm design and analysis
*/
# Include "RandomNumber. h"
# Include <iostream>
# Include <cmath>
Using namespace std;
RandomNumber rnd;
Template <typename Type>
Bool Majority (Type * T, int n)
{
// Monte Carlo algorithm for determining the primary element
Int I = rnd. Random (n) + 1;
Type x = T [I]; // randomly select array elements
Int k = 0;
For (int j = 0; j <n; ++ j)
If (T [j] = x)
++ K;
Return (k> n/2 );
}
Template <typename Type>
Bool MajorityMC (Type * T, int n, double e)
{
// Call the algorithm Majority repeatedly
Int k = ceil (log (1.0/e)/log (2.0 ));
For (int I = 1; I <= k; ++ I)
If (Majority (T, n ))
Return true;
Return false;
}
Int main ()
{
Int arr [10] = {3, 5, 7, 3, 9, 3, 3, 1, 3 };
Cout <majoritymc (ARR, 10, 0.1) <Endl;
Return 0;
}
I will find some good information about the Monte Carlo algorithm on the Internet and add it to this article for you to download.
In the next article, I should write the randomization algorithm (6)-some probability questions.
Tanky Woo is original. You are welcome to repost it. Please attach a link for reprinting. Please do not delete any links to this blog in this article without permission.
Tanky Woo Tag: Monte Carlo algorithm, Monte Carlo, randomization algorithm