0% found this document useful (0 votes)
3 views3 pages

AOA-Lab_Exp3

The document outlines an experiment to implement the Fractional Knapsack Problem using C programming. It discusses the theory behind the problem, including brute-force and greedy approaches, and provides the algorithm along with time and space complexity. The conclusion states that the implementation successfully maximizes profit by filling the knapsack with selected items based on their value-to-weight ratio.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

AOA-Lab_Exp3

The document outlines an experiment to implement the Fractional Knapsack Problem using C programming. It discusses the theory behind the problem, including brute-force and greedy approaches, and provides the algorithm along with time and space complexity. The conclusion states that the implementation successfully maximizes profit by filling the knapsack with selected items based on their value-to-weight ratio.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Subrato Tapaswi Roll No.

/Div: 60/D6AD
EXPERIMENT-3

AIM:
Write a C program to implement Fractional Knapsack Problem
THEORY:
Fractional Knapsack is an algorithmic problem in combinational optimization in which the goal is to fill a
container-i.e., knapsack with fractional amounts of different materials chosen to maximize the value of the
selected materials.
Brute-force approach: The brute-force approach tries all the possible solutions with all the different fractions
but it is a time-consuming approach.
Greedy approach: In Greedy approach, we calculate the ratio of profit/weight, and accordingly, we will
select the item. The item with the highest ratio would be selected first.
Complexity: Time Complexity: O(N*logN) here, N= size of the array
Space Complexity: O(1)
ALGORITHM:
Greedy Knapsack(m, n)
// p[1: n] and w[1: n] contain the profits and weights respectively
// of the n objects ordered such that p[i]/w[i] ≥ pli+1]/w[i+1]
//m is the knapsack size and z[1:n) is the solution vector.
{
for i:=1 to n do r[i]=0.0; // Initialize x.
U := m;
for i:=1 to n do
{
if (w[i] > U) then break;
x[i] = 1.0; U:- U - w[i];
}
if (i <n) then r[i]:= U/w[i];
}
PROGRAM CODE:
OUTPUT:

CONCLUSION:
Thus, we have implemented Fractional Knapsack which is a greedy algorithm used in order to fill the
knapsack of the given weight with different things to maximize the profit.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy