CSCI 6212 Design and Analysis of Algorithms Dynamic Programming Dr. Juman Byun The George Washington University Please drop this course if you have not.

Slides:



Advertisements
Similar presentations
Rod cutting Decide where to cut steel rods:
Advertisements

Dynamic Programming.
Algorithm Design Methodologies Divide & Conquer Dynamic Programming Backtracking.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
UMass Lowell Computer Science Analysis of Algorithms Prof. Giampiero Pecelli Fall, 2010 Paradigms for Optimization Problems Dynamic Programming.
Lecture 8: Dynamic Programming Shang-Hua Teng. Longest Common Subsequence Biologists need to measure how similar strands of DNA are to determine how closely.
CPSC 335 Dynamic Programming Dr. Marina Gavrilova Computer Science University of Calgary Canada.
15.Dynamic Programming Hsu, Lih-Hsing. Computer Theory Lab. Chapter 15P.2 Dynamic programming Dynamic programming is typically applied to optimization.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Unit 4: Dynamic Programming
Dynamic Programming.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
Dynamic Programming Part 1: intro and the assembly-line scheduling problem.
Sorting. Input: A sequence of n numbers a 1, …, a n Output: A reordering a 1 ’, …, a n ’, such that a 1 ’ < … < a n ’
Dynamic Programming CIS 606 Spring 2010.
Lecture 28 CSE 331 Nov 9, Flu and HW 6 Graded HW 6 at the END of the lecture If you have the flu, please stay home Contact me BEFORE you miss a.
Dynamic Programming Code
CSC 2300 Data Structures & Algorithms January 26, 2007 Chapter 2. Algorithm Analysis.
Lecture 34 CSE 331 Nov 30, Graded HW 8 On Wednesday.
November 7, 2005Copyright © by Erik D. Demaine and Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example:
Lecture 8: Dynamic Programming Shang-Hua Teng. First Example: n choose k Many combinatorial problems require the calculation of the binomial coefficient.
CS Main Questions Given that the computer is the Great Symbol Manipulator, there are three main questions in the field of computer science: What kinds.
Dynamic Programming 0-1 Knapsack These notes are taken from the notes by Dr. Steve Goddard at
Analysis of Algorithms
Lecture 7 Topics Dynamic Programming
Lecture 30 CSE 331 Nov 10, Online Office Hours
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Dynamic Programming – Part 2 Introduction to Algorithms Dynamic Programming – Part 2 CSE 680 Prof. Roger Crawfis.
Lecture 5 Dynamic Programming. Dynamic Programming Self-reducibility.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 25, 2014.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
Recursion and Dynamic Programming. Recursive thinking… Recursion is a method where the solution to a problem depends on solutions to smaller instances.
1 Summary: Design Methods for Algorithms Andreas Klappenecker.
COSC 3101A - Design and Analysis of Algorithms 7 Dynamic Programming Assembly-Line Scheduling Matrix-Chain Multiplication Elements of DP Many of these.
LECTURE 40: SELECTION CSC 212 – Data Structures.  Sequence of Comparable elements available  Only care implementation has O(1) access time  Elements.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 28, 2014.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 21, 2014.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
Dynamic Programming continued David Kauchak cs302 Spring 2012.
Dynamic Programming (Ch. 15) Not a specific algorithm, but a technique (like divide- and-conquer). Developed back in the day when “programming” meant “tabular.
CSCI 6212 Design and Analysis of Algorithms Dr. Juman Byun The George Washington University Please drop this course if you have not taken the following.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
CSC5101 Advanced Algorithms Analysis
Dynamic Programming 又稱 動態規劃 經常被用來解決最佳化問題. Dynamic Programming2 Rod cutting problem Given a rod of length N inches and a table of prices p[i] for i=1..N,
Sorting Algorithms Merge Sort Quick Sort Hairong Zhao New Jersey Institute of Technology.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
Sorting Quick, Merge & Radix Divide-and-conquer Technique subproblem 2 of size n/2 subproblem 1 of size n/2 a solution to subproblem 1 a solution to.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Dynamic Programming. What is Dynamic Programming  A method for solving complex problems by breaking them down into simpler sub problems. It is applicable.
1 Overview Divide and Conquer Merge Sort Quick Sort.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
D ESIGN & A NALYSIS OF A LGORITHM 13 – D YNAMIC P ROGRAMMING Informatics Department Parahyangan Catholic University.
CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ? Dr. Juman Byun The George Washington University Please drop this course if you.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Rod cutting Decide where to cut steel rods:
Design & Analysis of Algorithm Dynamic Programming
David Meredith Dynamic programming David Meredith
0/1 Knapsack Making Change (any coin set)
Algorithms CSCI 235, Spring 2019 Lecture 28 Dynamic Programming III
Introduction to Algorithms: Dynamic Programming
CSC 413/513- Intro to Algorithms
Dynamic Programming CISC4080, Computer Algorithms CIS, Fordham Univ.
Algorithms CSCI 235, Spring 2019 Lecture 27 Dynamic Programming II
Dynamic Programming.
Analysis of Algorithms CS 477/677
Presentation transcript:

CSCI 6212 Design and Analysis of Algorithms Dynamic Programming Dr. Juman Byun The George Washington University Please drop this course if you have not taken the following prerequisite. Sometimes enthusiasm alone is not enough. CSci 1311: Discrete Structures I (3) CSci 1112: Algorithms and Data Structures (3)

Example: Rod Cutting n=4

Example: Rod Cutting length iprice p i 1$1 2$5 3$8 4 $9 $10 5$10 6$17 7 8$20 9$24 10$30 Maximum Revenue, r 4 ? n=4

r n when n=4 ? ip[i] 1$1 2$5 3$8 4 $9 $10 5$10 6$17 7 8$20 9$24 10$30 $9$1$8$5 $8$1 $5$1$5$1$5$1 $10

Notation $5 $10 rod into 2 pieces4-inch Decomposition: 4 = r 4 = $5 + $5 Maximum Revenue:

Notation rnrn rnrn rod into k piecesn-inch Decomposition: n = i 1 + i 2 + … + i k Maximum Revenue:

General Procedure to Find Optimal Rod Cutting Uncut Rod of length npnpn r 1 + r n-1 r 2 + r n-2 r n-2 + r 2 r n-1 + r 1 CutRevenue Pick the largest

General Procedure to Find Optimal Rod Cutting

Recursive Top-Down Cut-Rod(p,n) 1.if n == 0 2.return 0 3.q = -∞ 4.for i = 1 to n 5.q = max(q,p[i] + Cut-Rod(p, n - i ) ) 6.return q

vs Divide-and-conquer Similarity to divide problems into subproblems Difference subproblems overlap

Can we do better ?

Momoized-Cut-Rod Memoized-Cut-Rod(p,n) 1.let r[0..n] be a new array 2.for i = 0 to n 3.r[i] = -∞ 4.return Memoized-Cut-Rod-Aux(p,n,r)

Momoized-Cut-Rod-Aux Momoized-Cut-Rod-Aux(p,n,r) 1.if r[n] >= 0 2.return r[n] 3.if n == 0 4.q = 0 5.else q = -∞ 6.for i = 1 to n 7.q = max(q,p[i]+Memoized-Cut-Rod-Aux(p,n-i,r)) 8.r[n] = q 9.return q

Bottom-Up-Cut-Rod Bottom-Up-Cut-Rod(p,n) 1.let r[0..n] be a new array 2.r[0] = 0 3.for j = 1 to n 4.q = -∞ 5.for i = 1 to j 6.q = max(q, p[i] + r[j-i]) 7.r[j] = q 8.return r[n]

Running Time

Extended-Bottom-Up-Cut- Rod Extended-Bottom-Up-Cut-Rod(p,n) 1.let r[0..n] and s[0..n] be new arrays 2.r[0] = 0 3.for j = 1 to n 4.q = -∞ 5.for i = 1 to j 6.if q < p[i] + r[j-i] 7.q = p[i] + r[j-i] 8.s[j] = i 9.r[j] = q 10.return r and s