Fractional Knapsack Problem - Design and Analysis - Study Notes, Study notes of Digital Systems Design

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

2011/2012

Uploaded on 11/03/2012

ankitay
ankitay 🇮🇳

4.4

(50)

106 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture No. 27
7.4 Fractional Knapsack Problem
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.
Let ρi = vi/wi denote the value per unit weight ratio for item i. Sort the items in decreasing
order of ρi. Add items in decreasing order of ρi. If the item fits, we take it all. At some
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.
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Fractional Knapsack Problem - Design and Analysis - Study Notes and more Study notes Digital Systems Design in PDF only on Docsity!

Lecture No. 27

7.4 Fractional Knapsack Problem

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.

Let ρi = vi /wi denote the value per unit weight ratio for item i. Sort the items in decreasing

order of ρi. Add items in decreasing order of ρi. If the item fits, we take it all. At some

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

ρi , then you would first take the items of weight 5, then 20, and then (since the item of

weight 40 does not fit) you would settle for the item of weight 30, for a total value of $

  • $100 + $90 = $220. On the other hand, if you had been less greedy, and ignored the item of weight 5, then you could take the items of weights 20 and 40 for a total value of $100+$160 = $260. This is shown in Figure 7.10.

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