Ingredients of Greedy Algorithms - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Ingredients of Greedy Algorithms

Description:

Depends on choices made so far but not those made. in the future. Optimal substructure. An optimal solution to a problem contains optimal solutions. to subproblems. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 10
Provided by: toshi155
Category:

less

Transcript and Presenter's Notes

Title: Ingredients of Greedy Algorithms


1
Ingredients of Greedy Algorithms
When is a greedy strategies applicable?
A sequence of locally optimal choices can yield a
globally optimal solution.
Depends on choices made so far but not those
made in the future.
An optimal solution to a problem contains optimal
solutions to subproblems.
2
0-1 Knapsack Problem
3
1
30
20 lb.
2
10
100 60 120
Carry as valuable a load W lbs as possible!
But no fractional amount of any item can be taken.
3
Fractional Knapsack Problem
3
30
1
30
20
2/3 of item 3
20 lb.
2
(80)
10
knapsack
100 60 120
Same description as 0-1 knapsack except fractions
of items can be taken.
4
Optimal Substructure I
0-1 knapsack
Most valuable load W lbs
5
Optimal Substructure II
Fractional knapsack (FK)
Most valuable load W lbs
6
Greedy Algorithm for FK
knapsack (50 lb.)
O(n lg n) including the sorting time.
7
No Greedy for 0-1Knapsack
20
optimal solution
greedy solution
Need to use dynamic programming!
8
A DP Solution to 0-1
Subproblem
KW, n will be the solution.
9
Recursive Definition
0 if w 0
or i 0
Kw, i
.
Running time O(nW)
.
Write a Comment
User Comments (0)
About PowerShow.com