PPT: Greedy Techniques | Algorithms - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


Greedy 
Techniques
Page 2


Greedy 
Techniques
Introduction
Objective
Understand the greedy method and its application 
in algorithm design.
Definition
A problem-solving strategy that makes the locally 
optimal choice at each step to achieve a globally 
optimal solution.
Key Steps
Identify the greedy choice, make the choice and 
reduce the problem, repeat until solved.
Applications
Scheduling, shortest paths, minimum spanning 
trees, coding.
Page 3


Greedy 
Techniques
Introduction
Objective
Understand the greedy method and its application 
in algorithm design.
Definition
A problem-solving strategy that makes the locally 
optimal choice at each step to achieve a globally 
optimal solution.
Key Steps
Identify the greedy choice, make the choice and 
reduce the problem, repeat until solved.
Applications
Scheduling, shortest paths, minimum spanning 
trees, coding.
Greedy vs. Other Techniques
Greedy Method
Makes locally optimal choices that 
are fast and simple, but not always 
globally optimal. Examples include 
Fractional Knapsack (optimal) and 
Activity Selection.
Dynamic Programming
Considers all possibilities and 
guarantees global optimum, as 
seen in the 0/1 Knapsack problem. 
More comprehensive but 
potentially slower.
Divide and Conquer
Splits the problem and solves 
recursively, like in Merge Sort. 
Effective for problems that can be 
broken down into similar 
subproblems.
Use greedy algorithms when the problem has greedy choice property and optimal substructure. Always verify that 
the greedy choice leads to a global optimum before implementation.
Page 4


Greedy 
Techniques
Introduction
Objective
Understand the greedy method and its application 
in algorithm design.
Definition
A problem-solving strategy that makes the locally 
optimal choice at each step to achieve a globally 
optimal solution.
Key Steps
Identify the greedy choice, make the choice and 
reduce the problem, repeat until solved.
Applications
Scheduling, shortest paths, minimum spanning 
trees, coding.
Greedy vs. Other Techniques
Greedy Method
Makes locally optimal choices that 
are fast and simple, but not always 
globally optimal. Examples include 
Fractional Knapsack (optimal) and 
Activity Selection.
Dynamic Programming
Considers all possibilities and 
guarantees global optimum, as 
seen in the 0/1 Knapsack problem. 
More comprehensive but 
potentially slower.
Divide and Conquer
Splits the problem and solves 
recursively, like in Merge Sort. 
Effective for problems that can be 
broken down into similar 
subproblems.
Use greedy algorithms when the problem has greedy choice property and optimal substructure. Always verify that 
the greedy choice leads to a global optimum before implementation.
Activity Selection Problem
Sort Activities
Arrange all activities by their finish times in 
ascending order.
Select First Activity
Choose the activity with the earliest finish time and 
set last_finish to its finish time.
Select Next Compatible Activities
For each subsequent activity, if its start time g last_finish, select it and update last_finish.
For example, with activities [(1, 4), (3, 5), (0, 6), (5, 7), (3, 8), (5, 9)], after sorting by finish time, we select (1, 4), 
(5, 7), and (5, 9), resulting in 3 activities. The time complexity is O(n log n) due to sorting.
Page 5


Greedy 
Techniques
Introduction
Objective
Understand the greedy method and its application 
in algorithm design.
Definition
A problem-solving strategy that makes the locally 
optimal choice at each step to achieve a globally 
optimal solution.
Key Steps
Identify the greedy choice, make the choice and 
reduce the problem, repeat until solved.
Applications
Scheduling, shortest paths, minimum spanning 
trees, coding.
Greedy vs. Other Techniques
Greedy Method
Makes locally optimal choices that 
are fast and simple, but not always 
globally optimal. Examples include 
Fractional Knapsack (optimal) and 
Activity Selection.
Dynamic Programming
Considers all possibilities and 
guarantees global optimum, as 
seen in the 0/1 Knapsack problem. 
More comprehensive but 
potentially slower.
Divide and Conquer
Splits the problem and solves 
recursively, like in Merge Sort. 
Effective for problems that can be 
broken down into similar 
subproblems.
Use greedy algorithms when the problem has greedy choice property and optimal substructure. Always verify that 
the greedy choice leads to a global optimum before implementation.
Activity Selection Problem
Sort Activities
Arrange all activities by their finish times in 
ascending order.
Select First Activity
Choose the activity with the earliest finish time and 
set last_finish to its finish time.
Select Next Compatible Activities
For each subsequent activity, if its start time g last_finish, select it and update last_finish.
For example, with activities [(1, 4), (3, 5), (0, 6), (5, 7), (3, 8), (5, 9)], after sorting by finish time, we select (1, 4), 
(5, 7), and (5, 9), resulting in 3 activities. The time complexity is O(n log n) due to sorting.
Fractional Knapsack Problem
Compute Value/Weight Ratio
Calculate the value-to-weight ratio for each available item.
Sort Items
Arrange items by decreasing value/weight ratio.
Fill Knapsack
Add items (or fractions) in order until capacity is reached.
For example, with items [(60, 10), (100, 20), (120, 30)] and capacity W = 50, we calculate ratios [6, 5, 4]. We add the 
entire first two items and 2/3 of the third, achieving a total value of 240. Unlike the 0/1 Knapsack problem, the 
fractional version allows for greedy optimality.
Read More
81 videos|113 docs|33 tests

FAQs on PPT: Greedy Techniques - Algorithms - Computer Science Engineering (CSE)

1. What are greedy techniques in algorithm design?
Ans.Greedy techniques are algorithmic strategies that make a series of choices, each of which looks best at the moment, with the hope of finding a global optimum. These techniques are used to solve optimization problems by selecting the locally optimal solution at each step without reconsidering previous choices.
2. What are some common applications of greedy algorithms?
Ans.Greedy algorithms are commonly applied in various fields, including graph algorithms (like Kruskal's and Prim's for minimum spanning trees), optimization problems (like the knapsack problem), and scheduling problems. They can also be seen in algorithms for Huffman coding and Dijkstra's algorithm for shortest paths.
3. How do greedy algorithms differ from dynamic programming?
Ans.Greedy algorithms differ from dynamic programming in that they make decisions sequentially and do not reconsider previous choices, while dynamic programming solves complex problems by breaking them down into simpler subproblems and storing the results of these subproblems to avoid redundant computations. Greedy solutions are often simpler but may not always yield the optimal solution, unlike dynamic programming.
4. What are the advantages and disadvantages of using greedy algorithms?
Ans.The advantages of greedy algorithms include their simplicity and efficiency, as they often have lower time complexity compared to other methods. However, their main disadvantage is that they do not always guarantee a global optimum solution, as they can lead to suboptimal results in certain problems.
5. Can you give an example of a problem where a greedy algorithm works effectively?
Ans.An example of a problem where a greedy algorithm works effectively is the activity selection problem. In this problem, given a set of activities with start and end times, the goal is to select the maximum number of activities that do not overlap. A greedy approach that always selects the next activity that finishes the earliest leads to an optimal solution.
Related Searches

study material

,

PPT: Greedy Techniques | Algorithms - Computer Science Engineering (CSE)

,

Free

,

Semester Notes

,

practice quizzes

,

Viva Questions

,

mock tests for examination

,

Sample Paper

,

past year papers

,

Extra Questions

,

Summary

,

Previous Year Questions with Solutions

,

ppt

,

video lectures

,

Important questions

,

shortcuts and tricks

,

PPT: Greedy Techniques | Algorithms - Computer Science Engineering (CSE)

,

MCQs

,

Exam

,

Objective type Questions

,

pdf

,

PPT: Greedy Techniques | Algorithms - Computer Science Engineering (CSE)

;