Question

In 1/0 Knapsack Problem, one can implement it dynamically with two for loops, like on this site: http://www.bogotobogo.com/Algorithms/knapsack.php

How can i implement it with a priority queue and optimize it with multithreading?

Était-ce utile?

La solution

In the algorithm in the section "0-1 Knapsack - Dynamic Programming", the inner loop can be parallelized. The execution of the loop's body for different values of jw can be executed in parallel as the calculation of the value for m[i][jw] does not require values m[i][jw'] where jw'!=jw, i.e. any iteration does not depend on previous iterations.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top