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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started