



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Fractional Knapsack Problem, Greedy solution to the fractional knapsack problem, Graphs, Types of graphs, Adjacent vertices, Incidence of edges on vertices are the key points in this study notes file.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Earlier we saw the 0-1 knapsack problem. A knapsack can only carry W total weight. There are n items; the ith^ item is worth vi and weighs wi. Items can either be put in the knapsack or not. The goal was to maximize the value of items without exceeding the total weight limit of W. In contrast, in the fractional knapsack problem, the setup is exactly the same. But, one is allowed to take fraction of an item for a fraction of the weight and fraction of value. The 0-1 knapsack problem is hard to solve. However, there is a simple and efficient greedy algorithm for the fractional knapsack problem.
point there is an item that does not fit in the remaining space. We take as much of this item as possible thus filling the knapsack completely.
Figure 7.8: Greedy solution to the fractional knapsack problem
It is easy to see that the greedy algorithm is optimal for the fractional knapsack problem. Given a room with sacks of gold, silver and bronze, one (thief?) would probably take as much gold as possible. Then take as much silver as possible and finally as much bronze as possible. It would never benefit to take a little less gold so that one could replace it with an equal weight of bronze.
We can also observe that the greedy algorithm is not optimal for the 0-1 knapsack problem. Consider the example shown in the Figure 7.9. If you were to sort the items by
weight 40 does not fit) you would settle for the item of weight 30, for a total value of $
Figure 7.9: Greedy solution for the 0-1 knapsack problem (non-optimal)
Figure 8.1: Types of graphs
A vertex w is adjacent to vertex v if there is an edge from v to w.
Figure 8.2: Adjacent vertices
In an undirected graph, we say that an edge is incident on a vertex if the vertex is an endpoint of the edge of the edge.
Figure 8.3: Incidence of edges on vertices
In a digraph, the number of edges coming out of a vertex is called the out-degree of that vertex. Number of edges coming in is the in-degree.
In an undirected graph, we just talk of degree of a vertex. It is the number of edges incident on the vertex.
Figure 8.4: In and out degrees of vertices of a graph