Dynamic Programming (16.0/15) The 3-d Paradigm 1st = Divide and Conquer 2nd = Greedy Algorithm Dynamic Programming = metatechnique (not a particular algorithm)

Slides:



Advertisements
Similar presentations
Lecture 8: Dynamic Programming Shang-Hua Teng. Longest Common Subsequence Biologists need to measure how similar strands of DNA are to determine how closely.
Advertisements

CPSC 335 Dynamic Programming Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Overview What is Dynamic Programming? A Sequence of 4 Steps
Algorithms Dynamic programming Longest Common Subsequence.
COMP8620 Lecture 8 Dynamic Programming.
David Luebke 1 5/4/2015 CS 332: Algorithms Dynamic Programming Greedy Algorithms.
CSC 252 Algorithms Haniya Aslam
Comp 122, Fall 2004 Dynamic Programming. dynprog - 2 Lin / Devi Comp 122, Spring 2004 Longest Common Subsequence  Problem: Given 2 sequences, X =  x.
1 Longest Common Subsequence (LCS) Problem: Given sequences x[1..m] and y[1..n], find a longest common subsequence of both. Example: x=ABCBDAB and y=BDCABA,
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 1 (Part 3) Design Patterns for Optimization Problems.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Lecture 2 Tuesday, 2/5/02 Dynamic Programming.
Dynamic Programming Reading Material: Chapter 7..
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Design Patterns for Optimization Problems Dynamic Programming.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Lecture 1 (Part 3) Tuesday, 9/3/02 Design Patterns for Optimization.
November 7, 2005Copyright © by Erik D. Demaine and Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example:
Dynamic Programming Reading Material: Chapter 7 Sections and 6.
Lecture 8: Dynamic Programming Shang-Hua Teng. First Example: n choose k Many combinatorial problems require the calculation of the binomial coefficient.
Notes This set of slides (Handout #7) is missing the material on Reductions and Greed that was presented in class. Those slides are still under construction,
Analysis of Algorithms
1 Dynamic Programming Jose Rolim University of Geneva.
Lecture 7 Topics Dynamic Programming
Longest Common Subsequence
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2005 Design Patterns for Optimization Problems Dynamic Programming.
Lecture 5 Dynamic Programming. Dynamic Programming Self-reducibility.
Dynamic Programming Dynamic programming is a technique for solving problems with a recursive structure with the following characteristics: 1.optimal substructure.
Dynamic Programming UNC Chapel Hill Z. Guo.
ADA: 7. Dynamic Prog.1 Objective o introduce DP, its two hallmarks, and two major programming techniques o look at two examples: the fibonacci.
Dynamic Programming.
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
CS 8833 Algorithms Algorithms Dynamic Programming.
Lecture21: Dynamic Programming Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
6/4/ ITCS 6114 Dynamic programming Longest Common Subsequence.
Introduction to Algorithms Jiafen Liu Sept
CS 3343: Analysis of Algorithms Lecture 18: More Examples on Dynamic Programming.
Chapter 7 Dynamic Programming 7.1 Introduction 7.2 The Longest Common Subsequence Problem 7.3 Matrix Chain Multiplication 7.4 The dynamic Programming Paradigm.
David Luebke 1 2/26/2016 CS 332: Algorithms Dynamic Programming.
CSC 213 Lecture 19: Dynamic Programming and LCS. Subsequences (§ ) A subsequence of a string x 0 x 1 x 2 …x n-1 is a string of the form x i 1 x.
TU/e Algorithms (2IL15) – Lecture 4 1 DYNAMIC PROGRAMMING II
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
Dynamic Programming Typically applied to optimization problems
Advanced Algorithms Analysis and Design
Lecture 5 Dynamic Programming
David Meredith Dynamic programming David Meredith
Advanced Algorithms Analysis and Design
Least common subsequence:
Lecture 5 Dynamic Programming
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
Dynamic Programming.
CS Algorithms Dynamic programming 0-1 Knapsack problem 12/5/2018.
Dynamic Programming Dr. Yingwu Zhu Chapter 15.
CS 3343: Analysis of Algorithms
Longest Common Subsequence
Dynamic Programming Comp 122, Fall 2004.
Lecture 8. Paradigm #6 Dynamic Programming
CS 332: Algorithms Amortized Analysis Continued
Trevor Brown DC 2338, Office hour M3-4pm
Introduction to Algorithms: Dynamic Programming
Longest Common Subsequence
Algorithms and Data Structures Lecture X
Binhai Zhu Computer Science Department, Montana State University
Longest common subsequence (LCS)
Analysis of Algorithms CS 477/677
Longest Common Subsequence
Dynamic Programming.
Presentation transcript:

Dynamic Programming (16.0/15) The 3-d Paradigm 1st = Divide and Conquer 2nd = Greedy Algorithm Dynamic Programming = metatechnique (not a particular algorithm) Programming = ``tableau method’’, not writing a code

Longest Common Subsequence (16.3/15.4) Problem: Given x[1..m] and y[1..n], find LCS x: A B C B D A B  B C B A y: B D C A B A Brute-force algorithm: –for every subsequence of x check if it is in y –O(n2 m ) time 2 m subsequences of x (each element either in or out O(n) for scanning y with x-subsequence (m  n)

Recurrent Formula for LCS (16.3/15.4) Let c[i,j] = length of LCS of X[i]=x[1..i],Y[j]= y[1..j] Then c[m,n] = length of LCS of x and y Theorem: if x[i] = y[j] otherwise Proof. x[i] = y[j]  LCS([X[i],Y[j]) = LCS(X[i-1],Y[j-1]) + x[i]

DP properties(16.2/15.3) 1st Observation: any part of the optimal answer is also optimal –The subsequence of LCS(X,Y) is LCS for some subsequences of X and Y. 2nd Observation: subproblems overlap –LCS(X[m],Y[n-1]) and LCS(X[m-1],Y[n]) has common subproblem LCS(X[m-1],Y[n-1]) –There are few problems in total = mn for LCS –Unlike divide and conquer

DP (16.2/15.3) After computing solution of a subproblem, store in table Time = O(mn) When computing c[i,j] we need O(1) time if we have: –x[i], y[j] –c[i,j-1] –c[i-1,j] –c[i-1,j-1]

DP Table for LCS y B D C A B A xABCBDABxABCBDAB

DP Table for LCS y B D C A B A xABCBDABxABCBDAB

Optimal Polygon Triangulation (16.4/?) Polygon has sides and vertices Polygon is simple = not self-intersecting. Polygon P is convex if any segment with ends in P belong to P Triangulation of P is partition of P with chords into triangles. Problem: Given a convex polygon and weight function defined on triangles (e.g. the perimeter). Find triangulation of minimum weight (of minimum total length). # of triangles = n - 2 triangles with n-3 chords

Optimal Polygon Triangulation (16.4/?) Optimal sub-triangulation of optimal triangulation Recurrent formula: t[i,j] = the weight of the optimal triangulation of the polygon ; If i=j, then t[i,j]=0; else Runtime O(n 3 ) and space is O(n 2 ) v[i-1] v[i] v[j] v[i-1] v[i] v[j] v[k]