1 / 10

Ye Junjie

Greedy Algorithm & Assignment 3 Discussion CSCI3160 tutorial (7 t h week) Office: SHB 913 Office Hour: (Mon) 10:00 -12:00 Email: jjye@cse.cuhk.edu.hk. Ye Junjie. Outline. Greedy Algorithm Coin Changing Bin Packing Assignment 3 Discussion . Coin Changing.

season
Télécharger la présentation

Ye Junjie

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Greedy Algorithm & Assignment 3 DiscussionCSCI3160 tutorial (7th week)Office: SHB 913 Office Hour: (Mon) 10:00 -12:00 Email: jjye@cse.cuhk.edu.hk Ye Junjie

  2. Outline Greedy Algorithm Coin Changing Bin Packing Assignment 3 Discussion

  3. Coin Changing Suppose that in a certain country, the coin dominations consist of: $1, $2, $5, $10 You want to design an algorithm such that you can make change of any x dollars using the fewest number of coins.

  4. Coin Changing Greedy algorithm: 1. Create an empty bag 2. while (x > 0) { Find the largest coin c at most x; Put c in the bag; Set x = x –c ; } 3. Return coins in the bag

  5. Bin Packing Bin Packing: In the bin packing problem, objects of different volumes must be packed into a finite number of bins or containers each of volume V in a way that minimizes the number of bins used. There are many variations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. http://en.wikipedia.org/wiki/Bin_packing_problem

  6. Bin Packing First-fit Algorithm: The algorithm processes the items in arbitrary order. For each item, it attempts to place the item in the first bin that can accommodate the item. If no bin is found, it opens a new bin and puts the item within the new bin. How good is the greedy algorithm comparing the optimal solution?

  7. Bin Packing First-fit Algorithm: It is impossible for 2 bins to be at most half full. Otherwise, it means at some point one bin is at most half full and we open a new bin to accommodate an item of size at most half capacity. Thus if we have B bins, at least B − 1 bins are more than half full. We have B ≤ 2OPT. Other Algorithms: Best-fit and etc…

  8. Assignment 3 Discussion 4.9: Consider a directed graph in which the only negative edges are those that leave s; all other edges are positive. Can Dijkstra’s algorithm apply? Use induction on set S to prove the correctness. 5.9(b): If G has a cycle with a unique heaviest edge e, then e can not be part of any MST. Replace e with other edge

  9. Assignment 3 Discussion For the Greedy-MST algorithm, prove that the colourinvariant holds after an application of the red rule: We need to prove that after applying a red rule, there is still a MST containing all blue edges. Bonus(1-spanner): Prove that for a MST M, T contains all edges of M.

  10. Thank you! Q&A

More Related