Chapter 15: Dynamic Programming

Slides:



Advertisements
Similar presentations
Algorithm Design Methodologies Divide & Conquer Dynamic Programming Backtracking.
Advertisements

Chapter 15 Dynamic Programming Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
1 Dynamic Programming (DP) Like divide-and-conquer, solve problem by combining the solutions to sub-problems. Differences between divide-and-conquer and.
Dynamic Programming Lets begin by looking at the Fibonacci sequence.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Design Patterns for Optimization Problems Dynamic Programming.
Dynamic Programming Code
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
UNC Chapel Hill Lin/Manocha/Foskey Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject.
November 7, 2005Copyright © by Erik D. Demaine and Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example:
chapter chapter chapter253.
Analysis of Algorithms
11-1 Matrix-chain Multiplication Suppose we have a sequence or chain A 1, A 2, …, A n of n matrices to be multiplied –That is, we want to compute the product.
Longest Common Subsequence
1 Dynamic programming algorithms for all-pairs shortest path and longest common subsequences We will study a new technique—dynamic programming algorithms.
Dynamic Programming UNC Chapel Hill Z. Guo.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
CS 5243: Algorithms Dynamic Programming Dynamic Programming is applicable when sub-problems are dependent! In the case of Divide and Conquer they are.
CS 8833 Algorithms Algorithms Dynamic Programming.
Dynamic Programming (Ch. 15) Not a specific algorithm, but a technique (like divide- and-conquer). Developed back in the day when “programming” meant “tabular.
Optimization Problems In which a set of choices must be made in order to arrive at an optimal (min/max) solution, subject to some constraints. (There may.
15.Dynamic Programming. Computer Theory Lab. Chapter 15P.2 Dynamic programming Dynamic programming is typically applied to optimization problems. In such.
Chapter 15 Dynamic Programming Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
David Luebke 1 2/26/2016 CS 332: Algorithms Dynamic Programming.
1 Chapter 15-2: Dynamic Programming II. 2 Matrix Multiplication Let A be a matrix of dimension p x q and B be a matrix of dimension q x r Then, if we.
Dynamic Programming Csc 487/687 Computing for Bioinformatics.
Dynamic Programming Typically applied to optimization problems
Dynamic Programming (DP)
Advanced Algorithms Analysis and Design
David Meredith Dynamic programming David Meredith
Dynamic Programming (DP)
CS 3343: Analysis of Algorithms
Advanced Algorithms Analysis and Design
Matrix Chain Multiplication
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Least common subsequence:
Dynamic programming techniques
Dynamic programming techniques
Dynamic Programming CISC4080, Computer Algorithms CIS, Fordham Univ.
CS200: Algorithm Analysis
Dynamic Programming Several problems Principle of dynamic programming
Chapter 8 Dynamic Programming.
Dynamic Programming Comp 122, Fall 2004.
CSCE 411 Design and Analysis of Algorithms
Matrix Multiplication Chains
Matrix Chain Multiplication
Dynamic Programming.
CS6045: Advanced Algorithms
Data Structure and Algorithms
Chapter 15: Dynamic Programming II
Dynamic Programming Comp 122, Fall 2004.
Lecture 8. Paradigm #6 Dynamic Programming
Ch. 15: Dynamic Programming Ming-Te Chi
Matrix Multiplication (Dynamic Programming)
Algorithms CSCI 235, Spring 2019 Lecture 28 Dynamic Programming III
Dynamic Programming-- Longest Common Subsequence
Introduction to Algorithms: Dynamic Programming
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Dynamic Programming CISC4080, Computer Algorithms CIS, Fordham Univ.
Midterm: week 7 in the lecture for 2 hours
//****************************************
Algorithms and Data Structures Lecture X
Binhai Zhu Computer Science Department, Montana State University
Longest common subsequence (LCS)
Analysis of Algorithms CS 477/677
Matrix Chain Multiplication
Negative-Weight edges:
Algorithms CSCI 235, Spring 2019 Lecture 27 Dynamic Programming II
Chapter 15: Dynamic Programming
Longest Common Subsequence
Presentation transcript:

Chapter 15: Dynamic Programming

Matrix-chain multiplication Compute the product of n matrices A1,A2,..,An Where to put the parentheses (A1( A2 (A3 A4))) (A1(( A2 A3) A4)) ((A1 A2) (A3 A4)) ((A1 (A2 A3)) A4) (((A1 A2) A3) A4) How many parenthesizations? 1 if n=1 P(n) = or P(1) P(n-1) + P(2) P(n-2) + … + P(n-1)P(1) Known as Catalan numbers. Grow as OMEGA(4^n / n^{3/2} ) Observation Suppose that an optimal parenthesization splits between A_k and A_{k+1}. Then parenthesization of A_1 through A_k must be optimal and so is for A_{k+1} through A_n The fact that this type of observation is correct is crucial for the ability to use dynamic programming

Recursive presentation of solution 0 if i=j Min[i,j] = or min {m[i,k] + m[k+1,j] + p_{i-1}p_kp_j} if i< j { i <= k < j} Understanding the complexity: How many pairs i < j for a given difference k (=j-i) Zoom on n/4 < k < 3n/4 For a given k, O(n) pairs each requiring min of O(n) values Since the number of values of k is O(n) the complexity is O(n^3)

Matrix-chain multiplication # of operations Where to split A1 30X35 A2 35X15 A3 15X5 A4 5X10 A5 10X20 A6 20X25 6 matrices :in which order to multiply m[2,5] is the minimum of 3 candidates: m[2,2] + m[3,5] +p1p2p5 = 0+2500+35X15X20=13000 m[2,3] + m[4,5] + p1p3p5 = 2625+1000+35X5X20=7125 m[2,4] + m[5,5] + p1p4p5 =4375+0+35X10X20=11375 =7125

Longest common subsequence (LCS) Z = {B,C,D,B} is a subsequence of X = {A,B,C,B,D,A,B} Given two sequences X and Y, and a subsequence Z, Z is a common subsequence of X and Y if it is a subsequence of X and a subsequence of Y Given two sequences X and Y, the LCS problem is to find the maximum-length common subsequence of X and Y

Theorem 15.1: Optimal substructure of an LCS Let X = <x_1,x_2,..,x_m> and Y=<y_1,y_2,..,y_n> and Z=<z_1,z_2,..,z_k> be sequences, where Z is any LCS of X and Y. Then: If x_m=y_n then z_k= x_m=y_n and Z_{k-1} is an LCS of X_{m-1} and Y_{n-1} If x_m != y_n then 2. z_k != X_m implies that Z is an LCS of X_{m-1} and Y 3. z_k != Y_n implies that Z is an LCS of X and Y_{n-1} This structure that the following Recursive solution: The LCS-length of <x_1,..x_i> and <y_1,..,y_j> is: 0 if i=0 or j=0 c[i,j] = c[i-1,j-1] + 1 if i,j >0 and x_i = y_j max(c[i-1,j],c[i,j-1]) if i,j >0 and x_i != y_j

LCS-length table Complexity O(nm) X = <A,B,C,B,D,A,B>, Y = <B,D,C,A,B,A> Complexity O(nm)