Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How will the members be held accountable?

Answered: 1 week ago

Question

a. How will the leader be selected?

Answered: 1 week ago