Presentation is loading. Please wait.

Presentation is loading. Please wait.

The results for Challenging Problem 1.

Similar presentations


Presentation on theme: "The results for Challenging Problem 1."— Presentation transcript:

1 The results for Challenging Problem 1.
You can find the results at the web site: Contact Mr. Liu Xiaowen directly if you have any problem concerning this. Liu Xiaowen: Phone: 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

2 CS3335 Design and Analysis of Algorithms/WANG Lusheng
Greedy Algorithms: A greedy algorithm always makes the choice that looks best at the moment. It makes a local optimal choice in the hope that this choice will lead to a globally optimal solution. Greedy algorithms yield optimal solutions for many (but not all) problems. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

3 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

4 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

5 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

6 Greedy works for denominations 10, 5, and 1
Strategy for Proof: (The strategy can be used for many problems. The hard part.) Compare an optimal solution with the solution given by greedy algorithm (bit by bit, or component by component). Let an optimal solution, denoted (x, y, z), have: x 10 dollar coins , y 5 dollar coins and z 1 dollar coins. Let the solution obtained from our greedy algorithm, denoted (x’, y’, z’) have: x’ 10 dollar coins , y’ 5 dollar coins and z’ 1 dollar coins. Show that the two solutions are the same. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

7 Greedy works for denominations 10, 5, and 1 (Fun part, not tested)
Theorem: The greedy algorithm works for denominations: 10, 5 and 1. Proof: We compare x and x’ (# of 10 dollar coins), (y and y’) # of 5 dollar coins and (z and z’) # of 1 dollar coins, one by one. Comparison of x and x’. Since x’ is from greedy algorithm, x’x. If x’>x, then y5+ z 1 10. (because x  10+ y5+ z 1 = x’ 10+y’5+ z ‘1 ) Thus, we can modify the optimal solution (x, y, z) using one more 10 dollar coin to replace 10 dollars that are expressed by (1) two 5 dollar coins, (2) one 5 dollar coin +five 1 dollar coins or (3) ten 1 dollar coins. The new solution (x+1, y’’, z’’) contains less # of coins than (x, y, z). Contradiction! Because by assumption, (x, y, z) is optimum. Thus, x’>x cannot be true. Therefore, x’=x. Similarly, we can show y’=y and z’=z. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

8 Strange denominations:
7 dollars, 5 dollars and 1 dollars Greedy algorithm for 11 dollars: 7dollars+4 1 dollar=11 dollars. (5 coins are required.) A better way: 2 5 dollars +1 dollar=11 dollars. (3 coins are required) Sometimes the greedy algorithm does not work. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

9 The 0-1 Knapsack problem:
N items, where the i-th item is worth vi dollars and weight wi pounds. vi and wi are integers. A thief can carry at most W (integer) pounds. How to take as valuable a load as possible. An item cannot be divided into pieces. The fractional knapsack problem: The same setting, but the thief can take fractions of items. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

10 Solve the fractional Knapsack problem:
Greedy on the value per pound vi/wi. Each time, take the item with maximum vi/wi . If exceeds W, take fractions of the item. Proof of correctness: (The hard part) Let X = i1, i2, …ik be the optimal items taken. Consider the item j with the highest vi /wi. if j is not used in X (the optimal solution), get rid of some items (possibly fractional items) and add item j. (since fractional items are allowed, we can do it.) Total value is increased. One more item selected by greedy is added to X Repeat the process, X is changed to contain all items selected by greedy WITHOUT decreasing the total value taken by the thief. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

11 The 0-1 knapsack problem cannot be solved optimally by greedy
Counter example: (moderate part) W=10 Items found (6pounds, 12dollars), (5pounds, 9 dollar), (5pounds, 9 dollars), (3pounds, 3 dollars), (3 pounds, 3 dollars) If we first take (6, 12) according to greedy algorithm, then solution is (6, 12), (3, 3) (total value is 12+3=15). However, a better solution is (5, 9), (5, 9) with total value 18. To show that a statement does not hold, we only have to give an example. To show that the theorem is true, we have to give an proof. 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

12 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

13 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

14 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

15 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

16 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

17 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

18 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

19 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

20 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

21 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

22 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

23 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

24 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

25 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

26 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

27 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

28 CS3335 Design and Analysis of Algorithms/WANG Lusheng
Example: 1, 2, 3, 4, 5, 6, 7, 8, 9 1, 2, 6, 7, 3, 4, 5, 8, 9 2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

29 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

30 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng

31 CS3335 Design and Analysis of Algorithms/WANG Lusheng
2019/4/29 CS3335 Design and Analysis of Algorithms/WANG Lusheng


Download ppt "The results for Challenging Problem 1."

Similar presentations


Ads by Google