CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 17.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

1 Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Overview What is Dynamic Programming? A Sequence of 4 Steps
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Introduction to Algorithms
CSCI 256 Data Structures and Algorithm Analysis Lecture 13 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 20.
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 Lecture 9 Asst. Prof. Dr. İlker Kocabaş 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
DYNAMIC PROGRAMMING. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
Lecture 37 CSE 331 Nov 4, Homework stuff (Last!) HW 10 at the end of the lecture Solutions to HW 9 on Monday Graded HW 9 on.
Dynamic Programming CIS 606 Spring 2010.
Lecture 38 CSE 331 Dec 3, A new grading proposal Towards your final score in the course MAX ( mid-term as 25%+ finals as 40%, finals as 65%) .
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.
Lecture 36 CSE 331 Dec 2, Graded HW 8 END of the lecture.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
Lecture 37 CSE 331 Dec 1, A new grading proposal Towards your final score in the course MAX ( mid-term as 25%+ finals as 40%, finals as 65%) .
Dynamic Programming 0-1 Knapsack These notes are taken from the notes by Dr. Steve Goddard at
1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into.
Analysis of Algorithms
Dynamic Programming Adapted from Introduction and Algorithms by Kleinberg and Tardos.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 13 Dynamic.
ADA: 7. Dynamic Prog.1 Objective o introduce DP, its two hallmarks, and two major programming techniques o look at two examples: the fibonacci.
1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into.
CSCI 256 Data Structures and Algorithm Analysis Lecture 14 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
1 Summary: Design Methods for Algorithms Andreas Klappenecker.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 8.
COSC 3101A - Design and Analysis of Algorithms 7 Dynamic Programming Assembly-Line Scheduling Matrix-Chain Multiplication Elements of DP Many of these.
CSC401: Analysis of Algorithms CSC401 – Analysis of Algorithms Chapter Dynamic Programming Objectives: Present the Dynamic Programming paradigm.
1 Programming for Engineers in Python Autumn Lecture 12: Dynamic Programming.
1 Chapter 6 Dynamic Programming. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, optimizing some local criterion. Divide-and-conquer.
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Topic 25 Dynamic Programming "Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it.
1 Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 14.
1 Chapter 6-1 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Sequence Alignment Tanya Berger-Wolf CS502: Algorithms in Computational Biology January 25, 2011.
Chapter 6 Dynamic Programming
1 Dynamic Programming Topic 07 Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing Lab. School of Information and Computer Technology.
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.
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
Computer Sciences Department1.  Property 1: each node can have up to two successor nodes (children)  The predecessor node of a node is called its.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
CSC5101 Advanced Algorithms Analysis
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
1 Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 18.
CSCI 256 Data Structures and Algorithm Analysis Lecture 16 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 3.
Lecture 33 CSE 331 Nov 20, HW 8 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm Submit your HWs to the side of.
Lecture 10: Dynamic Programming 1 CS 341: Algorithms Thursday, June 2 nd
CS502: Algorithms in Computational Biology
Weighted Interval Scheduling
Advanced Design and Analysis Techniques
Greedy Algorithms / Interval Scheduling Yin Tat Lee
CS38 Introduction to Algorithms
Prepared by Chen & Po-Chuan 2016/03/29
Chapter 6 Dynamic Programming
Chapter 6 Dynamic Programming
DYNAMIC PROGRAMMING.
Lecture 4 Dynamic Programming
Lecture 36 CSE 331 Nov 28, 2011.
Analysis of Algorithms CS 477/677
Asst. Prof. Dr. İlker Kocabaş
Dynamic Programming.
Presentation transcript:

CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 17

Algorithmic Paradigms Greed –Build up a solution incrementally, myopically optimizing some local criterion Divide-and-conquer –Break up a problem into two subproblems, solve each subproblem independently, and combine solution to subproblems to form solution to original problem Dynamic programming –Break up a problem into a series of overlapping subproblems, and build up solutions to larger and larger subproblems –Rather than solving overlapping problems again and again, solve each subproblem only once and record the results in a table. This simple idea can easily transform exponential-time algorithms into polynomial-time algorithms

Dynamic Programming (DP) DP is like the divide-and-conquer method in that it solves problems by combining the solutions to subproblems Divide-and-conquer algorithms partition the problem into independent subproblems, solve the subproblems recursively, and then combine their solutions to solve the original problem In contrast, DP is applicable when the subproblems are not independent (i.e., subproblems share subsubproblems). In this context, divide-and-conquer does more work than necessary, repeatedly solving the common subsubproblems. DP solves each subproblem just once and saves its answer in a table

DP History Bellman –Pioneered the systematic study of DP in the 1950s –DP as a general method for optimizing multistage decision processes Etymology –Dynamic programming = planning over time. Thus the word “programming” in the name of this technique stands for “planning”, not computer programming –Secretary of Defense was hostile to mathematical research –Bellman sought an impressive name to avoid confrontation "it's impossible to use dynamic in a pejorative sense" "something not even a Congressman could object to" Reference: Bellman, R. E. Eye of the Hurricane, An Autobiography.

DP Applications Areas –Bioinformatics –Control theory –Information theory –Operations research –Computer science: theory, graphics, AI, systems, …. Some famous DP algorithms –Viterbi for hidden Markov models –Unix diff for comparing two files –Smith-Waterman for sequence alignment –Bellman-Ford for shortest path routing in networks –Cocke-Kasami-Younger for parsing context free grammars

Developing DP algorithms The development of a DP algorithm can be broken into a sequence of 4 steps 1)Characterize the structure of an optimal solution 2)Recursively define the value of an optimal solution 3)Compute the value of an optimal solution in a bottom-up fashion 4)Construct an optimal solution from computed information

Weighted Interval Scheduling Weighted interval scheduling problem –Job j starts at s j, finishes at f j, and has weight or value v j –Two jobs compatible if they don't overlap –Goal: find maximum weight subset of mutually compatible jobs Time f g h e a b c d

Unweighted Interval Scheduling Review Recall: Greedy algorithm works if all weights are 1 –Consider jobs in ascending order of finish time –Add job to subset if it is compatible with previously chosen jobs Observation: Greedy algorithm can fail spectacularly if arbitrary weights are allowed Time b a weight = 999 weight = 1

Weighted Interval Scheduling Notation: Label jobs by finishing time: f 1  f 2 ...  f n Def: p(j) = largest index i < j such that job i is compatible with j Ex: p(8) = 5, p(7) = 3, p(2) = 0 Time

DP: Binary Choice Notation: OPT(j) = value of optimal solution to the problem consisting of job requests 1, 2,..., j –Case 1: OPT selects job j can't use incompatible jobs { p(j) + 1, p(j) + 2,..., j - 1 } must include optimal solution to problem consisting of remaining compatible jobs 1, 2,..., p(j) –Case 2: OPT does not select job j must include optimal solution to problem consisting of remaining compatible jobs 1, 2,..., j-1 optimal substructure

Weighted Interval Scheduling: Brute Force Brute force algorithm Input: n, s 1,…,s n, f 1,…,f n, v 1,…,v n Sort jobs by finish times so that f 1  f 2 ...  f n Compute p(1), p(2), …, p(n) Compute-Opt(j) { if (j = 0) return 0 else return max(v j + Compute-Opt(p(j)), Compute-Opt(j-1)) }

Weighted Interval Scheduling: Brute Force Observation: Recursive algorithm fails spectacularly because of redundant subproblems  exponential algorithm Number of recursive calls for family of "layered" instances grows like Fibonacci sequence p(1) = 0, p(j) = j

Weighted Interval Scheduling: Memoization Memoization: Store results of each subproblem in a cache; lookup as needed Input: n, s 1,…,s n, f 1,…,f n, v 1,…,v n Sort jobs by finish times so that f 1  f 2 ...  f n Compute p(1), p(2), …, p(n) for j = 1 to n Opt[j] = -1 Opt[0] = 0 M-Compute-Opt(j) { if (Opt[j] == -1) Opt[j] = max(v j + M-Compute-Opt(p(j)), M-Compute-Opt(j-1)) return Opt[j] }

Fill in the array with the Opt values Opt[ j ] = max (v j + Opt[ p[ j ] ], Opt[ j – 1])

Weighted Interval Scheduling: Running Time Claim: Memoized version of algorithm takes O(n log n) time –Sort by finish time: O(n log n) –Computing p(  ) : O(n) after sorting by finish time –M-Compute-Opt(j) : each invocation takes O(1) time and either (i) returns an existing value Opt[j] (ii) fills in one new entry Opt[j] and makes two recursive calls Progress measure  = # nonempty entries of Opt[] –initially  = 0, throughout   n –(ii) increases  by 1  at most 2n recursive calls Overall running time of M-Compute-Opt(n) is O(n)

Weighted Interval Scheduling: Finding a Solution Q: DP algorithm computes optimal value. What if we want the solution itself? –A: Do some post-processing –# of recursive calls  n  O(n) Run M-Compute-Opt(n) Run Find-Solution(n) Find-Solution(j) { if (j = 0) output nothing else if (v j + Opt[p(j)] > Opt[j-1]) print j Find-Solution(p(j)) else Find-Solution(j-1) }

Weighted Interval Scheduling: Iterative Version Input: n, s 1,…,s n, f 1,…,f n, v 1,…,v n Sort jobs by finish times so that f 1  f 2 ...  f n. Compute p(1), p(2), …, p(n) Iterative-Compute-Opt { Opt[0] = 0 for j = 1 to n Opt[j] = max(v j + Opt[p(j)], Opt[j-1]) }