First time here? Checkout the FAQ!
+1 vote

I was reading some of the notes (made easy and ACE)  and noticed that some teacher have taught that time complexity for Binary Knapsack O(2^(n/2)). which can not be reduced further. but What I have seen here that in worst case by using memoization we can reduce the time complexity upto O(n.W) where n is number of Object and W is capacity of knapsack.

What I am thinking that, Is it really Binary knapsack is NPC, Like Travelling Salesman problem because TSP tales O(n^2*2^n) times to calculate the tour by using dynamic method, which is efficient than o(n^n) of TSP brutforce techniques? Put some light, Am I missing something. Should I stop seeing those notes which people have posted over the internet. 

asked in Algorithms by Veteran (33.9k points)   | 208 views

1 Answer

+2 votes
Best answer

See AFAIK in DP we consider only the distinct function calls .So Using DP the complexity of Binary knapsack is O(nW).

But for the larger value of W the the complexity of Binary knapsack is O(2n). Because in 0/1 knapsack has very less repetition

So for the larger value W ,0/1 knapsack will generate n level complete binary tree So it will have  2n function calls and the time complexity

becomes O(2n). So it one of NP complete problem.

answered by Veteran (37k points)  
selected by
@ManojK Can you explain more, What do you mean by larger value? and Why that O(nW) did not work in the larger value?

 for n=5, W=100000  Here w has larger value.

Here n is polynomial in length but length of  w not polynomial it  can anything.

When comparing this with the  brute force algo take O(2n), but depending on W, either the dynamic programming algorithm is more efficient or the brute force algorithm could be more efficient. (For example, for n=5, W=100000, brute force is preferable, but for n=30 and W=1000, the dynamic programming solution is preferable.)

@manojK sir, abhi samjha cheekylaugh

Related questions

0 votes
1 answer
asked in Algorithms by firki lama Junior (907 points)   | 61 views
+1 vote
0 answers
+1 vote
2 answers

Top Users Jun 2017
  1. Bikram

    3704 Points

  2. Hemant Parihar

    1484 Points

  3. junaid ahmad

    1432 Points

  4. Arnab Bhadra

    1408 Points

  5. Niraj Singh 2

    1311 Points

  6. Rupendra Choudhary

    1194 Points

  7. rahul sharma 5

    1132 Points

  8. Debashish Deka

    994 Points

  9. srestha

    932 Points

  10. Arjun

    930 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 19 - 25
  1. Bikram

    1960 Points

  2. Niraj Singh 2

    1306 Points

  3. junaid ahmad

    502 Points

  4. sudsho

    410 Points

  5. akankshadewangan24

    388 Points

23,355 questions
30,066 answers
28,382 users