Why 0-1 knapsack problem is a NP complete problem, but this problem also has the dynamic programming solution? __ Dynamic Planning

Source: Internet
Author: User

Whether P is equal to NP is one of the most famous unsolved problems in computational complexity theory, a NP-complete problem, if we can find a polynomial-time algorithm to solve it, then the P=NP is explained.

Today, 0-1 knapsack problem has been proved to be NP complete problem, but it has a dynamic programming solution, this solution has the time complexity of O (n*w), where n is the number of items, W is the maximum weight of backpack constraints. So the time complexity is polynomial time for the input n,w, so the np=p is explained. Is there something wrong?

In fact, polynomial time is relative to the size of the input, the most intuitive input scale is the input to the algorithm data accounted for how many bits of memory. 0-1 the input of the backpack has the value of n items, the weight of n items, and the maximum load W of the backpack. Now assume that W occupies the number of bits L (that is, the maximum weight of the backpack input size is L), then log (W) =l, so O (n*w) =o (n*2^l), it is seen that the time complexity of the algorithm for the input scale L is a number of degrees, with the increase in the size of input L, The computation time will grow rapidly.

In fact, this kind of dynamic programming algorithm is called the Pseudo polynomial time algorithm, and the algorithm can't solve the problem in pseudo-polynomial time in real sense.

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.