SlideShare a Scribd company logo
8
Most read
12
Most read
Bachelor of Science in Artificial Intelligence and
Machine Learning
Course Name : Design and analysis of algorithms
Subject Code : UGCA1979
Semester : B.S.c AI&ML-3rd
by
Associate Professor, DCA, CBSA
Course Objectives
CO# Course Outcomes
CO1 relate the characteristics of different algorithms and their analysis methods.
CO2 compare and contrast the time and space trade-offs in algorithm analysis.
CO3 apply various fundamental algorithmic strategies
CO4 analyze the application techniques in solving specific problems.
CO5 utilize different traversal and shortest path algorithms.
Greedy Algorithms
• A greedy algorithm always makes the choice that looks best at the moment. That is, it
makes a locally optimal choice in the hope that this choice will lead to a globally
optimal solution.
• The greedy method is quite powerful and works well for a wide range of problems.
• A greedy algorithm, as the name suggests, always makes the choice that seems to be
the best at that moment. This means that it makes a locally-optimal choice in the
hope that this choice will lead to a globally-optimal solution.
Greedy Algorithms
Steps for Creating a Greedy Algorithm
• The steps to define a greedy algorithm are:
• Define the problem: Clearly state the problem to be solved and the
objective to be optimized.
• Identify the greedy choice: Determine the locally optimal choice at
each step based on the current state.
• Make the greedy choice: Select the greedy choice and update the
current state.
• Repeat: Continue making greedy choices until a solution is reached.
Greedy Algorithm Examples
• Examples of greedy algorithms are the best way to understand the
algorithm. Some greedy algorithm real-life examples are:
• Fractional Knapsack: Optimizes the value of items that can be
fractionally included in a knapsack with limited capacity.
• Dijkstra’s algorithm: Finds the shortest path from a source vertex to
all other vertices in a weighted graph.
• Kruskal’s algorithm: Finds the minimum spanning tree of a weighted
graph.
Applications of Greedy Algorithm
• There are many applications of the greedy method in DAA. Some
important greedy algorithm applications are:
• Assigning tasks to resources to minimize waiting time or maximize
efficiency.
• Selecting the most valuable items to fit into a knapsack with limited
capacity.
• Dividing an image into regions with similar characteristics.
• Reducing the size of data by removing redundant information.
Advantages of the Greedy Method
• The greedy approach is easy to implement.
• Typically have less time complexity.
• Greedy algorithms can be used for optimization purposes or finding close to
optimization in case of Hard problems.
• Greedy algorithms can produce efficient solutions in many cases, especially
when the problem has a substructure that exhibits the greedy choice property.
• Greedy algorithms are often faster than other optimization algorithms, such as
dynamic programming or branch and bound, because they require less
computation and memory.
Disadvantages/Limitations of Using a Greedy Algorithm
• Greedy algorithms may not always find the best possible solution.
• The order in which the elements are considered can significantly
impact the outcome.
• Greedy algorithms focus on local optimizations and may miss better
solutions that require considering a broader context.
• Greedy algorithms are not applicable to problems where the greedy
choice does not lead to an optimal solution.
Difference between Greedy Algorithm and Divide and Conquer
Algorithm
S.No Divide and conquer Greedy Algorithm
1
Divide and conquer is used to obtain a
solution to the given problem, it does not
aim for the optimal solution.
The greedy method is used to obtain an optimal solution to
the given problem.
2
In this technique, the problem is divided
into small subproblems. These
subproblems are solved independently.
Finally, all the solutions to subproblems
are collected together to get the solution
to the given problem.
In Greedy Method, a set of feasible solutions are generated
and pick up one feasible solution is the optimal solution.
3
Divide and conquer is less efficient and
slower because it is recursive in nature.
A greedy method is comparatively efficient and faster as it is
iterative in nature.
Fractional Knapsack Problem using Greedy algorithm
• The basic idea of the greedy approach is to calculate the
ratio profit/weight for each item and sort the item on the basis of this
ratio. Then take the item with the highest ratio and add them as much
as we can (can be the whole element or a fraction of it).
• This will always give the maximum profit because, in each step it adds
an element such that this is the maximum possible profit for that
much weight.
Example
• Consider the example: arr[] = {{100, 20}, {60, 10}, {120, 30}}, W = 50.
Sorting: Initially sort the array based on the profit/weight ratio. The sorted array will be {{60,
10}, {100, 20}, {120, 30}}.
Iteration:
• For i = 0, weight = 10 which is less than W. So add this element in the knapsack. profit =
60 and remaining W = 50 – 10 = 40.
• For i = 1, weight = 20 which is less than W. So add this element too. profit = 60 + 100 =
160 and remaining W = 40 – 20 = 20.
• For i = 2, weight = 30 is greater than W. So add 20/30 fraction = 2/3 fraction of the element.
Therefore profit = 2/3 * 120 + 160 = 80 + 160 = 240 and remaining W becomes 0.
• So the final profit becomes 240 for W = 50.
Conclusions
Learning outcomes
1. Students are able to understand vitualization concept.
2. Students are able to identify key technologies like hypervisors and containers, and their roles in
cloud environments.

More Related Content

Similar to Greedy Method unit-2(Design and analysis of algorithms).pptx (20)

PPTX
Module 3_DAA (2).pptx
AnkitaVerma776806
 
PPTX
Knapsack problem using Greedy method.pptx
Rajapriya82
 
PPTX
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
PPTX
Unit 3- Greedy Method.pptx
MaryJacob24
 
PDF
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
PPTX
Knapsack problem using greedy approach
padmeshagrekar
 
PDF
Module 2 - Greedy Algorithm Data structures and algorithm
farzanirani201402
 
PPT
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
 
PPTX
7. Algorithm Design and analysis ppt.pptx
deivasigamani9
 
PPT
Greedymethod
Meenakshi Devi
 
PDF
heuristic search Techniques and game playing.pdf
vijeta3feb
 
DOC
Data structure notes
anujab5
 
PDF
greedy method.pdf
deepakjoshi29912
 
PPTX
Greedy algorithm for design and analysis
JavedKhan524377
 
PDF
Unit V.pdf
KPRevathiAsstprofITD
 
PPTX
Greedy Algorithms project presentation ppt.pptx
ParasBhoite1
 
PPTX
Greedy algorithm presentations final year.pptx
ParasBhoite1
 
PPT
Greedy method1
Rajendran
 
PPT
Unit 3-Greedy Method
DevaKumari Vijay
 
PDF
Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming
Editor IJMTER
 
Module 3_DAA (2).pptx
AnkitaVerma776806
 
Knapsack problem using Greedy method.pptx
Rajapriya82
 
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Unit 3- Greedy Method.pptx
MaryJacob24
 
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Knapsack problem using greedy approach
padmeshagrekar
 
Module 2 - Greedy Algorithm Data structures and algorithm
farzanirani201402
 
Greedy method by Dr. B. J. Mohite
Zeal Education Society, Pune
 
7. Algorithm Design and analysis ppt.pptx
deivasigamani9
 
Greedymethod
Meenakshi Devi
 
heuristic search Techniques and game playing.pdf
vijeta3feb
 
Data structure notes
anujab5
 
greedy method.pdf
deepakjoshi29912
 
Greedy algorithm for design and analysis
JavedKhan524377
 
Greedy Algorithms project presentation ppt.pptx
ParasBhoite1
 
Greedy algorithm presentations final year.pptx
ParasBhoite1
 
Greedy method1
Rajendran
 
Unit 3-Greedy Method
DevaKumari Vijay
 
Comparative analysis-of-dynamic-and-greedy-approaches-for-dynamic-programming
Editor IJMTER
 

Recently uploaded (20)

PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Hashing Introduction , hash functions and techniques
sailajam21
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Ad

Greedy Method unit-2(Design and analysis of algorithms).pptx

  • 1. Bachelor of Science in Artificial Intelligence and Machine Learning Course Name : Design and analysis of algorithms Subject Code : UGCA1979 Semester : B.S.c AI&ML-3rd by Associate Professor, DCA, CBSA
  • 2. Course Objectives CO# Course Outcomes CO1 relate the characteristics of different algorithms and their analysis methods. CO2 compare and contrast the time and space trade-offs in algorithm analysis. CO3 apply various fundamental algorithmic strategies CO4 analyze the application techniques in solving specific problems. CO5 utilize different traversal and shortest path algorithms.
  • 4. • A greedy algorithm always makes the choice that looks best at the moment. That is, it makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. • The greedy method is quite powerful and works well for a wide range of problems. • A greedy algorithm, as the name suggests, always makes the choice that seems to be the best at that moment. This means that it makes a locally-optimal choice in the hope that this choice will lead to a globally-optimal solution. Greedy Algorithms
  • 5. Steps for Creating a Greedy Algorithm • The steps to define a greedy algorithm are: • Define the problem: Clearly state the problem to be solved and the objective to be optimized. • Identify the greedy choice: Determine the locally optimal choice at each step based on the current state. • Make the greedy choice: Select the greedy choice and update the current state. • Repeat: Continue making greedy choices until a solution is reached.
  • 6. Greedy Algorithm Examples • Examples of greedy algorithms are the best way to understand the algorithm. Some greedy algorithm real-life examples are: • Fractional Knapsack: Optimizes the value of items that can be fractionally included in a knapsack with limited capacity. • Dijkstra’s algorithm: Finds the shortest path from a source vertex to all other vertices in a weighted graph. • Kruskal’s algorithm: Finds the minimum spanning tree of a weighted graph.
  • 7. Applications of Greedy Algorithm • There are many applications of the greedy method in DAA. Some important greedy algorithm applications are: • Assigning tasks to resources to minimize waiting time or maximize efficiency. • Selecting the most valuable items to fit into a knapsack with limited capacity. • Dividing an image into regions with similar characteristics. • Reducing the size of data by removing redundant information.
  • 8. Advantages of the Greedy Method • The greedy approach is easy to implement. • Typically have less time complexity. • Greedy algorithms can be used for optimization purposes or finding close to optimization in case of Hard problems. • Greedy algorithms can produce efficient solutions in many cases, especially when the problem has a substructure that exhibits the greedy choice property. • Greedy algorithms are often faster than other optimization algorithms, such as dynamic programming or branch and bound, because they require less computation and memory.
  • 9. Disadvantages/Limitations of Using a Greedy Algorithm • Greedy algorithms may not always find the best possible solution. • The order in which the elements are considered can significantly impact the outcome. • Greedy algorithms focus on local optimizations and may miss better solutions that require considering a broader context. • Greedy algorithms are not applicable to problems where the greedy choice does not lead to an optimal solution.
  • 10. Difference between Greedy Algorithm and Divide and Conquer Algorithm S.No Divide and conquer Greedy Algorithm 1 Divide and conquer is used to obtain a solution to the given problem, it does not aim for the optimal solution. The greedy method is used to obtain an optimal solution to the given problem. 2 In this technique, the problem is divided into small subproblems. These subproblems are solved independently. Finally, all the solutions to subproblems are collected together to get the solution to the given problem. In Greedy Method, a set of feasible solutions are generated and pick up one feasible solution is the optimal solution. 3 Divide and conquer is less efficient and slower because it is recursive in nature. A greedy method is comparatively efficient and faster as it is iterative in nature.
  • 11. Fractional Knapsack Problem using Greedy algorithm • The basic idea of the greedy approach is to calculate the ratio profit/weight for each item and sort the item on the basis of this ratio. Then take the item with the highest ratio and add them as much as we can (can be the whole element or a fraction of it). • This will always give the maximum profit because, in each step it adds an element such that this is the maximum possible profit for that much weight.
  • 12. Example • Consider the example: arr[] = {{100, 20}, {60, 10}, {120, 30}}, W = 50. Sorting: Initially sort the array based on the profit/weight ratio. The sorted array will be {{60, 10}, {100, 20}, {120, 30}}. Iteration: • For i = 0, weight = 10 which is less than W. So add this element in the knapsack. profit = 60 and remaining W = 50 – 10 = 40. • For i = 1, weight = 20 which is less than W. So add this element too. profit = 60 + 100 = 160 and remaining W = 40 – 20 = 20. • For i = 2, weight = 30 is greater than W. So add 20/30 fraction = 2/3 fraction of the element. Therefore profit = 2/3 * 120 + 160 = 80 + 160 = 240 and remaining W becomes 0. • So the final profit becomes 240 for W = 50.
  • 13. Conclusions Learning outcomes 1. Students are able to understand vitualization concept. 2. Students are able to identify key technologies like hypervisors and containers, and their roles in cloud environments.