Session Objectives
At the end of this session, the learner will be able to:
Explain the control abstraction with respect to greedy Algorithms.
Identify and classify the various problems under greedy design technique.
Clearly distinguish the greedy method with the divide and conquer
method.
Apply the greedy methodology to the identified problems.
Greedy Technique
G.Kanagasabapathy AAMCE
Session Plan
Time
(in min)
10
10
10
Content
Greedy Method
Greedy method-an
Introduction
Identifying the
Problems Under
Greedy Method
An example for
greedy method
10
Comparison between
divide and conquer
and greedy algorithm
10
Conclusion and
summary
Greedy Technique
G.Kanagasabapathy AAMCE:
Learning Aid
and
Methodology
Analogy
Faculty
Approach
Narrates
Board Activity
Presentation
Explains
PPT
Facilitates
Monitors
Board Activity
Presentation
Board Activity
Explains
Explains
Listen
Facilitates
Typical Student
Activity
Listens
Understands
Listens
Participates
Participates
Listen
participates
Listen
participates
Participates
Identifies
Skill and
Competency
Developed
Knowledge
Comprehension
Knowledge
Comprehension
Intrapersonal
Interpersonal
Visual
Spatial
Linguistic
Knowledge
Comprehension
Intrapersonal
Interpersonal
Knowledge
Comprehension
Intrapersonal
Interpersonal
Linguistic
Knowledge
Comprehension
Intrapersonal
Interpersonal
Linguistic
Knowledge
Comprehension
Intrapersonal
Interpersonal
Page 3
Session Inputs
Greedy Method
Since the learners are already familiar with the concept, the best
way is to start the session by giving analogy.
A dog was going towards the forest holding a piece of bread in
his mouth. On his way, while he was crossing a pond of water, he
saw his own reflection. He thought that there was another dog in
the water, who holding another piece of bread in his mouth. He
thought, "If I grab his piece of bread, I would have more bread".
So when he opened his mouth to grab the piece of bread, his
piece, dropped into the water. He felt very sad. The one, who
wants the whole, leaving the half, gets nothing.
We are not debating if the greedy method is good or bad, but it
is true that it is an important algorithm design technique which
scans the list of inputs and adds to the existing solution, only if the
input satisfies the problem constraints. Thus, it will have a greedy
grab on every possible input.
D:\Thanjavur\Anjalai
Ammal Mahalingam\kanaga Sabhapathy\greedy.ppt
Greedy Technique
G.Kanagasabapathy AAMCE
Algorithm Greedy(a,n)
// a[1:n] contains the n inputs
{
solution :=0;
for i:= 1 to n do
{
x:= Select(a);
if Feasible ( solution, x) then
solution:=Union(solution,x);
}
return solution;
}
The function Select selects an input a[] and removes it.
Greedy Technique
G.Kanagasabapathy AAMCE:
Page 5
i ranges from 1 to n
I ranges from 1 to n
The following pseudo code contains solving the knapsack problem under
greedy method. This control structure forms the basis of solving most of the
problems under greedy method.
Algorithm GreedyKnapsack( m,n)
// P[1:n] and w[1:n] contain the profits and weights respectively.
// of the n objects ordered such that p[i]/w[i] >= p[i+1]/w[i+1].
// m is the knapsack size and x[1:n] is the solution vector.
{
for i:= 1 to n do x[i]=0.0;
U:= m;
for i:=1 to m do
{
Greedy Technique
G.Kanagasabapathy AAMCE
C:\
wipromission10Xworshop\greedy method_1.ppt
Greedy Technique
G.Kanagasabapathy AAMCE:
Page 7
Conclusion
After learning two techniques in algorithm namely greedy
method and divide and conquer. Now, it would be a right time to
conduct a pick and place activity to understand the knowledge
level of the learners.
Suggested Activity: Pick and Place
Place three bins. The bins are named as greedy, divide and conquer and
others. Place list of problems in a common bin. Divide the learners into
three teams A, B and C. Within 10 minutes each team should pick as many
problems from the common bin and place them into the appropriate bin
after identifying the correct category.
The problems would be:
Quick sort
Merge sort
Selection sort
Shortest path
Minimum scanning tree
Huffman code
Trapezoidal rule
Greedy Technique
G.Kanagasabapathy AAMCE
Summary
In this session, we learnt to:
Explain the control abstraction of greedy algorithms.
Identify and classify the problems in the pretext of greedy algorithms.
Clearly identify the differences between greedy methods and divide and
conquer algorithm.
Apply the greedy methodology for the problems identified.
Greedy Technique
G.Kanagasabapathy AAMCE:
Page 9
Assignment
1. Design a greedy algorithm for Tree vertex splitting (TVS) problem.
Implement your algorithm on a language of your choice.
2. Design a greedy algorithm for the construction of minimum spanning tree
(MST). Implement your algorithm in a language of your choice.
3. Design a greedy algorithm for computing the shortest path from a single
source to multiple destinations (Dijkstras algorithm). Implement your
algorithm in a language of your choice.
Greedy Technique
G.Kanagasabapathy AAMCE
References
Introduction to The Design & Analysis of Algorithms Anany Levitin,
pearson Education.
Fundamentals of Computer Algorithms- Ellis Horowitz,Sartaj Sahani
,Sanguthevar Rajasekaran-Galgotia publications.
Introduction to Algorithms- Thomas H.Cormen,Charles E. Leiserson,Ronald
L.Rivest- Prentice Hall India.
Greedy Technique
G.Kanagasabapathy AAMCE:
Page 11