Question

2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . . . 1} with weight {w1·W2. . . . . ux) and value (n 2, .

l have posted it a few times before but didnt get a satisfactory answer. kindly help me by answering in pseudo code
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I have assumed the list representation to be of an array type.

So therefore for compute mean, for each would be adding the respective values of at ith place in all the arrays.

I am using MATLAB as a basic language to write the pseudocode for COMPUTEMEAN.

In Matlab, the list of arrays are merged together in the form of a matrix such that the row denotes one array, and the matrix would be of the size (mXn). After this, we can apply the mean function on the columns of the matrix and thus get a vector having the mean as needed.

Following is the code for the approach.

function values_mean= COMPUTEMEAN(list){ %list is the list of m arrays as feasible solutions

2d_list = [X1; X2; X3;.......;Xm] %Here the ';' is important. m is already known before, this will create the req matrix

%Applying mean to the columns of the matrix

values_mean = mean(2d_list);

%This function returns the mean of each column in a row vector called values mean

}

Now for the greedy algorithm for this problem, we need to have a heuristic, i.e. we need to have a single measure which can be maximized and taken. Now in a normal greedy approach, we use value/weight ratio and the max ration is preferred first so that we have the best possible solution.

However here the question asks to use ComputeMean() in the greedy problem (heuristic). Now let's see what does the computeMean return to us exactly.

The computeMean method implemented above would return a row vector consisting of values between 0 and 1. This is because all values in the array representation are 0 or 1 so the mean of them is going to be somewhere in between. So each element in the returning vector can be said to be the likelihood of that element to be in the final solution.

So here, we can have ComputedMean as a heuristic measure. We can select those items which have a high computedMean value and keep doing so until the knapsack capacity is reached. That would give us a solution to the knapsack problem.

The effectiveness of such a greedy approach would depend highly on the success of Monte Carlo-style simulation approach that will return a list of feasible solutions. If the list of feasible solutions is close enough to the real solution then this method will succeed. Otherwise, the answer would be wrong. Therefore it can be concluded that this method can only be used if we have a list of correct feasible solutions possible.

If you have any doubts, please comment below.

If the answer helped you, please leave a thumbs up :)

Add a comment
Know the answer?
Add Answer to:
l have posted it a few times before but didnt get a satisfactory answer. kindly help me by answering in pseudo cod...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . ....

    solution is required in pseudo code please. 2 Knapsack Problem În al Knapsack problem. given n items(11-12. . . . . 1"} with weight {w1·W2. . . . . ux) and value (n 2, .., nJ, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity In this question, we will consider two different ways to represent a solution to the...

  • In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maxim...

    In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W . i-1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using . an...

  • 2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi,...

    2 Knapsack Problem In a Knapsack problem, given n items {11, I2, -.., In} with weight {wi, w2, -.., wn) and value fvi, v2, ..., vn], the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W. Tt i=1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using an array with size...

  • Please use MATLAB You are given an array, weights, that contains the weights of some cargo...

    Please use MATLAB You are given an array, weights, that contains the weights of some cargo items in pounds. You want to load a truck with items from the list, up to its capacity. The truck has a maximum capacity of 1,000 pounds. For this problem, you want to find the maximum possible weight that can be loaded onto the truck. The greedy algorithm is not guaranteed to achieve this optimal result. For example, if the weights were (25 452...

  • i need the solution in pseudo code please. 4 Dynamic Programmii Consider the following problem based on the transf...

    i need the solution in pseudo code please. 4 Dynamic Programmii Consider the following problem based on the transformation of a sequence (or collection) of coloured disks. Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, cl. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink,. c-black For a given sequence of coloured disks eg.,0,1,2,3,4), at each time step (or iteration) you are only...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Correct answer for this Java problem will get thumbs up and eternal thanks Problem Description Over...

    Correct answer for this Java problem will get thumbs up and eternal thanks Problem Description Over the course of this semester you will write a chess game database that will import chess games in PGN (http://www.saremba.de/chessgml/standards/pgn/pgn- complete.htm) format. As a first step you will write code to read PGN games and resolve board positions. Solution Description Write a class called PgnReader that contains the following public static methods: tagValue takes two String arguments: a tag name and a String which...

  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • pls answer all questions 1) A step-by-step solution to a problem is called a. hardware b....

    pls answer all questions 1) A step-by-step solution to a problem is called a. hardware b. an operating system c. a computer language d. an algorithm 2) separated the programming task from the computer operation tasks. a. Algorithms b. Data processors c. High-level programming languages d. Operating systems 3) is a 16-bit code that can represent symbols in languages other than English. a. ASCII b. Extended ASCII c. EBCDIC d. Unicode 4) When you want to download music to a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT