Understanding of dynamic programming algorithms

Source: Internet
Author: User

  1. What is a dynamic programming algorithm?

    The essence of dynamic programming algorithm is to divide and cure ideas and solve redundancy. As a result, it is similar to the method of splitting and greedy, which decomposes the problem to be solved into smaller, identical sub-problems, then solves the problem of sub-problems, and finally produces a whole optimal solution.

  2. Suitable for solving problems by using dynamic programming method, the sub-problems obtained by decomposition are often not independent of each other. In the solution process, the solution of the resolved sub-problem is saved and can be easily identified when needed.

    Examples are as follows:

    Fibonacci Series 0 N=0

    F (n) = 1 n=1

    F (n-1) +f (n-2) n>1

    If n=4, then f (4) =f (3) +f (2) is F (3) =f (2) +f (1) F (2) =f (1) +f (0). If each is counted, F (2), several times, is inefficient, and if n is large, repeat the calculation more. So the efficiency is very low. Dynamic programming method, the solution of the solved sub-problem is saved, it can be easily found when needed, the key of dynamic programming is to solve the redundancy, the original index-level complexity of the search algorithm is improved into a polynomial time algorithm, which is the fundamental purpose of dynamic programming algorithm. In the process of implementation, the dynamic programming method needs to store various states, so his space complexity is greater than other algorithms, which is a space for time-based technology.

  3. When are dynamic programming algorithms used?

    The way of thinking of any algorithm has its limitations, and it loses its function beyond certain conditions. The same dynamic programming algorithm should have three basic elements.

    1. Optimal substructure properties (proof: The first hypothesis is that the solution of the sub-problem derived from the optimal solution of the problem is not optimal, and then tries to show that under this hypothesis the optimal solution of the original problem can be constructed, which leads to the contradiction. )

    2. Overlapping properties of sub-problems

    When the recursive algorithm solves the problem, the sub-problem is not always a new problem, and some sub-problems occur several times, this property is called the overlapping nature of the sub-problem. The overlapping nature of sub-problems is not a necessary condition for dynamic programming, but if the nature is not satisfied, the dynamic programming algorithm has no advantage over other algorithms.

    3. Bottom-up solution

    Because the problem of dynamic programming has overlapping properties of sub-problems, it is necessary to use the bottom-up method, that is, to select the appropriate table first, the recursive stop condition is filled in the corresponding position of the table, then the scale of the problem is enlarged, the optimal value of each sub-problem is obtained, and the corresponding position of the table is filled. The optimal value of the original problem is found at this time until the scale of the problem is required.

  4. The dynamic programming algorithm is suitable for solving the optimization problem, and the process of solving the algorithm can be designed according to the following steps.

    (1) Analyzing the properties of the optimal solution, characterizing the structural characteristics of the optimal solution----investigate whether the dynamic programming algorithm is suitable.

    (2) Recursive definition of optimal values (i.e. the establishment of recursive or dynamic programming equations)

    (3) Calculate the optimal value in the bottom-up way and record the relevant information.

    (4) The optimal solution is constructed according to the information obtained when calculating the optimal value.

    Before further discussion on the design method and application of dynamic programming, there are two points to note that the first is that the characterization of the problem is very important to solve the dynamic programming, and the inappropriate depiction method will make the description of the problem not have the optimal sub-structure property, so that the optimal worthy recursive relationship cannot be established, and the dynamic programming can not be discussed. Second, in the process of algorithm implementation, we should make full use of the overlapping properties of sub-problems to improve the problem solving efficiency. Specifically, recursive (iterative) methods should be used to programmatically calculate the optimal value with recursive definition, rather than using direct recursion.



This article from the "Jane Answers Life" blog, reproduced please contact the author!

Understanding of dynamic programming algorithms

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.