Suppose that we have a knapsack with total capacity of w kg. We also have n items where item j has mass 117. The knapsack problem asks for a subset of these n items with the largest possible total mass not exceeding W.a) Devise a brute-force algorithm for solving the knapsack problem.________________b) Solve the knapsack problem when the capacity of the knapsack is 18 kg and there are five items: a 5-kg sleeping bag, an 8-kg tent, a 7-kg food pack, a 4-kg container of water, and an 11 -kg portable stove.

Solution:Step 1:First of all, we need to devise a brute-force calculation for taking care of the knapsack problem. Give us initially a chance to talk about the knapsack problem.Step 2:Assume that we have a knapsack with an aggregate limit of W kg. We likewise have n things where thing j has mass wj. The knapsack issue requests a subset of these n things with the biggest conceivable aggregate mass, not exceeding W.Step 3:Presently we investigate what a brute-force algorithm is and the means to keep in touch with one. In a brute-force algorithm, an issue is unraveled in the clearest way in view of the announcement of the issue and the meanings of terms. brute-force algorithm is intended to take care of issues without respect to the figuring assets required. For instance, in some brute-force algorithms, the answer for an issue is found by inspecting each conceivable arrangement, searching for the most ideal.