Lecture 12 Greedy Algorithms
Lecture 12 Greedy Algorithms
Algorithms
Mansi A. Radke
Disclaimer
• 1 10
• 5 1
Or
• 2 7
• 1 1
Take away
• Greedy algorithm does not always
give an optimal solution!
N=5
W = 100
Valuable first
• 3,5,half of 4
• 66 + 60 + 40/2 = 146
Lighter first
• 1,2,3,4
• 20+30+66+40 = 156
W 10 20 30 40 50
V 20 30 66 40 60
V/W 2 1.5 2.2 1 1.2
3,1,2,4/5 of 5
20+30+66+4/5 of 60 = 164 !
Time complexity