Question: C or C++ Implement Best-Frist Search with Branch-and-Bound Pruning for the 0-1 Knapsack Problem. Photo for reference 0-1 Knapsack Problem id sapsock (index i, int
C or C++
Implement Best-Frist Search with Branch-and-Bound Pruning for the 0-1 Knapsack Problem. Photo for reference 
0-1 Knapsack Problem id sapsock (index i, int profit, int weight) // This set is best // so far // Set numbest to // number of items // considered. Set // bestset to this // solution if (weight We& profit > masprofit)f maxprofitprofit; nsmbest bestset include; if (promising(i)f // Include wi+1] // Do not include ineludei 1]"yes knapsack( i, +1,-profit + p[i + 1], t'eight + w i+ 11); includeli 1]"no" knapsack(i +1, profit, weight); bool promising (index ) index j, int totweight flost bound if (weight W) /I Node is promising only // if we should expand to // its children. There must /I be some capacity left for /I the children retura false; elset bound profit; totweight-weight; while (j n&k totweigtw) // Grab as many items as // possible bound bound +plili if (k ) bound- bosnd + (W- totwcight) . plk/ return bound> mazprofit; // Use k for consistency // with formula in text. /I Grab fraction of kth // item
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
