SlideShare a Scribd company logo
7
Most read
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

PDF
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
PPTX
Introduction to the Greedy Algorithms - primer
PDF
Unit 3 - Greedy Method
PDF
Unit 3 greedy method
PPTX
daa-unit-3-greedy method
PPTX
esign and Analysis of Algorithms Presentation.pptx
PPTX
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
PDF
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"
Lec07-Greedy Algorithms.pdf Lec07-Greedy Algorithms.pdf
Introduction to the Greedy Algorithms - primer
Unit 3 - Greedy Method
Unit 3 greedy method
daa-unit-3-greedy method
esign and Analysis of Algorithms Presentation.pptx
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Mastering Greedy Algorithms: Optimizing Solutions for Efficiency"

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

PPTX
Ms nikita greedy agorithm
PPTX
Module 3_DAA (2).pptx
PPTX
Knapsack problem using Greedy method.pptx
PPTX
Divide and Conquer / Greedy Techniques
PPTX
Unit 3- Greedy Method.pptx
PDF
Analysis and Design of Algorithms notes
PPTX
Knapsack problem using greedy approach
PDF
Module 2 - Greedy Algorithm Data structures and algorithm
PPT
Greedy method by Dr. B. J. Mohite
PPTX
7. Algorithm Design and analysis ppt.pptx
PPT
Greedymethod
PDF
heuristic search Techniques and game playing.pdf
DOC
Data structure notes
PDF
greedy method.pdf
PPTX
Greedy algorithm for design and analysis
PDF
PPTX
Greedy Algorithms project presentation ppt.pptx
PPTX
Greedy algorithm presentations final year.pptx
PPT
Greedy method1
PPT
Unit 3-Greedy Method
Ms nikita greedy agorithm
Module 3_DAA (2).pptx
Knapsack problem using Greedy method.pptx
Divide and Conquer / Greedy Techniques
Unit 3- Greedy Method.pptx
Analysis and Design of Algorithms notes
Knapsack problem using greedy approach
Module 2 - Greedy Algorithm Data structures and algorithm
Greedy method by Dr. B. J. Mohite
7. Algorithm Design and analysis ppt.pptx
Greedymethod
heuristic search Techniques and game playing.pdf
Data structure notes
greedy method.pdf
Greedy algorithm for design and analysis
Greedy Algorithms project presentation ppt.pptx
Greedy algorithm presentations final year.pptx
Greedy method1
Unit 3-Greedy Method
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Welding lecture in detail for understanding
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Construction Project Organization Group 2.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT
Project quality management in manufacturing
PDF
Well-logging-methods_new................
composite construction of structures.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CH1 Production IntroductoryConcepts.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Welding lecture in detail for understanding
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Structs to JSON How Go Powers REST APIs.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
Lecture Notes Electrical Wiring System Components
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Project quality management in manufacturing
Well-logging-methods_new................
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.