SlideShare a Scribd company logo
2
Most read
International Journal of Modern Trends in Engineering and
Research
www.ijmter.com
e-ISSN: 2349-9745
@IJMTER-2014, All rights Reserved 5
Comparative Analysis of Dynamic and Greedy
Approaches for Dynamic Programming
Jay Vala1
, Dhara Monaka2
, Jaymit Pandya3
1
Asst. Prof., I.T. Department, G H Patel College of Engg & Tech, jayvala1623@gmail.com
2
Asst. Prof., B.C.A. Department, Nandkunvarba Mahila College, dhara.monaka123@gmail.com
3
Asst. Prof., I.T. Department, G H Patel College of Engg & Tech, erpandyajaymit@gmail.com
Abstract— This paper analyze few algorithms of the 0/1 Knapsack Problem and fractional
knapsack problem. This problem is a combinatorial optimization problem in which one has
to maximize the benefit of objects without exceeding capacity. As it is an NP-complete
problem, an exact solution for a large input is not possible. Hence, paper presents a
comparative study of the Greedy and dynamic methods. It also gives complexity of each
algorithm with respect to time and space requirements. Our experimental results show that
the most promising approaches are dynamic programming.
Keywords- knapsack, dynamic programming, greedy programming, NP-Complete,
complexity
I. INTRODUCTION
The knapsack problem or rucksack problem is a problem in combinatorial optimization:
Given a set of items, each with a mass and a value, determine the number of each item to
include in a collection so that the total weight is less than or equal to a given limit and the
total value is as large as possible. It derives its name from the problem faced by someone who
is constrained by a fixed-size knapsack and must fill it with the most valuable items [1]
.
The 0-1 knapsack problem can solve using a partitioning algorithm for finding break item,
weak reduction, strong upper bound, finding the solution vector and minimality.
II. DIFFERENT APPROACHES TO PROBLEM
1) Greedy Approach
A thief robbing a store and can carry a maximal weight of w into their knapsack. There are n
items and ith
item weigh wi and is worth vi dollars. What items should thief take? This
version of problem is known as Fractional knapsack problem. The setup is same, but the thief
can take fractions of items, meaning that the items can be broken into smaller pieces so that
thief may decide to carry only a fraction of xi of item i, where 0 ≤ xi ≤ 1[2][3]
.
2) Dynamic Approach
Again a thief robbing a store and can carry a maximal weight of w into their knapsack. There
are n items and ith item weigh w i and is worth vi dollars. What items should thief take? This
version of problem is known as 0-1 knapsack problem. The setup is the same, but the items
International Journal of Modern Trends in Engineering and Research(IJMTER)
Volume 01, Issue 01, July- 2014
e-ISSN: 2349-9745
@IJMTER-2014, All rights Reserved 6
may not be broken into smaller pieces, so thief may decide either to take an item or to leave it
(binary choice), but may not take a fraction of an item [2][3]
.
III. GREEDY ALGORITHM
It is as follows.
1. Calculate Vi = vi/si for i=1,2,…,n
2. Sort the items by declaring Vi
3. Find j such that s1+s2+…..+ sn<= S < s1+s2+…..+ sn+1
4.
IV. DYNAMIC ALGORITHM
It is as follows.
for i=1 to n
if si < = s
if vi + V[i-1,s- si] > V[i-1, s]
V[i,s] = vi + V[i-1,s- si]
else
V[i,s] = V[i-1,s]
else V[i,s] = V[i-1,s]
V. RESULT ANALYSIS
Implemented knapsack problem with different values of weight and profit or value in Turbo C. If
we consider a data value is w={1, 2, 5}, v={1, 6, 18} and Carrying capacity W= 7 then output of
greedy is:
Fig. 1 Solved by Greedy approach
Same data values and solving by Dynamic programming.
International Journal of Modern Trends in Engineering and Research(IJMTER)
Volume 01, Issue 01, July- 2014
e-ISSN: 2349-9745
@IJMTER-2014, All rights Reserved 7
Fig. 2 Solved by Dynamic programming
After implemented knapsack problem in c programming for different values of weight and profit.
Result of both methods gives same optimal solution and different time.
Method Input Data Capacity Profit Time
Greedy
W={1,3,4,5}
V={1,4,5,6}
9 11 15.86
W={1,2,5,6,7} ,
V={1,6,18,20,28}
11 40 25.73
W={10,20,30,40,50}
V={10,30,64,50,60}
100 156 21.68
Dynamic
W={1,3,4,5}
V={1,4,5,6}
9 11 17.69
W={1,2,5,6,7} ,
V={1,6,18,20,28}
11 40 18.47
W={10,20,30,40,50}
V={10,30,64,50,60}
100 156 19.65
VI. CONCLUSION
In this paper we conclude that for particular one knapsack problem we can implement two
methods greedy and dynamic. But when we implemented both method for different dataset values
then we notice something like, we consider comparison parameter as optimal profit or total value
for filling knapsack using available weight then dynamic and greedy both are gaining same profit.
If we consider time then dynamic take less amount of time compare with greedy. So we can
conclude that dynamic is better than greedy with respect to time.
REFERENCES
[1]. George B. Dantzig, Discrete-Variable Extremum Problems, Operations Research Vol. 5,
No. 2, April 1957, pp. 266–288,doi:10.1287/opre.5.2.266
[2] Gossett, Eric. Discreet Mathematics with Proof. New Jersey: Pearson Education Inc.,
2003.
International Journal of Modern Trends in Engineering and Research(IJMTER)
Volume 01, Issue 01, July- 2014
e-ISSN: 2349-9745
@IJMTER-2014, All rights Reserved 8
[3] Levitin, Anany. The Design and Analysis of Algorithms. New Jersey: Pearson Education
Inc., 2003.
[4] Mitchell, Melanie. An Introduction to Genetic Algorithms. Massachusettss: The MIT
Press, 1998.
[5] Obitko, Marek. ―Basic Description.‖ IV. Genetic Algorithm. Czech Technical
University (CTU). http://cs.felk.cvut.cz/~xobitko/ga/gaintro.html
[6] Different Approaches to Solve the 0/1 Knapsack Problem. Maya Hristakeva, Dipti
Shrestha; Simpson Colleges
Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming
Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming

More Related Content

PDF
Paper id 71201961
PDF
In insight into QAC2(1) : Dynkin diagrams and properties of roots
PDF
Group Magic Labeling of Cycles With a Common Vertex
PDF
Numerical approach of riemann-liouville fractional derivative operator
PPT
Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...
PPTX
Daa unit 3
PDF
Iterative methods for the solution of saddle point problem
PDF
Paper id 71201961
In insight into QAC2(1) : Dynkin diagrams and properties of roots
Group Magic Labeling of Cycles With a Common Vertex
Numerical approach of riemann-liouville fractional derivative operator
Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...
Daa unit 3
Iterative methods for the solution of saddle point problem

What's hot (18)

PDF
Ricci Solitons in an Kenmotsu Manifold admitting Conharmonic Curvature Tensor
DOCX
Dissertation on petal graphs
PDF
Minimal dominating functions of corona product graph of a cycle with a compl
PDF
Design and Implentation of High Speed 16x16 CMOS Vedic Multiplier
PDF
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
PDF
Daa chapter 3
PDF
QMC: Operator Splitting Workshop, Structured Composite Problems in Direct Hil...
PDF
A class of three stage implicit rational runge kutta schemes for approximatio...
PDF
Development of implicit rational runge kutta schemes for second order ordinar...
PDF
Some fixed point results for cone metric space
PDF
Aitken's Method
PDF
Artificial intelligence ai choice mechanism hypothesis of a mathematical method
PDF
IRJET- On the Homogeneous Ternary Quadratic Diophantine Equation 3(X+Y)2-2xy=...
PDF
Some new exact Solutions for the nonlinear schrödinger equation
PDF
07 a70102 finite element methods in civil engineering
PDF
Steven Duplij, Raimund Vogl, "Polyadic Braid Operators and Higher Braiding Ga...
PDF
International Journal of Computational Engineering Research (IJCER)
PDF
Steven Duplij, Raimund Vogl, "Polyadic braid operators and higher braiding ga...
Ricci Solitons in an Kenmotsu Manifold admitting Conharmonic Curvature Tensor
Dissertation on petal graphs
Minimal dominating functions of corona product graph of a cycle with a compl
Design and Implentation of High Speed 16x16 CMOS Vedic Multiplier
IRJET- Wavelet based Galerkin Method for the Numerical Solution of One Dimens...
Daa chapter 3
QMC: Operator Splitting Workshop, Structured Composite Problems in Direct Hil...
A class of three stage implicit rational runge kutta schemes for approximatio...
Development of implicit rational runge kutta schemes for second order ordinar...
Some fixed point results for cone metric space
Aitken's Method
Artificial intelligence ai choice mechanism hypothesis of a mathematical method
IRJET- On the Homogeneous Ternary Quadratic Diophantine Equation 3(X+Y)2-2xy=...
Some new exact Solutions for the nonlinear schrödinger equation
07 a70102 finite element methods in civil engineering
Steven Duplij, Raimund Vogl, "Polyadic Braid Operators and Higher Braiding Ga...
International Journal of Computational Engineering Research (IJCER)
Steven Duplij, Raimund Vogl, "Polyadic braid operators and higher braiding ga...
Ad

Viewers also liked (11)

PDF
Swaati algorithm of alignment ppt
PDF
My presentation all shortestpath
PPT
lecture 26
PPTX
(Icca 2014) shortest path analysis in social graphs
PPTX
Pixton
PDF
Raspberry Pi Foundation - Intro for Creative Technologists
PPTX
PowerPoint día a día
PPT
Equivalence dosage
DOC
Portfolio
PDF
paper_towel_research
PPTX
Curso de historia de méxico
Swaati algorithm of alignment ppt
My presentation all shortestpath
lecture 26
(Icca 2014) shortest path analysis in social graphs
Pixton
Raspberry Pi Foundation - Intro for Creative Technologists
PowerPoint día a día
Equivalence dosage
Portfolio
paper_towel_research
Curso de historia de méxico
Ad

Similar to Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming (20)

PPTX
Knapsack problem using greedy approach
PPT
Design and analysis of Algorithms - Lecture 15.ppt
PPTX
Fractional Knapsack Problem
PDF
A Survey- Knapsack Problem Using Dynamic Programming
PPTX
Greedy Algorithm - Knapsack Problem
PPTX
Ms nikita greedy agorithm
PPT
Knapsack problem and Memory Function
PPTX
Knapsack
PPT
Elak3 need of greedy for design and analysis of algorithms.ppt
PPTX
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
PPTX
Greedy Method unit-2(Design and analysis of algorithms).pptx
PPTX
Dynamic Programming-Knapsack Problem
PPTX
Fractional knapsack class 13
PPTX
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
PPTX
knapsack problem
PPTX
Knapsack problem
PPTX
Algorithms Design Patterns
PPTX
Dynamic Programming
PPTX
Knapsack Problem (DP & GREEDY)
PDF
7f44bdd880a385b7c1338293ea4183f930ea
Knapsack problem using greedy approach
Design and analysis of Algorithms - Lecture 15.ppt
Fractional Knapsack Problem
A Survey- Knapsack Problem Using Dynamic Programming
Greedy Algorithm - Knapsack Problem
Ms nikita greedy agorithm
Knapsack problem and Memory Function
Knapsack
Elak3 need of greedy for design and analysis of algorithms.ppt
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
Greedy Method unit-2(Design and analysis of algorithms).pptx
Dynamic Programming-Knapsack Problem
Fractional knapsack class 13
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
knapsack problem
Knapsack problem
Algorithms Design Patterns
Dynamic Programming
Knapsack Problem (DP & GREEDY)
7f44bdd880a385b7c1338293ea4183f930ea

More from Editor IJMTER (20)

PDF
A NEW DATA ENCODER AND DECODER SCHEME FOR NETWORK ON CHIP
PDF
A RESEARCH - DEVELOP AN EFFICIENT ALGORITHM TO RECOGNIZE, SEPARATE AND COUNT ...
PDF
Analysis of VoIP Traffic in WiMAX Environment
PDF
A Hybrid Cloud Approach for Secure Authorized De-Duplication
PDF
Aging protocols that could incapacitate the Internet
PDF
A Cloud Computing design with Wireless Sensor Networks For Agricultural Appli...
PDF
A CAR POOLING MODEL WITH CMGV AND CMGNV STOCHASTIC VEHICLE TRAVEL TIMES
PDF
Sustainable Construction With Foam Concrete As A Green Green Building Material
PDF
USE OF ICT IN EDUCATION ONLINE COMPUTER BASED TEST
PDF
Textual Data Partitioning with Relationship and Discriminative Analysis
PDF
Testing of Matrices Multiplication Methods on Different Processors
PDF
Survey on Malware Detection Techniques
PDF
SURVEY OF TRUST BASED BLUETOOTH AUTHENTICATION FOR MOBILE DEVICE
PDF
SURVEY OF GLAUCOMA DETECTION METHODS
PDF
Survey: Multipath routing for Wireless Sensor Network
PDF
Step up DC-DC Impedance source network based PMDC Motor Drive
PDF
SPIRITUAL PERSPECTIVE OF AUROBINDO GHOSH’S PHILOSOPHY IN TODAY’S EDUCATION
PDF
Software Quality Analysis Using Mutation Testing Scheme
PDF
Software Defect Prediction Using Local and Global Analysis
PDF
Software Cost Estimation Using Clustering and Ranking Scheme
A NEW DATA ENCODER AND DECODER SCHEME FOR NETWORK ON CHIP
A RESEARCH - DEVELOP AN EFFICIENT ALGORITHM TO RECOGNIZE, SEPARATE AND COUNT ...
Analysis of VoIP Traffic in WiMAX Environment
A Hybrid Cloud Approach for Secure Authorized De-Duplication
Aging protocols that could incapacitate the Internet
A Cloud Computing design with Wireless Sensor Networks For Agricultural Appli...
A CAR POOLING MODEL WITH CMGV AND CMGNV STOCHASTIC VEHICLE TRAVEL TIMES
Sustainable Construction With Foam Concrete As A Green Green Building Material
USE OF ICT IN EDUCATION ONLINE COMPUTER BASED TEST
Textual Data Partitioning with Relationship and Discriminative Analysis
Testing of Matrices Multiplication Methods on Different Processors
Survey on Malware Detection Techniques
SURVEY OF TRUST BASED BLUETOOTH AUTHENTICATION FOR MOBILE DEVICE
SURVEY OF GLAUCOMA DETECTION METHODS
Survey: Multipath routing for Wireless Sensor Network
Step up DC-DC Impedance source network based PMDC Motor Drive
SPIRITUAL PERSPECTIVE OF AUROBINDO GHOSH’S PHILOSOPHY IN TODAY’S EDUCATION
Software Quality Analysis Using Mutation Testing Scheme
Software Defect Prediction Using Local and Global Analysis
Software Cost Estimation Using Clustering and Ranking Scheme

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Digital Logic Computer Design lecture notes
PPTX
Artificial Intelligence
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
Geodesy 1.pptx...............................................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
introduction to datamining and warehousing
PPTX
Sustainable Sites - Green Building Construction
DOCX
573137875-Attendance-Management-System-original
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Operating System & Kernel Study Guide-1 - converted.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Digital Logic Computer Design lecture notes
Artificial Intelligence
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Geodesy 1.pptx...............................................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Internet of Things (IOT) - A guide to understanding
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
introduction to datamining and warehousing
Sustainable Sites - Green Building Construction
573137875-Attendance-Management-System-original
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming

  • 1. International Journal of Modern Trends in Engineering and Research www.ijmter.com e-ISSN: 2349-9745 @IJMTER-2014, All rights Reserved 5 Comparative Analysis of Dynamic and Greedy Approaches for Dynamic Programming Jay Vala1 , Dhara Monaka2 , Jaymit Pandya3 1 Asst. Prof., I.T. Department, G H Patel College of Engg & Tech, jayvala1623@gmail.com 2 Asst. Prof., B.C.A. Department, Nandkunvarba Mahila College, dhara.monaka123@gmail.com 3 Asst. Prof., I.T. Department, G H Patel College of Engg & Tech, erpandyajaymit@gmail.com Abstract— This paper analyze few algorithms of the 0/1 Knapsack Problem and fractional knapsack problem. This problem is a combinatorial optimization problem in which one has to maximize the benefit of objects without exceeding capacity. As it is an NP-complete problem, an exact solution for a large input is not possible. Hence, paper presents a comparative study of the Greedy and dynamic methods. It also gives complexity of each algorithm with respect to time and space requirements. Our experimental results show that the most promising approaches are dynamic programming. Keywords- knapsack, dynamic programming, greedy programming, NP-Complete, complexity I. INTRODUCTION The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a mass and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items [1] . The 0-1 knapsack problem can solve using a partitioning algorithm for finding break item, weak reduction, strong upper bound, finding the solution vector and minimality. II. DIFFERENT APPROACHES TO PROBLEM 1) Greedy Approach A thief robbing a store and can carry a maximal weight of w into their knapsack. There are n items and ith item weigh wi and is worth vi dollars. What items should thief take? This version of problem is known as Fractional knapsack problem. The setup is same, but the thief can take fractions of items, meaning that the items can be broken into smaller pieces so that thief may decide to carry only a fraction of xi of item i, where 0 ≤ xi ≤ 1[2][3] . 2) Dynamic Approach Again a thief robbing a store and can carry a maximal weight of w into their knapsack. There are n items and ith item weigh w i and is worth vi dollars. What items should thief take? This version of problem is known as 0-1 knapsack problem. The setup is the same, but the items
  • 2. International Journal of Modern Trends in Engineering and Research(IJMTER) Volume 01, Issue 01, July- 2014 e-ISSN: 2349-9745 @IJMTER-2014, All rights Reserved 6 may not be broken into smaller pieces, so thief may decide either to take an item or to leave it (binary choice), but may not take a fraction of an item [2][3] . III. GREEDY ALGORITHM It is as follows. 1. Calculate Vi = vi/si for i=1,2,…,n 2. Sort the items by declaring Vi 3. Find j such that s1+s2+…..+ sn<= S < s1+s2+…..+ sn+1 4. IV. DYNAMIC ALGORITHM It is as follows. for i=1 to n if si < = s if vi + V[i-1,s- si] > V[i-1, s] V[i,s] = vi + V[i-1,s- si] else V[i,s] = V[i-1,s] else V[i,s] = V[i-1,s] V. RESULT ANALYSIS Implemented knapsack problem with different values of weight and profit or value in Turbo C. If we consider a data value is w={1, 2, 5}, v={1, 6, 18} and Carrying capacity W= 7 then output of greedy is: Fig. 1 Solved by Greedy approach Same data values and solving by Dynamic programming.
  • 3. International Journal of Modern Trends in Engineering and Research(IJMTER) Volume 01, Issue 01, July- 2014 e-ISSN: 2349-9745 @IJMTER-2014, All rights Reserved 7 Fig. 2 Solved by Dynamic programming After implemented knapsack problem in c programming for different values of weight and profit. Result of both methods gives same optimal solution and different time. Method Input Data Capacity Profit Time Greedy W={1,3,4,5} V={1,4,5,6} 9 11 15.86 W={1,2,5,6,7} , V={1,6,18,20,28} 11 40 25.73 W={10,20,30,40,50} V={10,30,64,50,60} 100 156 21.68 Dynamic W={1,3,4,5} V={1,4,5,6} 9 11 17.69 W={1,2,5,6,7} , V={1,6,18,20,28} 11 40 18.47 W={10,20,30,40,50} V={10,30,64,50,60} 100 156 19.65 VI. CONCLUSION In this paper we conclude that for particular one knapsack problem we can implement two methods greedy and dynamic. But when we implemented both method for different dataset values then we notice something like, we consider comparison parameter as optimal profit or total value for filling knapsack using available weight then dynamic and greedy both are gaining same profit. If we consider time then dynamic take less amount of time compare with greedy. So we can conclude that dynamic is better than greedy with respect to time. REFERENCES [1]. George B. Dantzig, Discrete-Variable Extremum Problems, Operations Research Vol. 5, No. 2, April 1957, pp. 266–288,doi:10.1287/opre.5.2.266 [2] Gossett, Eric. Discreet Mathematics with Proof. New Jersey: Pearson Education Inc., 2003.
  • 4. International Journal of Modern Trends in Engineering and Research(IJMTER) Volume 01, Issue 01, July- 2014 e-ISSN: 2349-9745 @IJMTER-2014, All rights Reserved 8 [3] Levitin, Anany. The Design and Analysis of Algorithms. New Jersey: Pearson Education Inc., 2003. [4] Mitchell, Melanie. An Introduction to Genetic Algorithms. Massachusettss: The MIT Press, 1998. [5] Obitko, Marek. ―Basic Description.‖ IV. Genetic Algorithm. Czech Technical University (CTU). http://cs.felk.cvut.cz/~xobitko/ga/gaintro.html [6] Different Approaches to Solve the 0/1 Knapsack Problem. Maya Hristakeva, Dipti Shrestha; Simpson Colleges