The algorithm study notes recursive algorithm

The algorithm study notes recursive algorithm

Reference: "Informatics Olympiad through a fifth edition of" directory:

Foreword

01. What is the recursive algorithm

02. preliminary understanding of recursive algorithm

03. Classic recurrence relation:

1.Fibonacci (Fibonacci) series

2.Hanio (Tower of Hanoi) problem

3. plane segmentation

4.Catalan数

The Stirling number of second kind

04. Conclusion

Foreword

Recursive algorithm is a very broad application of algorithms, today we have to learn together, recursive algorithm. First, we need to learn recursive algorithm basic understanding of it.

01. What is the recursive algorithm

Recursive algorithm is a very broad application of the algorithm. OI is not only widely in industry applications, and have applications in various fields of mathematics, so that the recursive algorithm can solve many problems. Recursive algorithm is based on conditions known to derive the unknown condition. This way you can deal with the problem of the original complex operations into several simple step and repeat the operation, give full play to the computer is good at processing information duplicate features. After time we will learn dynamic programming recursive algorithm to use, and the relationship between the two are inseparable.

02. preliminary understanding of recursive algorithm

To use the recursive algorithm, we must first find the boundary conditions and subject to write recursive formula, so the next step to continue. Recursive algorithm, as long as you can write recursive formula and boundary conditions, then you this program has been successful in half, then as long as you pay attention to other details, then you will be able to pass this program.

03. Classic recurrence relations

Classic recurrence relation total is divided into five categories, namely: Fibonacci series, Hanio tower issue, split plane issues, Catalan and the number of the second kind Stirling numbers.

1.Fibonacci (Fibonacci) series

In all recursive relationships, Fibonacci series should be the most widely known as a recursive relationship, and therefore, its solution is relatively simple. The most famous Fibonacci sequence in question is a famous Italian mathematician Fibonacci in the year of 1202's "rabbit reproductive problems" face the question is this: there is a new pair of male and female rabbits over two months can be assumed to breed a male and a female one pair bunnies, Q: how many rabbits (provided that during this time the rabbit will not die) after over n months. Solution: Let n full months after a total of rabbit f pairs, where the number of new-born rabbit current month is f (n) pair. The n-1 month after the number of remaining rabbits assumed to F (n-1) pair, boundary condition is f (0) = 0; f (1) = 1; then the recursive formula is: f (n) = f (n-1) + f (n-2) Note: there are many series problems can be abstracted as Fibonacci number or deformation of its transformation, which is a classic recurrence relations, extremely versatile.

2.Hanio (Tower of Hanoi) problem

Tower of Hanoi is the second class classical recursion relations. Towers of Hanoi problem can be considered a more classic recursive topic. See Title: Hanio column by n different disc sizes three wooden pillars and a, b, c the composition. Initially, the n sets of disks in descending order in a column. The column requires a disc according to the following rule of n c is moved to column 1. 2. The disc can only be moved a disc can be stored in the three column 3. In the process of moving, the market does not allow a small pressure n disks from these interrogations a column c is moved to column requires a total number of times the disc move. 

Solution: This question requires us to obtain the total number of disks times need to move, then we need to analyze the boundary conditions and recursive formula is given in accordance with the requirements, so the first thing we need to analyze the meaning of the questions, and then were based on questions asked write the boundary conditions and recursive conditions. First, let f [n] is required to move a column from the column c is moved to the secondary disk. Obviously, when n is equal to 1, only needs to move the plate directly to a column like column c, the f [n] = 1. When n is equal to 2 when the first column of a minimum to move the plate column b, and then move a platter column to column c, and b from the minimal plate column c is moved to column, so that, when n is equal to 2 when, f [n] = 3 , which is the need to move three times. So, when there are n disks a column (Tip: n> = 2), always the first to the n + 1 is moved to the upper plate by means of column b c columns, then a lowermost column plate movement c to the column and then the column by means of a plate b n-1 th column c is moved to column, a total mobile f [n-1] + 1 + f [n-1] times disks. Thus, the recursive formula is f [n] = 2f [n-1] +1, the boundary f [1] = 1

3. plane segmentation

Refers to a plane dividing a question: Suppose there are n closed curves drawn on the plane, and any two closed curves exactly at two points, and any three non-intersecting closed curve at the same point, the plane closed curve Q which It is divided into the number of regions. Solution: Let F [n] to the plane of the closed curve is divided into a number of n. We can launch a formula by drawing the way. Hold the picture here, you can own paintings. Therefore, according to this, we can see f [2] -f [1] = 2; f [3] -f [2] = 4; f [4] -f [3] = 6. From these formulas we introduced to, we can see f [n] -f [n-1] = 2 [n-1]. Recurrence formula is f [n] = f [n-1] +2 [n-1], the boundary conditions of a [1] = 1. Of course, the conclusion here is that we observed and by drawing four figures come, just to give solution, and correctness has yet to be proven.

4.Catalan数

Catalan Euler number obtained by the first calculation of the exact number of problems convex deformation n different diagonal triangular split time, it is often a problem occurs in the combination of the count. Problem: In a convex polygon n by the n-gon disjoint interior diagonal, the n-gon split into several triangles, the number of different resolution [n] is represented by f, f [n ] That is the number of Catalan. For example, there are five pentagon split manner, the f [5] = 5. Seeking for an arbitrary polygon corresponding projection n f [n0].

Solution: Suppose f (n) is the total program convex polygon split number n. Conditions given by the subject that we know: a convex polygon of n sides are bound to be any one of a triangle in which one side while q (1), q (n) Similarly, we then in accordance with "not in the same one three points on the straight line can be confirmed as a triangle ", (a), as long as the q-q (2), q (3) ...... q (n-1) q o'clock to find a point (. 1) , q (n) constitute three vertexes of a triangle. N-gon will be divided into three disjoint portions, respectively, we call the region A, region B, region C, which is bound to a triangular region C, the region A is a convex n-gon, area B an a-n + 1-sided polygon, the total number of split programs region a is a (n) types of split programs total area B a (a-n + 1). For the convenience of calculation, the boundary condition agreed f (n) = 1.

The Stirling number of second kind

In a typical five recurrence relation, the second kind Stirling numbers are little known. It is also because of this, we must first explain the Stirling numbers of the second kind is what it is. Defined: n a differentiated into several identical boxes m, the requirement is no empty cassette, wherein the different schemes used, A (N, M) to said Stirling number of second kind referred to. Stirling numbers of the second kind occurs in less competition, but competition also has some problems with its similar, or even more complex.

Conclusion

Through the above five kinds of classical recurrence relations established during the discussion, the subject can be known to treat the recurrence classes to specific conditions, to find a contact state with the previous state, so as to establish the corresponding recurrence relations.

 

Guess you like

Origin www.cnblogs.com/murongxueqing/p/11333922.html