remember this value and now let's try it in the other way all right so now we're going to perform the greedy algorithm but this time choosing the largest value instead of the smallest size so if i'm selecting the largest value that means i'm going to select item NUMBER_TOKEN. so we have a size of NUMBER_TOKEN and a value of NUMBER_TOKEN. then i'm going to be choosing between item one and item two because they have the same largest value since this has a smaller size item two i'm going to select this one and so that means that if i were to select the entire item i would have a weight of NUMBER_TOKEN. obviously i can't do that because that goes over my capacity and so instead i need to select NUMBER_TOKEN of this item so that means that my capacity is going to go to NUMBER_TOKEN. NUMBER_TOKEN of NUMBER_TOKEN is clearly NUMBER_TOKEN. same thing here that means that i am going to get an additional NUMBER_TOKEN value here and that is going to lead me to NUMBER_TOKEN. so let's take this and store this down here as well so the two answers we got were NUMBER_TOKEN and NUMBER_TOKEN. now what we can say right now is okay well clearly the other approach selecting the smallest size worked better for this example but is this actually the optimal answer are either of these the optimal answer to this problem and well the answer to that is no there's actually a better way to solve this still using a greedy approach but it requires a little bit of thinking so the purpose of me showing you those two methods there was to illustrate that in a lot of examples you can use a greedy algorithm but you have to make sure you're really thinking about what your greedy criteria is how you're selecting the optimal choice at every single step now for this problem here you have to remember that we can select a fractional amount of all of these items and so really what we should do is find the items that have the best value to size ratio select the largest fractions of those items that we can and then continue on throughout the yellow group so i'll show you what i mean by that but let's just have a look here so what i'm going to do is make another column and i'm going to call this value over size now the point of this is that the items that have the largest value over size ratio are the best items for me to select so quite simply if we're looking at this right here nine size gives me nine value that means my value to size ratio is one so for every extra capacity i add or remove i guess from my backpack i get one value whereas if we're looking at say NUMBER_TOKEN and NUMBER_TOKEN i need to pull out my calculator for this but NUMBER_TOKEN divided by NUMBER_TOKEN is NUMBER_TOKEN if we're looking at NUMBER_TOKEN and NUMBER_TOKEN we're going to get NUMBER_TOKEN and if we're looking at NUMBER_TOKEN and NUMBER_TOKEN then we're going to get NUMBER_TOKEN so here we can see that the best item to select in terms of the value to size ratio is going to be item NUMBER_TOKEN and then we're going to have item NUMBER_TOKEN and then it's going to be item NUMBER_TOKEN followed by item NUMBER_TOKEN. so now what our new greedy algorithm should do here the correct greedy algorithm is at each step in our algorithm we should select the item that has the highest value over size ratio and take as much of that item as we possibly can so in this case we see that this is our best item so we're going to take all
NO_SEGMENT_TOKEN