Dynamic Programming. Outline and Reading. Computing Fibonacci
|
|
- Jeffrey O’Brien’
- 5 years ago
- Views:
Transcription
1 Dynamic Programming Dynamic Programming version Outline and Reading Matrix Chain-Product ( 5.3.1) The General Technique ( 5.3.2) -1 Knapsac Problem ( 5.3.3) Dynamic Programming version Computing Fibonacci Dynamic Programming is a general algorithm design paradigm: Iteratively solves small subproblems which are combined to solve overall problem. Fibonacci numbers defined F = F 1 = 1 F n = F n-1 + F n-2, for n > 1 Recursive solution: int fib(int x) if (x=) return ; else if (x=1) return 1; else return fib(x-1) + fib(x-2); Dynamic Programming Solution: f[]=; f[1]=1; for i 2 to x do f[i] f[i-1] + f[i-2]; return f[x]; Dynamic Programming version 1.2 3
2 Dynamic Programming revealed Brea problem into subproblems (Hardest part!) subproblems are shared optimal subproblem solution needs to help solve overall problem. (subproblem optimality) Compute solutions to small subproblems Store solutions in array A. Combine already computed solutions into solutions for larger subproblems Solutions Array A is iteratively filled (Optional: reduce space needed by reusing array) Dynamic Programming version Reducing Space for Computing Fibonacci store only previous 2 values to compute next value int fib(x) if (x=) return ; else if (x=1) return 1; else int last 1; nextlast ; for i 2 to x do temp last + nextlast; nextlast last; last temp; return temp; Dynamic Programming version Matrix Chain-Products Review: Matrix Multiplication. C = A*B A is d e and B is e f e 1 = C[ i, A[ i, ]* = O(def ) time (def multiplications) e e B f j d A i C i,j d Dynamic Programming version f
3 Matrix Chain-Products Matrix Chain-Product: Compute A=A *A 1 * *A n-1 A i is d i d i+1 Problem: How to parenthesize? [for minimizing ops] Example B is 3 1 C is 1 5 D is 5 5 (B*C)*D taes = 1575 ops B*(C*D) taes = 4 ops Dynamic Programming version An Enumeration Approach Matrix Chain-Product Alg.: Try all possible ways to parenthesize A=A *A 1 * *A n-1 Calculate number of ops for each one Pic the one that is best Running time: The number of paranethesizations is equal to the number of binary trees with n nodes This is exponential! It is called the Catalan number, and it is almost 4 n. This is a terrible algorithm! Dynamic Programming version A Greedy Approach Idea #1: repeatedly select the product that uses (up) the most operations. Counter-example: A is 1 5 B is 5 1 C is 1 5 D is 5 1 Greedy idea #1 gives (A*B)*(C*D), which taes = 2 ops A*((B*C)*D) taes = 1 ops Dynamic Programming version 1.2 9
4 Another Greedy Approach Idea #2: repeatedly select the product that uses the fewest operations. Counter-example: A is B is 11 9 C is 9 1 D is 1 99 Greedy idea #2 gives A*((B*C)*D)), which taes = ops (A*B)*(C*D) taes =1899 ops The greedy approach is not giving us the optimal value. Dynamic Programming version A Recursive Approach Define subproblems: Find the best parenthesization of A i *A i+1 * *A j. Let N i,j denote the number of operations done by this subproblem. The optimal solution for the whole problem is N,n-1. Subproblem optimality: The optimal solution can be defined in terms of optimal subproblems There has to be a final multiplication (root of the expression tree) for the optimal solution. Say, the final multiply is at index i: (A * *A i )*(A i+1 * *A n-1 ). Then the optimal solution N,n-1 is the sum of two optimal subproblems, N,i and N i+1,n-1 plus the time for the last multiply. If subproblems were not optimal, neither is global solution. Dynamic Programming version A Characterizing Equation Define global optimal in terms of optimal subproblems, by checing all possible locations for final multiply. Recall that A i is a d i d i+1 dimensional matrix. So, a characterizing equation for N i,j is the following: N i, j = j+ i < j min{ Ni, + N + 1, j + did+ 1d 1} Note that subproblems are not independent--the subproblems overlap (are shared) Dynamic Programming version
5 A Dynamic Programming Construct optimal subproblems bottom-up. N i,i s are easy, so start with them Then do length 2,3, subproblems, and so on. Array N i,j stores solutions Running time: O(n 3 ) matrixchain(s): Input: sequence S of n matrices to be multiplied Output: number of operations in an optimal paranthesization of S for i 1 to n-1 do N i,i for b 1 to n-1 do for i to n-b-1 do j i+b N i,j +infinity for i to j-1 do N i,j min{n i,j, N i, +N +1,j +d i d +1 d j+1 } Dynamic Programming version A Dynamic Programming Visualization Ni j The bottom-up construction fills in the N array by diagonals N i,j gets values from pervious entries in i-th row and j-th column Filling in each entry in the N table taes O(n) time. Total run time: O(n 3 ) Getting actual parenthesization can be done by remembering for each N entry, = j+ min{ Ni, + N+ 1, j + did+ 1d 1} i < j answer N 1 2 j 1 i n-1 n-1 Dynamic Programming version The General Dynamic Programming Technique Applies to a problem that at first seems to require a lot of time (possibly exponential), provided we have: Simple subproblems: the subproblems can be defined in terms of a few variables, such as j, l, m, and so on. Subproblem optimality: the global optimum value can be defined in terms of optimal subproblems Subproblem overlap: the subproblems are not independent, but instead they overlap (hence, should be constructed bottom-up). Dynamic Programming version
6 The /1 Knapsac Problem Given: A set S of n items, with each item i having b i - a positive benefit w i - a positive weight Goal: Choose items with maximum total benefit but with. If we are not allowed to tae fractional amounts, then this is the /1 napsac problem. In this case, we let T denote the set of items we tae Objective: maximize Constraint: w i W b i i T i T Dynamic Programming version Example Given: A set S of n items, with each item i having b i - a positive benefit w i - a positive weight Goal: Choose items with maximum total benefit but with. napsac Items: Weight: Benefit: in 2 in 2 in 6 in 2 in $2 $3 $6 $25 $8 9 in Solution: 5 (2 in) 3 (2 in) 1 (4 in) Dynamic Programming version A /1 Knapsac, First Attempt S : Set of items numbered 1 to. Define ] = best selection from S. Problem: does not have subproblem optimality: Consider S={(3,2),(5,4),(8,5),(4,3),(1,9)} benefit-weight pairs Best for S 4 : Best for S 5 : Dynamic Programming version
7 A /1 Knapsac, Second Attempt S : Set of items numbered 1 to. Define = best selection from S with weight exactly equal to w Good news: this does have subproblem optimality:, w w } if w else I.e., best subset of S with weight exactly w is either the best subset of S -1 w/ weight w or the best subset of S -1 w/ weight w-w plus item. Dynamic Programming version > w The /1 Knapsac Recall definition of : > w, w w } else 1Knapsac(S, W): Since is defined in Input: set S of items w/ benefit b i terms of -1,*], we can and weight w i ; max. weight W reuse the same array Output: benefit of best subset with Running time: O(nW). for w to W do Not a polynomial-time algorithm if W is large for 1 to n do This is a pseudo-polynomial for w W downto w do time algorithm if w-w ]+b > then w-w ]+b Dynamic Programming version Dynamic Programming revealed Brea problem into subproblems that are shared have subproblem optimality (optimal subproblem solution helps solve overall problem) subproblem optimality means can write recursive realtionship between subproblems! Compute solutions to small subproblems Store solutions in array A. Combine already computed solutions into solutions for larger subproblems Solutions Array A is iteratively filled (Optional: reduce space needed by reusing array) Dynamic Programming version
8 The /1 Knapsac Problem Given: A set S of n items, with each item i having b i - a positive benefit w i - a positive weight Goal: Choose items with maximum total benefit but with. If we are not allowed to tae fractional amounts, then this is the /1 napsac problem. In this case, we let T denote the set of items we tae Objective: maximize Constraint: w i W b i i T i T Dynamic Programming version Towards the /1 Knapsac S : Set of items numbered 1 to = {(b 1,w 1 ), (b 2,w 2 ),, (b,w )} Define = maximum benefit of optimal subset from S with total weight at most j Recursive definition of :, j w } if = otherwise Dynamic Programming version Towards the /1 Knapsac if =, j w } otherwise rec1knap(s, W): = maximum benefit Input: set S of items w/ benefit b 1, b 2, b of optimal subset from S,; weights w 1, w 2, w j and max. weight W with total weight at most j Output: benefit of best subset with Recursive version of if = then {S = emptyset} algorithm based on return recursive subproblem remove item (benefit-weight (b,w )) relationship. from S Not a dynamic if w > W then {item does not fit} return rec1knap(s,w) programming version. return max(rec1knap(s,w), rec1knap(s,w-w ) + b ) Dynamic Programming version
9 Towards the /1 Knapsac Modified recursive version that stores subproblem solutions First allocate global array B of size n+1 by W Then initialize all entries of i, to 1 B stores results of recursive calls Entries in B are computed when necessary This is considered a dynamic programming version., j w ] + b } if = otherwise rec1knap(s, W): Input: set S of items w/ benefit b 1, b 2,,b,; weights w 1, w 2, w j and max. weight W Output: benefit of best subset with if = then return remove item (benefit-weight (b,w )) from S if -1, W]= 1 then -1,W]=rec1Knap(S,W) if w > W then return -1, W] if -1, W- w ]= 1 then -1,W - w ]=rec1knap(s,w -w ) return max(-1, W], -1,W - w ]+b ) Dynamic Programming version The /1 Knapsac - Iterative if =, j w } otherwise 1Knapsac(S, W): Input: set S of n items w/ benefit b Recursive computation i and weight w i ; max. weight W not necessary Output: benefit of best subset with Compute iteratively, for w to W do {base case} bottom-up, All -1,*] must be for 1 to n do computed before *] for j 1 to W do because of subproblem if w then dependencies -1, else This is also dynamic max(-1,, programming. -1,j-w Dynamic Programming version 1.2 ]+b ) 26 The /1 Knapsac - Iterative if =, j w } otherwise 1Knapsac(S, W): Input: set S of n items w/ benefit b Not necessary to use all the i and weight w i ; max. weight W space Output: benefit of best subset with Keep trac of one row at a time for w to W do {base case} Overwrite results from, previous row as new values for 1 to n do computed for j W downto 1 do Must compute right to left (W if w then downto 1) so that the next -1, row (*]) uses results from else the previous row (-1,*]). max(-1,, Simplify this to get version in -1, j-w ]+b ) boo. Dynamic Programming version
10 The /1 Knapsac - Iterative if =, j w } otherwise 1Knapsac(S, W): Input: set S of n items w/ benefit b Not necessary to use all the i and weight w i ; max. weight W space Output: benefit of best subset with Keep trac of one row at a time for w to W do {base case} Overwrite results from previous row as new values for 1 to n do computed for j W downto 1 do Must compute right to left (W if w then downto 1) so that the next row (*]) uses results from else the previous row (-1,*]). max(, Simplify this to get version in j-w ]+b ) boo. Dynamic Programming version The /1 Knapsac > w, w w } else 1Knapsac(S, W): The boo version: Input: set S of n items w/ benefit b i When value does not change and weight w i ; max. weight W from one row to the next, Output: benefit of best subset with then no need to assign same value. for w to W do Running time: O(nW). Not a polynomial-time for 1 to n do algorithm if W is large for w W downto w do This is a pseudo-polynomial if w-w ]+b > then time algorithm w-w ]+b Dynamic Programming version
Dynamic Programming. An Enumeration Approach. Matrix Chain-Products. Matrix Chain-Products (not in book)
Matrix Chain-Products (not in book) is a general algorithm design paradigm. Rather than give the general structure, let us first give a motivating example: Matrix Chain-Products Review: Matrix Multiplication.
More informationPresentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Dynamic Programming
Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 25 Dynamic Programming Terrible Fibonacci Computation Fibonacci sequence: f = f(n) 2
More informationCSED233: Data Structures (2017F) Lecture12: Strings and Dynamic Programming
(2017F) Lecture12: Strings and Dynamic Programming Daijin Kim CSE, POSTECH dkim@postech.ac.kr Strings A string is a sequence of characters Examples of strings: Python program HTML document DNA sequence
More informationString Patterns and Algorithms on Strings
String Patterns and Algorithms on Strings Lecture delivered by: Venkatanatha Sarma Y Assistant Professor MSRSAS-Bangalore 11 Objectives To introduce the pattern matching problem and the important of algorithms
More informationUnit-5 Dynamic Programming 2016
5 Dynamic programming Overview, Applications - shortest path in graph, matrix multiplication, travelling salesman problem, Fibonacci Series. 20% 12 Origin: Richard Bellman, 1957 Programming referred to
More informationDynamic Programming. Nothing to do with dynamic and nothing to do with programming.
Dynamic Programming Deliverables Dynamic Programming basics Binomial Coefficients Weighted Interval Scheduling Matrix Multiplication /1 Knapsack Longest Common Subsequence 6/12/212 6:56 PM copyright @
More informationOutline. CS38 Introduction to Algorithms. Fast Fourier Transform (FFT) Fast Fourier Transform (FFT) Fast Fourier Transform (FFT)
Outline CS8 Introduction to Algorithms Lecture 9 April 9, 0 Divide and Conquer design paradigm matrix multiplication Dynamic programming design paradigm Fibonacci numbers weighted interval scheduling knapsack
More informationWe augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real
14.3 Interval trees We augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real numbers ], with Interval ]represents the set Open and half-open intervals
More informationPartha Sarathi Manal
MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 29 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.
More informationDynamic Programming II
June 9, 214 DP: Longest common subsequence biologists often need to find out how similar are 2 DNA sequences DNA sequences are strings of bases: A, C, T and G how to define similarity? DP: Longest common
More informationDynamic Programming. Design and Analysis of Algorithms. Entwurf und Analyse von Algorithmen. Irene Parada. Design and Analysis of Algorithms
Entwurf und Analyse von Algorithmen Dynamic Programming Overview Introduction Example 1 When and how to apply this method Example 2 Final remarks Introduction: when recursion is inefficient Example: Calculation
More informationIntroduction to Algorithms
Introduction to Algorithms Dynamic Programming Well known algorithm design techniques: Brute-Force (iterative) ti algorithms Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic
More informationFramework for Design of Dynamic Programming Algorithms
CSE 441T/541T Advanced Algorithms September 22, 2010 Framework for Design of Dynamic Programming Algorithms Dynamic programming algorithms for combinatorial optimization generalize the strategy we studied
More informationLecture 57 Dynamic Programming. (Refer Slide Time: 00:31)
Programming, Data Structures and Algorithms Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institution Technology, Madras Lecture 57 Dynamic Programming (Refer Slide Time:
More informationDynamic Programming. An Introduction to DP
Dynamic Programming An Introduction to DP Dynamic Programming? A programming technique Solve a problem by breaking into smaller subproblems Similar to recursion with memoisation Usefulness: Efficiency
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra
More informationCSC 373 Lecture # 3 Instructor: Milad Eftekhar
Huffman encoding: Assume a context is available (a document, a signal, etc.). These contexts are formed by some symbols (words in a document, discrete samples from a signal, etc). Each symbols s i is occurred
More informationCS473-Algorithms I. Lecture 10. Dynamic Programming. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 1 Dynamic Programming 1 Introduction An algorithm design paradigm like divide-and-conquer Programming : A tabular method (not writing computer code) Divide-and-Conquer (DAC):
More informationWe ve done. Now. Next
We ve done Matroid Theory Task scheduling problem (another matroid example) Dijkstra s algorithm (another greedy example) Dynamic Programming Now Matrix Chain Multiplication Longest Common Subsequence
More informationAlgorithm Design Techniques part I
Algorithm Design Techniques part I Divide-and-Conquer. Dynamic Programming DSA - lecture 8 - T.U.Cluj-Napoca - M. Joldos 1 Some Algorithm Design Techniques Top-Down Algorithms: Divide-and-Conquer Bottom-Up
More information10/24/ Rotations. 2. // s left subtree s right subtree 3. if // link s parent to elseif == else 11. // put x on s left
13.2 Rotations MAT-72006 AA+DS, Fall 2013 24-Oct-13 368 LEFT-ROTATE(, ) 1. // set 2. // s left subtree s right subtree 3. if 4. 5. // link s parent to 6. if == 7. 8. elseif == 9. 10. else 11. // put x
More informationDynamic Programming Assembly-Line Scheduling. Greedy Algorithms
Chapter 13 Greedy Algorithms Activity Selection Problem 0-1 Knapsack Problem Huffman Code Construction Dynamic Programming Assembly-Line Scheduling C-C Tsai P.1 Greedy Algorithms A greedy algorithm always
More informationCSE 417 Dynamic Programming (pt 4) Sub-problems on Trees
CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees Reminders > HW4 is due today > HW5 will be posted shortly Dynamic Programming Review > Apply the steps... 1. Describe solution in terms of solution
More informationCS 231: Algorithmic Problem Solving
CS 231: Algorithmic Problem Solving Naomi Nishimura Module 5 Date of this version: June 14, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides
More informationLecture 4: Dynamic programming I
Lecture : Dynamic programming I Dynamic programming is a powerful, tabular method that solves problems by combining solutions to subproblems. It was introduced by Bellman in the 950 s (when programming
More informationData Structures and Algorithms Week 8
Data Structures and Algorithms Week 8 Dynamic programming Fibonacci numbers Optimization problems Matrix multiplication optimization Principles of dynamic programming Longest Common Subsequence Algorithm
More informationLecture 13: Chain Matrix Multiplication
Lecture 3: Chain Matrix Multiplication CLRS Section 5.2 Revised April 7, 2003 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm
More informationComputer Sciences Department 1
1 Advanced Design and Analysis Techniques (15.1, 15.2, 15.3, 15.4 and 15.5) 3 Objectives Problem Formulation Examples The Basic Problem Principle of optimality Important techniques: dynamic programming
More informationChain Matrix Multiplication
Chain Matrix Multiplication Version of November 5, 2014 Version of November 5, 2014 Chain Matrix Multiplication 1 / 27 Outline Outline Review of matrix multiplication. The chain matrix multiplication problem.
More informationLecture 8. Dynamic Programming
Lecture 8. Dynamic Programming T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018
More information1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors
1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors on an EREW PRAM: See solution for the next problem. Omit the step where each processor sequentially computes the AND of
More information12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares
12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares Optimal substructure Dynamic programming is typically applied to optimization problems. An optimal solution to the original
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 15, 2015 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 7 April 15, 2015 洪國寶 1 Course information (5/5) Grading (Tentative) Homework 25% (You may collaborate when solving the homework, however when writing
More informationF(0)=0 F(1)=1 F(n)=F(n-1)+F(n-2)
Algorithms Dana Shapira Lesson #4: Dynamic programming Fibonacci Series F()= F()= F(n)=F(n-)+F(n-) Write a Divide and Conquer Algorithm! What is its running time? Binomial Coefficients n! n = ( )! n! Recursive
More information6. Algorithm Design Techniques
6. Algorithm Design Techniques 6. Algorithm Design Techniques 6.1 Greedy algorithms 6.2 Divide and conquer 6.3 Dynamic Programming 6.4 Randomized Algorithms 6.5 Backtracking Algorithms Malek Mouhoub, CS340
More information/463 Algorithms - Fall 2013 Solution to Assignment 3
600.363/463 Algorithms - Fall 2013 Solution to Assignment 3 (120 points) I (30 points) (Hint: This problem is similar to parenthesization in matrix-chain multiplication, except the special treatment on
More informationModule 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm
Module 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm This module 27 focuses on introducing dynamic programming design strategy and applying it to problems like chained matrix
More informationA BRIEF INTRODUCTION TO DYNAMIC PROGRAMMING (DP) by Amarnath Kasibhatla Nanocad Lab University of California, Los Angeles 04/21/2010
A BRIEF INTRODUCTION TO DYNAMIC PROGRAMMING (DP) by Amarnath Kasibhatla Nanocad Lab University of California, Los Angeles 04/21/2010 Overview What is DP? Characteristics of DP Formulation Examples Disadvantages
More information15.Dynamic Programming
15.Dynamic Programming Dynamic Programming is an algorithm design technique for optimization problems: often minimizing or maximizing. Like divide and conquer, DP solves problems by combining solutions
More informationLecture 22: Dynamic Programming
Lecture 22: Dynamic Programming COSC242: Algorithms and Data Structures Brendan McCane Department of Computer Science, University of Otago Dynamic programming The iterative and memoised algorithms for
More information1 Non greedy algorithms (which we should have covered
1 Non greedy algorithms (which we should have covered earlier) 1.1 Floyd Warshall algorithm This algorithm solves the all-pairs shortest paths problem, which is a problem where we want to find the shortest
More informationDynamic Programming (Part #2)
Dynamic Programming (Part #) Introduction to Algorithms MIT Press (Chapter 5) Matrix-Chain Multiplication Problem: given a sequence A, A,, A n, compute the product: A A A n Matrix compatibility: C = A
More informationSo far... Finished looking at lower bounds and linear sorts.
So far... Finished looking at lower bounds and linear sorts. Next: Memoization -- Optimization problems - Dynamic programming A scheduling problem Matrix multiplication optimization Longest Common Subsequence
More informationSankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment
Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment
More informationCMPS 102 Solutions to Homework 7
CMPS 102 Solutions to Homework 7 Kuzmin, Cormen, Brown, lbrown@soe.ucsc.edu November 17, 2005 Problem 1. 15.4-1 p.355 LCS Determine an LCS of x = (1, 0, 0, 1, 0, 1, 0, 1) and y = (0, 1, 0, 1, 1, 0, 1,
More informationPractice Problems for the Final
ECE-250 Algorithms and Data Structures (Winter 2012) Practice Problems for the Final Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each
More informationECE608 - Chapter 15 answers
¼ À ÈÌ Ê ½ ÈÊÇ Ä ÅË ½µ ½ º¾¹¾ ¾µ ½ º¾¹ µ ½ º¾¹ µ ½ º ¹½ µ ½ º ¹¾ µ ½ º ¹ µ ½ º ¹¾ µ ½ º ¹ µ ½ º ¹ ½¼µ ½ º ¹ ½½µ ½ ¹ ½ ECE608 - Chapter 15 answers (1) CLR 15.2-2 MATRIX CHAIN MULTIPLY(A, s, i, j) 1. if
More informationTutorial 6-7. Dynamic Programming and Greedy
Tutorial 6-7 Dynamic Programming and Greedy Dynamic Programming Why DP? Natural Recursion may be expensive. For example, the Fibonacci: F(n)=F(n-1)+F(n-2) Recursive implementation memoryless : time= 1
More informationAlgorithms: Dynamic Programming
Algorithms: Dynamic Programming Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Dynamic Programming Spring 2012 1 / 58 Dynamic Programming General Strategy: Solve recursively the problem top-down based
More informationThe Knapsack Problem an Introduction to Dynamic Programming. Slides based on Kevin Wayne / Pearson-Addison Wesley
The Knapsack Problem an Introduction to Dynamic Programming Slides based on Kevin Wayne / Pearson-Addison Wesley Different Problem Solving Approaches Greedy Algorithms Build up solutions in small steps
More informationCSC 373: Algorithm Design and Analysis Lecture 8
CSC 373: Algorithm Design and Analysis Lecture 8 Allan Borodin January 23, 2013 1 / 19 Lecture 8: Announcements and Outline Announcements No lecture (or tutorial) this Friday. Lecture and tutorials as
More informationCS201 Discussion 7 MARKOV AND RECURSION
CS201 Discussion 7 MARKOV AND RECURSION Before we begin Any questions about the midterm solutions? Making a Markov Map Recall that in Markov, we re trying to make a map of all k-grams to all k-grams that
More informationMemoization/Dynamic Programming. The String reconstruction problem. CS124 Lecture 11 Spring 2018
CS124 Lecture 11 Spring 2018 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember
More informationLecture 6: Combinatorics Steven Skiena. skiena
Lecture 6: Combinatorics Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Learning to Count Combinatorics problems are
More informationOutline Purpose How to analyze algorithms Examples. Algorithm Analysis. Seth Long. January 15, 2010
January 15, 2010 Intuitive Definitions Common Runtimes Final Notes Compare space and time requirements for algorithms Understand how an algorithm scales with larger datasets Intuitive Definitions Outline
More informationLecture 16: Introduction to Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY
Lecture 16: Introduction to Dynamic Programming Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day
More information3 INTEGER LINEAR PROGRAMMING
3 INTEGER LINEAR PROGRAMMING PROBLEM DEFINITION Integer linear programming problem (ILP) of the decision variables x 1,..,x n : (ILP) subject to minimize c x j j n j= 1 a ij x j x j 0 x j integer n j=
More informationDynamic Programming. December 15, CMPE 250 Dynamic Programming December 15, / 60
Dynamic Programming December 15, 2016 CMPE 250 Dynamic Programming December 15, 2016 1 / 60 Why Dynamic Programming Often recursive algorithms solve fairly difficult problems efficiently BUT in other cases
More informationCSE 101- Winter 18 Discussion Section Week 6
CSE 101- Winter 18 Discussion Section Week 6 Administrative Introducing 1:1 Sessions: https://docs.google.com/spreadsheets/d/1kgxt_rzbzlibbdijiczs_ o1wxdwa9hhvxccprn8_bwk/edit?usp=sharing Please see the
More informationEfficient Sequential Algorithms, Comp309. Problems. Part 1: Algorithmic Paradigms
Efficient Sequential Algorithms, Comp309 Part 1: Algorithmic Paradigms University of Liverpool References: T. H. Cormen, C. E. Leiserson, R. L. Rivest Introduction to Algorithms, Second Edition. MIT Press
More information15.4 Longest common subsequence
15.4 Longest common subsequence Biological applications often need to compare the DNA of two (or more) different organisms A strand of DNA consists of a string of molecules called bases, where the possible
More informationCSC-140 Assignment 5
CSC-140 Assignment 5 Please do not Google a solution to these problems, cause that won t teach you anything about programming - the only way to get good at it, and understand it, is to do it! 1 Introduction
More information5.1 The String reconstruction problem
CS125 Lecture 5 Fall 2014 5.1 The String reconstruction problem The greedy approach doesn t always work, as we have seen. It lacks flexibility; if at some point, it makes a wrong choice, it becomes stuck.
More informationDynamic Programming. CSE 421: Intro Algorithms. Some Algorithm Design Techniques, I. Techniques, II. Outline:
Dynamic Programming CSE 42: Intro Algorithms Summer 2007 W. L. Ruzzo Dynamic Programming, I Fibonacci & Stamps Outline: General Principles Easy Examples Fibonacci, Licking Stamps Meatier examples RNA Structure
More informationProgramming & Data Structure Laboratory. Day 2, July 24, 2014
Programming & Data Structure Laboratory Day 2, July 24, 2014 Loops Pre and post test loops for while do-while switch-case Pre-test loop and post-test loop Condition checking True Loop Body False Loop Body
More informationElements of Dynamic Programming. COSC 3101A - Design and Analysis of Algorithms 8. Discovering Optimal Substructure. Optimal Substructure - Examples
Elements of Dynamic Programming COSC 3A - Design and Analysis of Algorithms 8 Elements of DP Memoization Longest Common Subsequence Greedy Algorithms Many of these slides are taken from Monica Nicolescu,
More informationAlgorithms. Ch.15 Dynamic Programming
Algorithms Ch.15 Dynamic Programming Dynamic Programming Not a specific algorithm, but a technique (like divide-and-conquer). Developed back in the day when programming meant tabular method (like linear
More informationDynamic Programming Group Exercises
Name: Name: Name: Dynamic Programming Group Exercises Adapted from material by Cole Frederick Please work the following problems in groups of 2 or 3. Use additional paper as needed, and staple the sheets
More informationLECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS
Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq
More informationCMSC351 - Fall 2014, Homework #4
CMSC351 - Fall 2014, Homework #4 Due: November 14th at the start of class PRINT Name: Grades depend on neatness and clarity. Write your answers with enough detail about your approach and concepts used,
More informationResources matter. Orders of Growth of Processes. R(n)= (n 2 ) Orders of growth of processes. Partial trace for (ifact 4) Partial trace for (fact 4)
Orders of Growth of Processes Today s topics Resources used by a program to solve a problem of size n Time Space Define order of growth Visualizing resources utilization using our model of evaluation Relating
More informationS Postgraduate Course on Signal Processing in Communications, FALL Topic: Iteration Bound. Harri Mäntylä
S-38.220 Postgraduate Course on Signal Processing in Communications, FALL - 99 Topic: Iteration Bound Harri Mäntylä harri.mantyla@hut.fi ate: 11.10.1999 1. INTROUCTION...3 2. ATA-FLOW GRAPH (FG) REPRESENTATIONS...4
More informationCSE 521: Algorithms. Dynamic Programming, I Intro: Fibonacci & Stamps. W. L. Ruzzo
CSE 521: Algorithms Dynamic Programming, I Intro: Fibonacci & Stamps W. L. Ruzzo 1 Dynamic Programming Outline: General Principles Easy Examples Fibonacci, Licking Stamps Meatier examples Weighted interval
More informationCSE 421: Intro Algorithms. Winter 2012 W. L. Ruzzo Dynamic Programming, I Intro: Fibonacci & Stamps
CSE 421: Intro Algorithms Winter 2012 W. L. Ruzzo Dynamic Programming, I Intro: Fibonacci & Stamps 1 Dynamic Programming Outline: General Principles Easy Examples Fibonacci, Licking Stamps Meatier examples
More information1 Dynamic Programming
Recitation 13 Dynamic Programming Parallel and Sequential Data Structures and Algorithms, 15-210 (Fall 2013) November 20, 2013 1 Dynamic Programming Dynamic programming is a technique to avoid needless
More information4.1 Interval Scheduling
41 Interval Scheduling Interval Scheduling Interval scheduling Job j starts at s j and finishes at f j Two jobs compatible if they don't overlap Goal: find maximum subset of mutually compatible jobs a
More informationProblem Set 6. Part A:
Introduction to Algorithms: 6.006 Massachusetts Institute of Technology April 12, 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Problem Set 6 Problem Set 6 This problem set is divided into
More informationmemoization or iteration over subproblems the direct iterative algorithm a basic outline of dynamic programming
Dynamic Programming 1 Introduction to Dynamic Programming weighted interval scheduling the design of a recursive solution memoizing the recursion 2 Principles of Dynamic Programming memoization or iteration
More informationAlgorithms IV. Dynamic Programming. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms IV Dynamic Programming Guoqiang Li School of Software, Shanghai Jiao Tong University Dynamic Programming Shortest Paths in Dags, Revisited Shortest Paths in Dags, Revisited The special distinguishing
More information15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015
15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015 Dynamic Programming is a powerful technique that allows one to solve many different types
More informationCME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh HW#3 Due at the beginning of class Thursday 03/02/17
CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh (rezab@stanford.edu) HW#3 Due at the beginning of class Thursday 03/02/17 1. Consider a model of a nonbipartite undirected graph in which
More informationAlgorithms for Integer Programming
Algorithms for Integer Programming Laura Galli November 9, 2016 Unlike linear programming problems, integer programming problems are very difficult to solve. In fact, no efficient general algorithm is
More informationDynamic Programming Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Dynamic Programming What is Dynamic Programming? Technique for avoiding redundant work in recursive algorithms Works best with optimization problems that have a nice underlying structure Can often be used
More information1 Dynamic Programming
Recitation 13 Dynamic Programming Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2013) April 17, 2013 1 Dynamic Programming Dynamic programming is a technique to avoid needless
More informationESO207A: Data Structures and Algorithms End-semester exam
ESO207A: Data Structures and Algorithms End-semester exam Max marks: 120 Time: 180 mins. 17-July-2017 1. Answer all 7 questions. Questions 1 to 3 are from module 3 and questions 4 to 7 are from module
More informationComputer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming
Computer Science 385 Design and Analysis of Algorithms Siena College Spring 29 Topic Notes: Dynamic Programming We next consider dynamic programming, a technique for designing algorithms to solve problems
More informationAlgorithms Dr. Haim Levkowitz
91.503 Algorithms Dr. Haim Levkowitz Fall 2007 Lecture 4 Tuesday, 25 Sep 2007 Design Patterns for Optimization Problems Greedy Algorithms 1 Greedy Algorithms 2 What is Greedy Algorithm? Similar to dynamic
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More information14 Dynamic. Matrix-chain multiplication. P.D. Dr. Alexander Souza. Winter term 11/12
Algorithms Theory 14 Dynamic Programming (2) Matrix-chain multiplication P.D. Dr. Alexander Souza Optimal substructure Dynamic programming is typically applied to optimization problems. An optimal solution
More informationSubset sum problem and dynamic programming
Lecture Notes: Dynamic programming We will discuss the subset sum problem (introduced last time), and introduce the main idea of dynamic programming. We illustrate it further using a variant of the so-called
More informationCS 170 DISCUSSION 8 DYNAMIC PROGRAMMING. Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17
CS 170 DISCUSSION 8 DYNAMIC PROGRAMMING Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17 DYNAMIC PROGRAMMING Recursive problems uses the subproblem(s) solve the current one. Dynamic
More informationChapter 3 Dynamic programming
Chapter 3 Dynamic programming 1 Dynamic programming also solve a problem by combining the solutions to subproblems. But dynamic programming considers the situation that some subproblems will be called
More informationLecture 17: Array Algorithms
Lecture 17: Array Algorithms CS178: Programming Parallel and Distributed Systems April 4, 2001 Steven P. Reiss I. Overview A. We talking about constructing parallel programs 1. Last time we discussed sorting
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 6, 2016 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 7 April 6, 2016 洪國寶 1 Course information (5/5) Grading (Tentative) Homework 25% (You may collaborate when solving the homework, however when writing up
More informationChapter 1: Number and Operations
Chapter 1: Number and Operations 1.1 Order of operations When simplifying algebraic expressions we use the following order: 1. Perform operations within a parenthesis. 2. Evaluate exponents. 3. Multiply
More information16.Greedy algorithms
16.Greedy algorithms 16.1 An activity-selection problem Suppose we have a set S = {a 1, a 2,..., a n } of n proposed activities that with to use a resource. Each activity a i has a start time s i and a
More informationIN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech
IN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech License CC BY-NC-SA 2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Outline Previously on IN101 Python s anatomy Functions,
More informationAlgorithm classification
Types of Algorithms Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We ll talk about a classification scheme for algorithms This classification scheme
More information- Main approach is recursive, but holds answers to subproblems in a table so that can be used again without re-computing
Dynamic Programming class 2 - Main approach is recursive, but holds answers to subproblems in a table so that can be used again without re-computing - Can be formulated both via recursion and saving in
More information6.001 Notes: Section 4.1
6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,
More information