Summary: This chapter introduces probability analysis and Random Algorithms Based on employment issues. Probability Analysis is generally used to determine the running time of some algorithms. The randomization algorithm is used to force the input of the algorithm to conform to a certain probability distribution. The behavior of the randomization algorithm is determined not only by the input, but also by the value generated by a random number generator.
1.Probability Analysis
You can use random indicator variables for probability analysis to obtain the expected values of events.
Theorem: given event a in Sample Space S and S, if XA = I {A}, E [xa] = Pr {}
2.Random Algorithm
Probability Analysis assumes input. In a random algorithm, random occurs on the algorithm rather than on the input distribution, that is, for the same input, due to the introduction of random algorithms, the final arrangement also changes. This makes "even your worst enemy cannot generate the worst input series, because random sorting makes the input order irrelevant, the random algorithm runs poorly only when the random number generator generates an unlucky replacement ".
Method for randomly arranging Arrays
1) assign a random priority P [I] to each element a [I] of the array, and sort the elements in array A according to the priority. Sorting here will take O (nlgn) time.
Pseudocode
Permute-by-sorting
N <-length [A]
For I <-1 to n
Do P [I] = random (1, n ^ 3)
Sort a, using P as sort keys
Return
Theorem: Assuming that all priorities are unique, the permute-by-sorting process can generate an even and random arrangement of input.
2) arrange the given sequence in the same place. Completed in O (n) time.
Pseudocode
Randomize-in-place ()
N <-length [A]
For I <-1 to n
Do swap a [I] <-> A [random (I, n)]
The process randomize-in-place can calculate an even random arrangement.