Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top