SlideShare a Scribd company logo
GANDHINAGAR INSTITUTE OF TECHNOLOGY
Computer Engineering Department
ADA (2150703)
Fractional knapsack problem
Prepared By:
Harsh Kothari
(170120107066)
Guided By:
Prof. Kiran Shah
Contents:
What is greedy approach?
Greedy Algorithms and techniques.
Knapsack problem.
Knapsack Algorithm.
Example of Knapsack problem.
Greedy Algorithms:
• Many real-world problems are optimization problems in that they
attempt to find an optimal solution among many possible
candidate solutions.
• An optimization problem is one in which you want to find, not just a
solution, but the best
solution
• A “greedy algorithm” sometimes works well for optimization problems
• A greedy algorithm works in phases. At each phase: You take the best
you can get right now, without regard for future consequences.You hope
that by choosing a local optimum at each step, you will end up at a
global optimum.
• Constructs a solution to an optimization problem piece by
• piece through a sequence of choices that are:
1.feasible, i.e. satisfying the constraints.
2.locally optimal (with respect to some neighborhood definition).
3.greedy (in terms of some measure).
Greedy Technique:
Knapsack Problem:
• Given n objects each have a weight wi and a value vi , and given
a knapsack of total capacity W. The problem is to pack the
knapsack with these objects in order to maximize the total value
of those objects packed without exceeding the knapsack’s
capacity.
• More formally, let xi denote the fraction of the object i to be
included in the knapsack, 0 
xi  1, for 1  i  n. The problem is to find values for the xi
such that
n n
 xivi
i1
 xi wi
i1
is maximized. W and
The optimal Knapsack Algorithm:
This algorithm is for time complexity O(n lgn))
(1) Sort the n objects from large to small based on the ratios vi/wi . We
assume the
arrays w[1..n] and v[1..n] store the respective weights and
values after sorting.
(2) initialize array x[1..n] to zeros.
(3) weight = 0; i = 1
(4) while (i  n and weight < W) do
(I) if weight + w[i]  W then x[i] = 1
(II) else x[i] = (W – weight) / w[i]
(III) weight = weight + x[i] * w[i]
(IV) i++
Example of Knapsack problem:
 Let us consider that the capacity of the knapsack W = 60 and the list
of provided items are shown in the following table −
Item A B C D
Profit 280 100 120 120
Weight 40 10 20 24
Ratio 7 10 6 5
 As the provided items are not sorted. After sorting, the items are as shown in the
following table.
Item B A C D
Profit 100 280 120 120
Weight 10 40 20 24
Ratio 10 7 6 5
 After sorting all the items, First all of B is chosen as weight
of B is less than the capacity of the knapsack.
 Next, item A is chosen, as the available capacity of the knapsack
is greater than the weight of A.
 Now, C is chosen as the next item. However, the whole item
cannot be chosen as the remaining capacity of the knapsack is
less than the weight of C.
 Hence, fraction of C (i.e. (60 − 50)/20) is chosen.
Solution:
 Now, the capacity of the Knapsack is equal to the selected items.
Hence, no more item can be selected.
 The total weight of the selected items is
10 + 40 + 20 * (10/20) = 60
And the total profit is
100 + 280 + 120 * (10/20) = 380 + 60 = 440
 This is the optimal solution. We cannot gain more profit
selecting any different combination of items.
Cont.
Item A B C D
Selected 1 1 0.5 0
Fractional Knapsack Problem

More Related Content

What's hot

0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
Amin Omi
 
Stack
StackStack
Dynamic Programming-Knapsack Problem
Dynamic Programming-Knapsack ProblemDynamic Programming-Knapsack Problem
Dynamic Programming-Knapsack Problem
Amrita Yadav
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
Ummar Hayat
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Circular queue
Circular queueCircular queue
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
Ashim Lamichhane
 
greedy algorithm Fractional Knapsack
greedy algorithmFractional Knapsack greedy algorithmFractional Knapsack
greedy algorithm Fractional Knapsack
Md. Musfiqur Rahman Foysal
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
NBACriteria2SICET
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Open Addressing on Hash Tables
Open Addressing on Hash Tables Open Addressing on Hash Tables
Open Addressing on Hash Tables
Nifras Ismail
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
District Administration
 
Knapsack problem and Memory Function
Knapsack problem and Memory FunctionKnapsack problem and Memory Function
Knapsack problem and Memory Function
Barani Tharan
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 

What's hot (20)

0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Stack
StackStack
Stack
 
Dynamic Programming-Knapsack Problem
Dynamic Programming-Knapsack ProblemDynamic Programming-Knapsack Problem
Dynamic Programming-Knapsack Problem
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort  selection sortInsertion sort bubble sort  selection sort
Insertion sort bubble sort selection sort
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Circular queue
Circular queueCircular queue
Circular queue
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
greedy algorithm Fractional Knapsack
greedy algorithmFractional Knapsack greedy algorithmFractional Knapsack
greedy algorithm Fractional Knapsack
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
 
Open Addressing on Hash Tables
Open Addressing on Hash Tables Open Addressing on Hash Tables
Open Addressing on Hash Tables
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Knapsack problem and Memory Function
Knapsack problem and Memory FunctionKnapsack problem and Memory Function
Knapsack problem and Memory Function
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 

Similar to Fractional Knapsack Problem

Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Jay Patel
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
garishma bhatia
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
dakccse
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
BinayakMukherjee4
 
Design and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.pptDesign and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.ppt
QurbanAli72
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
Abhishek Singh
 
knapsackusingbranchandbound
knapsackusingbranchandboundknapsackusingbranchandbound
knapsackusingbranchandbound
hodcsencet
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Melaku Bayih Demessie
 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptx
Akswant
 
Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
Paras Patel
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
Nikitagupta123
 
lect
lectlect
lect
farazch
 
lecture 26
lecture 26lecture 26
lecture 26sajinsc
 
lect
lectlect
lect
farazch
 
Lecture34
Lecture34Lecture34
Lecture34farazch
 
lec
leclec
lec
farazch
 

Similar to Fractional Knapsack Problem (20)

12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Design and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.pptDesign and analysis of Algorithms - Lecture 15.ppt
Design and analysis of Algorithms - Lecture 15.ppt
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
knapsackusingbranchandbound
knapsackusingbranchandboundknapsackusingbranchandbound
knapsackusingbranchandbound
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Lec30
Lec30Lec30
Lec30
 
Greedy+Day-3.pptx
Greedy+Day-3.pptxGreedy+Day-3.pptx
Greedy+Day-3.pptx
 
Knapsack Dynamic
Knapsack DynamicKnapsack Dynamic
Knapsack Dynamic
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 
lect
lectlect
lect
 
lecture 26
lecture 26lecture 26
lecture 26
 
lect
lectlect
lect
 
Lecture34
Lecture34Lecture34
Lecture34
 
Lecture34
Lecture34Lecture34
Lecture34
 
lec
leclec
lec
 

More from harsh kothari

Instructuion set of 8085
Instructuion set of 8085Instructuion set of 8085
Instructuion set of 8085
harsh kothari
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
stirling method maths
stirling method mathsstirling method maths
stirling method maths
harsh kothari
 
170120107066 dbms
170120107066 dbms170120107066 dbms
170120107066 dbms
harsh kothari
 
170120107066 dielectric.ppt
170120107066 dielectric.ppt170120107066 dielectric.ppt
170120107066 dielectric.ppt
harsh kothari
 
Hk
HkHk
170120107074 looping statements and nesting of loop statements
170120107074 looping statements and nesting of loop statements170120107074 looping statements and nesting of loop statements
170120107074 looping statements and nesting of loop statements
harsh kothari
 
170120107066 chronemics.ppt
170120107066 chronemics.ppt170120107066 chronemics.ppt
170120107066 chronemics.ppt
harsh kothari
 
170120107066 power series.ppt
170120107066 power series.ppt170120107066 power series.ppt
170120107066 power series.ppt
harsh kothari
 
170120107066 flowchart.ppt
170120107066 flowchart.ppt170120107066 flowchart.ppt
170120107066 flowchart.ppt
harsh kothari
 
control circuit
 control circuit control circuit
control circuit
harsh kothari
 

More from harsh kothari (11)

Instructuion set of 8085
Instructuion set of 8085Instructuion set of 8085
Instructuion set of 8085
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
stirling method maths
stirling method mathsstirling method maths
stirling method maths
 
170120107066 dbms
170120107066 dbms170120107066 dbms
170120107066 dbms
 
170120107066 dielectric.ppt
170120107066 dielectric.ppt170120107066 dielectric.ppt
170120107066 dielectric.ppt
 
Hk
HkHk
Hk
 
170120107074 looping statements and nesting of loop statements
170120107074 looping statements and nesting of loop statements170120107074 looping statements and nesting of loop statements
170120107074 looping statements and nesting of loop statements
 
170120107066 chronemics.ppt
170120107066 chronemics.ppt170120107066 chronemics.ppt
170120107066 chronemics.ppt
 
170120107066 power series.ppt
170120107066 power series.ppt170120107066 power series.ppt
170120107066 power series.ppt
 
170120107066 flowchart.ppt
170120107066 flowchart.ppt170120107066 flowchart.ppt
170120107066 flowchart.ppt
 
control circuit
 control circuit control circuit
control circuit
 

Recently uploaded

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 

Recently uploaded (20)

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 

Fractional Knapsack Problem

  • 1. GANDHINAGAR INSTITUTE OF TECHNOLOGY Computer Engineering Department ADA (2150703) Fractional knapsack problem Prepared By: Harsh Kothari (170120107066) Guided By: Prof. Kiran Shah
  • 2. Contents: What is greedy approach? Greedy Algorithms and techniques. Knapsack problem. Knapsack Algorithm. Example of Knapsack problem.
  • 3. Greedy Algorithms: • Many real-world problems are optimization problems in that they attempt to find an optimal solution among many possible candidate solutions. • An optimization problem is one in which you want to find, not just a solution, but the best solution • A “greedy algorithm” sometimes works well for optimization problems • A greedy algorithm works in phases. At each phase: You take the best you can get right now, without regard for future consequences.You hope that by choosing a local optimum at each step, you will end up at a global optimum.
  • 4. • Constructs a solution to an optimization problem piece by • piece through a sequence of choices that are: 1.feasible, i.e. satisfying the constraints. 2.locally optimal (with respect to some neighborhood definition). 3.greedy (in terms of some measure). Greedy Technique:
  • 5. Knapsack Problem: • Given n objects each have a weight wi and a value vi , and given a knapsack of total capacity W. The problem is to pack the knapsack with these objects in order to maximize the total value of those objects packed without exceeding the knapsack’s capacity. • More formally, let xi denote the fraction of the object i to be included in the knapsack, 0  xi  1, for 1  i  n. The problem is to find values for the xi such that n n  xivi i1  xi wi i1 is maximized. W and
  • 6. The optimal Knapsack Algorithm: This algorithm is for time complexity O(n lgn)) (1) Sort the n objects from large to small based on the ratios vi/wi . We assume the arrays w[1..n] and v[1..n] store the respective weights and values after sorting. (2) initialize array x[1..n] to zeros. (3) weight = 0; i = 1 (4) while (i  n and weight < W) do (I) if weight + w[i]  W then x[i] = 1 (II) else x[i] = (W – weight) / w[i] (III) weight = weight + x[i] * w[i] (IV) i++
  • 7. Example of Knapsack problem:  Let us consider that the capacity of the knapsack W = 60 and the list of provided items are shown in the following table − Item A B C D Profit 280 100 120 120 Weight 40 10 20 24 Ratio 7 10 6 5  As the provided items are not sorted. After sorting, the items are as shown in the following table. Item B A C D Profit 100 280 120 120 Weight 10 40 20 24 Ratio 10 7 6 5
  • 8.  After sorting all the items, First all of B is chosen as weight of B is less than the capacity of the knapsack.  Next, item A is chosen, as the available capacity of the knapsack is greater than the weight of A.  Now, C is chosen as the next item. However, the whole item cannot be chosen as the remaining capacity of the knapsack is less than the weight of C.  Hence, fraction of C (i.e. (60 − 50)/20) is chosen. Solution:
  • 9.  Now, the capacity of the Knapsack is equal to the selected items. Hence, no more item can be selected.  The total weight of the selected items is 10 + 40 + 20 * (10/20) = 60 And the total profit is 100 + 280 + 120 * (10/20) = 380 + 60 = 440  This is the optimal solution. We cannot gain more profit selecting any different combination of items. Cont. Item A B C D Selected 1 1 0.5 0