




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Greedy algorithms
Presented by Dr. Matloob Khushi School of Computer Science
Undirected graphs
Directed graphs
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum.
Only works for some sets of coins!
E.g. Won't work for {20c, 12c, 5c} and change amount $0.
Also won't work for {20c, 12c, 1c} and $0.
Does work in easily identifiable cases
Will always work if each coin is an integer multiple of the next smallest denomination:
e.g. {40c, 20c, 10c, 1c}
Will work for base conversion
e.g. Convert 19 to binary ({…, 16, 8, 4, 2, 1}):
Does work in easily identifiable cases
Will always work if each coin is an integer multiple of the next smallest denomination:
e.g. {40c, 20c, 10c, 1c}
Will work for base conversion
e.g. Convert 19 to binary ({…, 16, 8, 4, 2, 1}):
19 = 16 +
Does work in easily identifiable cases
Will always work if each coin is an integer multiple of the next smallest denomination:
e.g. {40c, 20c, 10c, 1c}
Will work for base conversion
e.g. Convert 19 to binary ({…, 16, 8, 4, 2, 1}):
19 = 16 + 2 + 1
Does work in easily identifiable cases
Will always work if each coin is an integer multiple of the next smallest denomination:
e.g. {40c, 20c, 10c, 1c}
Will work for base conversion
e.g. Convert 19 to binary ({…, 16, 8, 4, 2, 1}):
19 = 16 + 2 + 1 = 10011 2
0 1 2 3 4 5 6 7 8 9 10 11 Time
f g h
e
a b c d
0 1 2 3 4 5 6 7 8 9 10 11 Time
f g h
e
a b c d
Time 0
A
C
F
B
D
G
E
1 2 3 4 5 6 7 8 9 10 11
H
0 1 2 3 4 5 6 7 8 9 10 11
Time 0
A
C
F
B
D
G
E
1 2 3 4 5 6 7 8 9 10 11
H
0 1 2 3 4 5 6 7 8 9 10 11