Analysis and exploration of dynamic programming algorithm

Source: Internet
Author: User

Analysis and exploration of dynamic programming algorithm



absrtact: Dynamic programming is a branch of operational research. It is a method to solve the optimization problem of multi-stage decision process. Dynamic programming is to optimize the generation of decision sequences in accordance with certain conditions. The dynamic programming thought is used frequently in various kinds of information science, and its function is more and more valued by people. In this paper, the dynamic programming algorithm is analyzed and explored to solve many problems in real life.

Introduction

The algorithm is a clear instruction to solve a series of problems and can obtain the required output within a limited time. A good algorithm is very helpful for solving one or a class of practical problems. Evaluate an algorithm is good or bad, mainly in two aspects (excluding the situation of error algorithm). One, the time merits and demerits, second, the space superiority and disadvantage of. The quality of time is the time it takes for different algorithms to solve this problem when dealing with the same problem. The efficiency of the algorithm is the expression of time in different ways. On the other hand, when dealing with the same problem, the resources (computer resources) required by different algorithms to solve the problem are mainly embodied in the memory resources occupied. In general, the merits of the algorithm are measured by time complexity and spatial complexity.

For an algorithm, it is not possible to determine whether the optimal algorithm can be explained by solving one or a class of problems alone. Because, for a class of problems, perhaps the complexity of the algorithm is lower than other algorithms, and the complexity of solving another type of problem may be higher than other algorithms. Therefore, there is no best algorithm, only the optimal algorithm for a practical problem, the time complexity and space complexity of the algorithm are lower than other algorithms.

1. Introduction to Dynamic planning

1.1 Basic ideas of dynamic programming

The essence of dynamic programming is to divide and cure the thought and solve redundancy, therefore, dynamic programming is an algorithm strategy to decompose the problem instances into smaller, similar self-problems, and to save the solution of sub-problems and avoid the calculation of repetitive self-problems.

The problem of dynamic programming is characterized by a significant duplication of sub-problems in the sub-problem tree. The key of the dynamic programming method is that, for the recurrence of sub-problems, only in the first encounter when the solution, and save the answer, so that later encountered when the direct reference, do not have to re-solve.

1.2 Dynamic Planning Classification

The dynamic programming according to its model can be divided into: knapsack model, the longest non-descending sub-sequence model, the largest segment and model, LCS model, segment coverage problem model, stock model, continuous segment Division model, game model and so on. One of the most common is the knapsack problem, for knapsack problem can be subdivided into: 0-1 knapsack problem, infinite knapsack problem, limited knapsack problem, valuable backpack, small backpack and other problems.

2. Dynamic Programming Key Terms

2.1 Stages

When solving a problem with dynamic programming, it is necessary to divide the whole process of the problem into several interrelated phases so as to solve it in a certain order. The division of the stage is generally based on the natural characteristics of time and space, and it is generally easy to transform the problem into a multi-stage decision-making process.

2.2 Status

The state represents the nature of a certain stage of a thing, and the state is described by a variable, which is called a state variable. Each state can be transformed from one to the other.

2.3 Decision Making

a certain selective action in the handling of the problem is decision-making. A practical problem may require multiple decisions, and one decision is required at each stage. Once a decision is taken from one stage to another, the state shifts.

2.4 Strategy and optimal strategy

at all stages, the whole process of solving the problem is arranged according to the agreed decision method. The overall of these decisions is called a strategy. In practical problems, the strategy of finding the optimal effect from the decision-making set is called the optimal strategy.

2.5 state Transition Equation

The end of the previous stage is the starting point of the latter stage, which describes the evolution of the state from the K stage to the k+1 stage, and is the equation about the state of two neighboring stages, called the state transfer equation, which is the core of the dynamic programming.

3, the use of dynamic planning conditions

Any method of thinking has certain limitations, beyond the specific conditions, it loses its role. Similarly, dynamic planning also needs to meet its conditions of use. To solve the dynamic programming problem must satisfy the optimization principle and the no-effect.

Optimization principle: Regardless of the past state and decision-making, to the state of the previous decision-making, the remaining decisions must constitute the optimal strategy. In short, the self-strategy of an optimization strategy is always optimal.


K

(Fig. 1)

As shown in 1, Route I and J are the optimal path from a to C, and according to the optimization principle, Route J must be the best route from B to C.

Optimization principle is the basis of dynamic programming, any problem, if lost the optimization principle of support, it is impossible to use dynamic programming method calculation.

No effect: "Past steps can only affect future development through the current state, the current state is a summary of history." This feature shows that dynamic planning is only suitable for solving problems that are not related to the past state of the current decision. State, which appears at any position in the policy, is of the same status and can implement the same strategy, which is no effect.

4. Dynamic planning and calculation steps

4.1 Partitioning Phase

According to the time or spatial characteristics of the problem, the problem is divided into several stages. The premise is that the several stages must be orderly, that is, the no-direction sex.

4.2 Select Status

The various objective situations that arise when the problem is developed into various stages are expressed in different states.

4.3 Determining the decision and writing out the state transition equation

State transfer is the process of exporting the state of this phase based on the state and decision of the previous phase.

For the dynamic programming problem, the division of the stage is the key, and it must be based on test instructions analysis to find a reasonable method of dividing the stage. According to the information obtained when calculating the optimal value, the optimal solution of the problem is constructed.

Next I use an example to illustrate the steps to solve a dynamic planning problem.

[Problem description]:

has a positive integer sequence b1,b2,b3,...,bn, if subscript is I1<i2<i3<...<ik and has bi1≤bi2≤ ... ≤bik said that there is a non-descending sequence of length K. There may be multiple non-descending sequences that output the length of the longest sequence.

[Sample input]:

13 7 9 16 38 24 37 18

[Sample output]:

5 (7 9 PNs)

[Problem analysis]:

1, phased: The number of numbers for the stage.

2, determine the state and state variables: N number of the longest non-descending sequence length.

3, the decision: with the front of which number splicing into the longest not descending sequence.

4, strategy and optimal strategy: The Final Solution is there.

5. State Transfer equation:


[Solution process]:

1, the number of stages, starting from the second calculation, because there are only 1, so do a comparison, because 7<13, do not meet the requirements of the problem, do not make any changes, the length is still 1.

2. There are 2 items in front of the third item, so two comparisons are required to obtain the current longest non-descending sequence of 2, as shown in the following table:


(Fig. 2)

3, Processing: In the 1,2,......,i-1 term, find than a[i] less than equal to the longest length of L; if l>0, then b[i]=l+1.

5. Dynamic Planning Summary

The problem of dynamic programming is a "multi-stage decision problem", in order to obtain an optimal solution (scheme). The essence of dynamic programming is to divide and cure the thought and solve redundancy, therefore, dynamic programming is an algorithm strategy to decompose the problem into smaller, similar sub-problems, and to store the solution of sub-problem and avoid the calculation of duplicate sub-problems to solve the optimization problem. There are many possible solutions to such problems, each with a value, and dynamic programming to find the optimal (maximum or minimum) solution. If there are multiple optimal solutions, it only takes one of them.

(Fig. 3)

Dynamic programming is similar to greedy algorithm, which solves the problem by multi-stage decision-making process, while dynamic programming is similar to recursive method, when the problem cannot be decomposed into independent stage, but conforms to the optimal principle (optimal substructure property), it is more suitable for dynamic programming.

But the dynamic programming and the general recurrence difference is also more obvious, the main performance is as follows:

1, recursive boundary conditions are generally obvious, while the dynamic programming boundary conditions are relatively hidden, easy to be neglected;

2, recursive mathematics is generally strong, but the dynamic programming of the relatively weak mathematical;

3, recursion generally does not divide the stage, and dynamic planning generally has a more obvious stage;

4, dynamic planning is often used to find an optimal value, and the general recursion is often used to count or to find a value.

Therefore, in general, dynamic planning is more suitable for solving most optimization problems. However, dynamic programming to solve the problem is not necessarily optimal (less complex), so the specific problem needs to be analyzed to determine the optimal algorithm.


Analysis and exploration of dynamic programming algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.