COEN 179 Lecture Notes - Lecture 19: Zapatista Army Of National Liberation, Dynamic Programming, Alnitak

11 views5 pages

Document Summary

P1(a[lohi]){ assert(lo + 1 <= hi); ans = -inf; for(i = lo; i < hi; ++i) for(j = i + 1; j <= hi; ++j) ans = max(ans, abs(a[i], a[j]); return ans; P2(a[lohi]){ assert(lo + 1 <= hi); mergesort(a[lohi]); return a[hi] - a[lo]; A[lo] : 0. 0; mid = (lo + hi) / 2; return p4(a[lomid]) + p4(a[mid+1hi]); Used for optimization problems when greedy technique fails similar to greedy. Dp tries all alternatives to reduce the problem. Unlike exhaustive search, dp uses caching to solve intermediate results. Caching helps keep running time to o(n^2, n^3, n^4 ) and not exponential. Greedy does not give an optimal answers denomination set is {1, 5, 7, 10, 25} Dp calls for looking at all choices for the first coin. e. g. n = 11. Note that when implemented recursively the same subproblem , Chas , sete) are saved nwitrmetimes interdependent recursive cans.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers