Question: Java Greedy Algorithm knapsack.java public class Knapsack { //privates public Knapsack(int W, int[] w, int[] b) { //constructor } public void GreedySolution() { //Print optimal

Java Greedy Algorithm

knapsack.java

public class Knapsack { //privates public Knapsack(int W, int[] w, int[] b) { //constructor } public void GreedySolution() { //Print optimal solution //use greedy algorithm //Print set with max sum

// print total benefit and weight of optimal set

} }

//end of knapsack.java

//beginining of driver

KNPDriver.java

public class KNPDriver

{

public static void main( String[] args)

{

int n=7;

int[] weights = {-1, 60, 50, 60, 50, 70, 70, 45};

int W = 100;

int[] benefits = {-1, 180, 95, 40, 95, 40, 40, 10

System.out.println(" Greedy Approximate Solution");

Knapsack kp4 = new Knapsack(W, weights, benefits);

kp4.GreedyApproximateSolution();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!