1 / 17

Intro to Computer Algorithms Lecture 18

Intro to Computer Algorithms Lecture 18. Phillip G. Bradford Computer Science University of Alabama. Announcements. Advisory Board’s Industrial Talk Series http://www.cs.ua.edu/9IndustrialSeries.shtm 2-Dec: Mike Thomas, CIO, Gulf States Paper Next Research Colloquia:

lucien
Télécharger la présentation

Intro to Computer Algorithms Lecture 18

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. Intro to Computer Algorithms Lecture 18 Phillip G. Bradford Computer Science University of Alabama

  2. Announcements • Advisory Board’s Industrial Talk Series • http://www.cs.ua.edu/9IndustrialSeries.shtm • 2-Dec: Mike Thomas, CIO, Gulf States Paper • Next Research Colloquia: • Prof. Nael Abu-Ghazaleh • 10-Nov @ 11:00am • “Active Routing in Mobile Ad Hoc Networks”

  3. Computer Security Research Group • Meets every Friday from 11:00 to 12:00 • In 112 Houser • Computer Security, etc. • Email me to be on the mailing list!

  4. CS Story Time • Prof. Jones’ research group • See http://cs.ua.edu/StoryHourSlide.pdf

  5. Next Midterm • Tuesday before Thanksgiving ! • 25-November

  6. Outline • Complete Dynamic Programming • Principle of Optimality • Start the Greedy Design Paradigm

  7. Dynamic Programming • Principle of optimality • Consider any well-formed substructure s of an optimal structure S • Then s is optimal itself. • This allows the combination of well-formed substructures into optimal superstructures

  8. Knapsack Problem • Section 3.4 from the book

  9. Knapsack Problem • Suppose the knapsack’s capacity is • W=10 • What subsets can we choose within the knapsack’s capacity while maximizing the subsets value? • Note: {3,4} is optimal • Does not include item 1 (of the highest value)

  10. Apparent worst-case? • Try all subsets! • Can we find a better algorithm? • It is not clear!

  11. Other than exhaustive search? • Dynamic programming • V[i,j] is the optimal solution for • w1,…,wi (having values v1,…,vi) • And capacity j: W > j > 1. • Want to find V[n,W] • Suppose W is a base-10 integer, then how large is this table???

  12. DP Recurrence for Knapsack • Can we fit the ith item? • No, then optimal solution is V[i-1,j] • Yes, then optimal solution • Includes ith item: vi + V[i-1,j-wi] • Does not include the ith item: V[i-1,j] • If j-wi> 0 • V[i,j]  max{ V[i-1,j], vi + V[i-1,j-wi] }

  13. DP Recurrence for Knapsack • Base Cases • V[0,j] = 0 • No items in knapsack (with j capacity) has no value • V[i,0] = 0 • Zero capacity, putting items 1,…,i does no good

  14. Computing this DP Recurrence Capacity 0, 1, j-wi W 0 0 0 0 0 1 0 Value n 0

  15. The Greedy Paradigm • Greedy Principle: • Start with an (optimal) solution and adding locally optimal structure eventually gives a globally optimal solution

  16. The Greedy Paradigm • Change Making Problem • Not necessarily optimal • d1>d2> … > dn • Give back correct change • Greedy Method • Start with largest denomination • Exhaust it, • On to next smaller denomination

  17. Prim’s Algorithm • Spanning Tree of an undirected graph • Acyclic subgraph containing all nodes • Minimum weight spanning tree • Weighted edges • Among the least cost spanning trees • The algorithm • The inductive Proof of optimality

More Related