CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure

Size: px
Start display at page:

Download "CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure"

Transcription

1 CSE Weighted Interval Scheduling, Knapsack, RNA Secondary Structure Shayan Oveis haran

2 Weighted Interval Scheduling

3 Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs compatible if they don t overlap. oal: find maximum weight subset of mutually compatible jobs. a b c d e f g 9 h Time

4 Weighted Job Scheduling by Induction Suppose,, n are all jobs. This Let idea us works use induction: for any Optimization problem, e.g., vertexcover, we can independent compute the set, optimum etc. job scheduling IH (strong ind): Suppose for < n jobs. For NP-hard problems there is no ordering to reduce # subproblems IS: oal: For any n jobs we can compute OPT. Case : Job n is not in OPT. -- Then, just return OPT of,, n. Take best of the two Case : Job n is in OPT. -- Then, delete all jobs not compatible with n and recurse. Q: Are we done? A: No, How many subproblems are there? Potentially n all possible subsets of jobs. n n- n- n- n- n- n-

5 Sorting to Reduce Subproblems Sorting Idea: Label jobs by finishing time f f(n) IS: For jobs,,n we want to compute OPT Case : Suppose OPT has job n. So, all jobs i that are not compatible with n are not OPT Let p(n) = largest index i < n such that job i is compatible with n. Then, we just need to find OPT of,, p(n) P(n) P(n)+ n- n- n

6 Sorting to reduce Subproblems Sorting Idea: Label jobs by finishing time f f(n) IS: For jobs,,n we want to compute OPT Case : Suppose OPT has job n. So, all jobs i that are not compatible with n are not OPT Let p(n) = largest index i < n such that job i is compatible with n. Then, we just need to find OPT of,, p(n) Case : OPT does not select job n. Then, OPT is just the OPT of,, n Take best of the two Q: Have we made any progress (still reducing to two subproblems)? A: Yes! This time every subproblem is of the form,, i for some i So, at most n possible subproblems.

7 Weighted Job Scheduling by Induction Sorting Idea: Label jobs by finishing time f f(n) Def OPT(j) denote the OPT solution of,, j The most important part of a correct DP; It fixes IH To solve OPT(j): Case : OPT(j) has job j. So, all jobs i that are not compatible with j are not OPT(j) Let p(j) = largest index i < j such that job i is compatible with j. So OPT j = OPT p j j. Case : OPT(j) does not select job j. Then, OPT j = OPT(j ) if j = OPT j = ቐ max w j + OPT p j, OPT j o. w.

8 Algorithm Input: n, s,, s(n) and f,, f(n) and w,, w n. Sort jobs by finish times so that f f f(n). Compute p(), p(),, p(n) Compute-Opt(j) { if (j = ) return else return max(w j } + Compute-Opt(p(j)), Compute-Opt(j-))

9 Recursive Algorithm Fails Even though we have only n subproblems, we do not store the solution to the subproblems So, we may re-solve the same problem many many times. Ex. Number of recursive calls for family of "layered" instances grows like Fibonacci sequence p() =, p(j) = j- 9

10 Algorithm with Memorization Memoization. Compute and Store the solution of each sub-problem in a cache the first time that you face it. lookup as needed. Input: n, s,, s(n) and f,, f(n) and w,, w n. Sort jobs by finish times so that f f f(n). Compute p(), p(),, p(n) for j = to n M[j] = empty M[] = M-Compute-Opt(j) { if (M[j] is empty) M[j] = max(w j + M-Compute-Opt(p(j)), M-Compute-Opt(j-)) return M[j] }

11 Bottom up Dynamic Programming You can also avoid recusion recursion may be easier conceptually when you use induction Input: n, s,, s(n) and f,, f(n) and w,, w n. Sort jobs by finish times so that f f f(n). Compute p(), p(),, p(n) Iterative-Compute-Opt { M[] = for j = to n M[j] = max(w j + M[p(j)], M[j-]) } Output M[n] Claim: M[j] is value of OPT(j) Timing: Easy. Main loop is O(n); sorting is O(n log n)

12 Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9 OPT(j) p(j) w j j

13 Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9 OPT(j) p(j) w j j

14 Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9 OPT(j) p(j) w j j

15 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

16 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

17 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

18 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

19 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

20 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

21 OPT(j) p(j) w j j Example Label jobs by finishing time: f f n. p(j) = largest index i < j such that job i is compatible with j. Time 9

22 Knapsack Problem

23 Knapsack Problem iven n objects and a "knapsack. Item i weighs w i > kilograms and has value v i >. Knapsack has capacity of W kilograms. oal: fill knapsack so as to maximize total value. Item Value Weight Ex: OPT is {, } with value. W = reedy: repeatedly add item with maximum ratio v i / w i. Ex: {,, } achieves only value = greedy not optimal.

24 Dynamic Programming: First Attempt Let OPT(i)=Max value of subsets of items,, i of weight W. Case : OPT(i) does not select item i - In this caes OPT(i) = OPT(i ) Case : OPT(i) selects item i In this case, item i does not immediately imply we have to reject other items The problem does not reduce to OPT(i ) because we now want to pack as much value into box of weight W w i Conclusion: We need more subproblems, we need to strengthen IH.

25 Stronger DP (Strengthenning Hypothesis) Let OPT(i, w) = Max value of subsets of items,, i of weight w Case : OPT(i, w) selects item i In this case, OPT i, w = v i + OPT(i, w w i ) Case : OPT i, w does not select item i In this case, OPT i, w = OPT(i, w). Take best of the two Therefore, OPT i, w = ቐOPT i, w max(opt i, w, v i + OPT i, w w i If i = If w i > w o.w.,

26 DP for Knapsack Compute-OPT(i,w) if M[i,w] == empty if (i==) M[i,w]= recursive else if (w i > w) M[i,w]=Comp-OPT(i-,w) else M[i,w]= max {Comp-OPT(i-,w), v i + Comp-OPT(i-,w-w i )} return M[i, w] for w = to W M[, w] = for i = to n for w = to W if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Non-recursive return M[n, W]

27 DP for Knapsack W + 9 { } n + {, } {,, } {,,, } {,,,, } W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight

28 DP for Knapsack W + 9 { } n + {, } {,, } {,,, } {,,,, } W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight

29 DP for Knapsack W + 9 { } n + {, } {,, } {,,, } {,,,, } OPT: {, } value = + = W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight 9

30 DP for Knapsack W + 9 { } n + {, } {,, } 9 {,,, } {,,,, } OPT: {, } value = + = W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight

31 DP for Knapsack W + 9 { } n + {, } {,, } 9 {,,, } 9 {,,,, } OPT: {, } value = + = W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight

32 DP for Knapsack W + 9 { } n + {, } {,, } 9 {,,, } 9 9 {,,,, } 9 OPT: {, } value = + = W = if (w i > w) M[i, w] = M[i-, w] else M[i, w] = max {M[i-, w], v i + M[i-, w-w i ]} Item Value Weight

33 Knapsack Problem: Running Time Running time: Θ(n W) Not polynomial in input size! "Pseudo-polynomial. Decision version of Knapsack is NP-complete. Knapsack approximation algorithm: There exists a polynomial algorithm that produces a feasible solution that has value within.% of optimum in time Poly(n, log W).

34 DP Ideas so far You may have to define an ordering to decrease #subproblems You may have to strengthen DP, equivalently the induction, i.e., you have may have to carry more information to find the Optimum. This means that sometimes we may have to use two dimensional or three dimensional induction

35 RNA Secondary Structure

36 RNA Secondary Structure RNA: A String B = b b b n over alphabet { A, C,, U }. Secondary structure. RNA is single-stranded so it tends to loop back and form base pairs with itself. This structure is essential for understanding behavior of molecule. U C A A A C A U A U U A A C A A C U A U C A U C C C Ex: UCAUUACAAUUAACAACUCUACCAA complementary base pairs: A-U, C-

37 RNA Secondary Structure (Formal) Secondary structure. A set of pairs S = { (b i, b j ) } that satisfy: [Watson-Crick.] S is a matching and each pair in S is a Watson-Crick pair: A-U, U-A, C-, or -C. [No sharp turns.]: The ends of each pair are separated by at least intervening bases. If (b i, b j ) S, then i < j -. [Non-crossing.] If (b i, b j ) and (b k, b l ) are two pairs in S, then we cannot have i < k < j < l. Free energy: Usual hypothesis is that an RNA molecule will maximize total free energy. approximate by number of base pairs oal: iven an RNA molecule B = b b b n, find a secondary structure S that maximizes the number of base pairs.

38 Secondary Structure (Examples) C U C U C C C U A U A U A U A U A U A base pair A U U C C A U A U C A U A U U C C A U ok sharp turn crossing

39 DP: First Attempt First attempt. Let OPT(n) = maximum number of base pairs in a secondary structure of the substring b b b n. Suppose b n is matched with b t in OPT n. What IH should we use? match b t and b n t n Diffuclty: This naturally reduces to two subproblems Finding secondary structure in b,, b t, i.e., OPT(t-) Finding secondary structure in b t+,, b n,??? 9

40 DP: Second Attempt Definition: OPT(i, j) = maximum number of base pairs in a secondary structure of the substring b i, b i+,, b j The most important part of a correct DP; It fixes IH Case : If j i. OPT(i, j) = by no-sharp turns condition. Case : Base b j is not involved in a pair. OPT(i, j) = OPT(i, j-) Case : Base b j pairs with b t for some i t < j non-crossing constraint decouples resulting sub-problems OPT(i, j) = + max t { OPT(i, t ) + OPT(t +, j ) }

CSE 421 Dynamic Programming

CSE 421 Dynamic Programming CSE Dynamic Programming Yin Tat Lee Weighted Interval Scheduling Interval Scheduling Job j starts at s(j) and finishes at f j and has weight w j Two jobs compatible if they don t overlap. Goal: find maximum

More information

CSE 202 Dynamic Programming II

CSE 202 Dynamic Programming II CSE 202 Dynamic Programming II Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally,

More information

Dynamic Programming 1

Dynamic Programming 1 Dynamic Programming 1 lgorithmic Paradigms Divide-and-conquer. Break up a problem into two sub-problems, solve each sub-problem independently, and combine solution to sub-problems to form solution to original

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I 6. DYNAMIC PRORAMMIN I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Dynamic Programming: Interval Scheduling and Knapsack

Dynamic Programming: Interval Scheduling and Knapsack Dynamic Programming: Interval Scheduling and Knapsack . Weighted Interval Scheduling Weighted Interval Scheduling Weighted interval scheduling problem. Job j starts at s j, finishes at f j, and has weight

More information

Dynamic Programming. Weighted Interval Scheduling. Algorithmic Paradigms. Dynamic Programming

Dynamic Programming. Weighted Interval Scheduling. Algorithmic Paradigms. Dynamic Programming lgorithmic Paradigms Dynamic Programming reed Build up a solution incrementally, myopically optimizing some local criterion Divide-and-conquer Break up a problem into two sub-problems, solve each sub-problem

More information

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 58: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 28 Announcement: Homework 3 due February 5 th at :59PM Midterm Exam: Wed, Feb 2 (8PM-PM) @ MTHW 2 Recap: Dynamic Programming

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I 6. DYNAMIC PROGRAMMING I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 /9/ lgorithmic Paradigms hapter Dynamic Programming reed. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into two sub-problems, solve

More information

6. DYNAMIC PROGRAMMING I

6. DYNAMIC PROGRAMMING I lgorithmic paradigms 6. DYNMI PRORMMIN I weighted interval scheduling segmented least squares knapsack problem RN secondary structure reedy. Build up a solution incrementally, myopically optimizing some

More information

Dynamic Programming. Cormen et. al. IV 15

Dynamic Programming. Cormen et. al. IV 15 Dynamic Programming Cormen et. al. IV 5 Dynamic Programming Applications Areas. Bioinformatics. Control theory. Operations research. Some famous dynamic programming algorithms. Unix diff for comparing

More information

Chapter 6. Weighted Interval Scheduling. Dynamic Programming. Algorithmic Paradigms. Dynamic Programming Applications

Chapter 6. Weighted Interval Scheduling. Dynamic Programming. Algorithmic Paradigms. Dynamic Programming Applications lgorithmic Paradigms hapter Dynamic Programming reedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into sub-problems, solve each

More information

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,.

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,. lgorithmic Paradigms hapter Dynamic Programming reed Build up a solution incrementally, myopically optimizing some local criterion Divide-and-conquer Break up a problem into two sub-problems, solve each

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 //8 Fast Integer Division Too (!) Schönhage Strassen algorithm CS 8: Algorithm Design and Analysis Integer division. Given two n-bit (or less) integers s and t, compute quotient q = s / t and remainder

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 208 Announcement: Homework 3 due February 5 th at :59PM Final Exam (Tentative): Thursday, May 3 @ 8AM (PHYS 203) Recap: Divide

More information

Dynamic Programming( Weighted Interval Scheduling)

Dynamic Programming( Weighted Interval Scheduling) Dynamic Programming( Weighted Interval Scheduling) 17 November, 2016 Dynamic Programming 1 Dynamic programming algorithms are used for optimization (for example, finding the shortest path between two points,

More information

CS Lunch. Dynamic Programming Recipe. 2 Midterm 2! Slides17 - Segmented Least Squares.key - November 16, 2016

CS Lunch. Dynamic Programming Recipe. 2 Midterm 2! Slides17 - Segmented Least Squares.key - November 16, 2016 CS Lunch 1 Michelle Oraa Ali Tien Dao Vladislava Paskova Nan Zhuang Surabhi Sharma Wednesday, 12:15 PM Kendade 307 2 Midterm 2! Monday, November 21 In class Covers Greedy Algorithms Closed book Dynamic

More information

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov Dynamic Programming Data Structures and Algorithms Andrei Bulatov Algorithms Dynamic Programming 18-2 Weighted Interval Scheduling Weighted interval scheduling problem. Instance A set of n jobs. Job j

More information

Chapter 6. Dynamic Programming. CS 350: Winter 2018

Chapter 6. Dynamic Programming. CS 350: Winter 2018 Chapter 6 Dynamic Programming CS 350: Winter 2018 1 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer. Break up a problem into

More information

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Dynamic Programming Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Paradigms for Designing Algorithms Greedy algorithm Make a

More information

RNA Secondary Structure. CSE 417 W.L. Ruzzo

RNA Secondary Structure. CSE 417 W.L. Ruzzo RN Secondary Structure SE 417 W.L. Ruzzo The Double Helix Los lamos Science The entral Dogma of Molecular Biology DN RN Protein gene Protein DN (chromosome) cell RN (messenger) Non-coding RN Messenger

More information

Activity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities.

Activity selection. Goal: Select the largest possible set of nonoverlapping (mutually compatible) activities. Greedy Algorithm 1 Introduction Similar to dynamic programming. Used for optimization problems. Not always yield an optimal solution. Make choice for the one looks best right now. Make a locally optimal

More information

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n Aside: Golden Ratio Golden Ratio: A universal law. Golden ratio φ = lim n a n+b n a n = 1+ 5 2 a n+1 = a n + b n, b n = a n 1 Ruta (UIUC) CS473 1 Spring 2018 1 / 41 CS 473: Algorithms, Spring 2018 Dynamic

More information

Dynamic programming. Curs 2015

Dynamic programming. Curs 2015 Dynamic programming. Curs 2015 Fibonacci Recurrence. n-th Fibonacci Term INPUT: n nat QUESTION: Compute F n = F n 1 + F n 2 Recursive Fibonacci (n) if n = 0 then return 0 else if n = 1 then return 1 else

More information

Greedy Algorithms My T. UF

Greedy Algorithms My T. UF Introduction to Algorithms Greedy Algorithms @ UF Overview A greedy algorithm always makes the choice that looks best at the moment Make a locally optimal choice in hope of getting a globally optimal solution

More information

Algoritmiek, bijeenkomst 3

Algoritmiek, bijeenkomst 3 Algoritmiek, bijeenkomst 3 Mathijs de Weerdt Today Introduction Greedy Divide and Conquer (very briefly) Dynamic programming Slides with thanks to Kevin Wayne and Pearson Education (made available together

More information

Knapsack and Scheduling Problems. The Greedy Method

Knapsack and Scheduling Problems. The Greedy Method The Greedy Method: Knapsack and Scheduling Problems The Greedy Method 1 Outline and Reading Task Scheduling Fractional Knapsack Problem The Greedy Method 2 Elements of Greedy Strategy An greedy algorithm

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 12.1 Introduction Today we re going to do a couple more examples of dynamic programming. While

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

This means that we can assume each list ) is

This means that we can assume each list ) is This means that we can assume each list ) is of the form ),, ( )with < and Since the sizes of the items are integers, there are at most +1pairs in each list Furthermore, if we let = be the maximum possible

More information

CSE 421 Greedy Algorithms / Interval Scheduling

CSE 421 Greedy Algorithms / Interval Scheduling CSE 421 Greedy Algorithms / Interval Scheduling Yin Tat Lee 1 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

More information

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing

More information

The Double Helix. CSE 417: Algorithms and Computational Complexity! The Central Dogma of Molecular Biology! DNA! RNA! Protein! Protein!

The Double Helix. CSE 417: Algorithms and Computational Complexity! The Central Dogma of Molecular Biology! DNA! RNA! Protein! Protein! The Double Helix SE 417: lgorithms and omputational omplexity! Winter 29! W. L. Ruzzo! Dynamic Programming, II" RN Folding! http://www.rcsb.org/pdb/explore.do?structureid=1t! Los lamos Science The entral

More information

Dynamic programming. Curs 2017

Dynamic programming. Curs 2017 Dynamic programming. Curs 2017 Fibonacci Recurrence. n-th Fibonacci Term INPUT: n nat QUESTION: Compute F n = F n 1 + F n 2 Recursive Fibonacci (n) if n = 0 then return 0 else if n = 1 then return 1 else

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 6 Greedy Algorithms Interval Scheduling Interval Partitioning Scheduling to Minimize Lateness Sofya Raskhodnikova S. Raskhodnikova; based on slides by E. Demaine,

More information

13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks

13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks 13 Dynamic Programming (3) Optimal Binary Search Trees Subset Sums & Knapsacks Average-case analysis Average-case analysis of algorithms and data structures: Input is generated according to a known probability

More information

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Algorithmic Paradigms Greed. Build up a solution incrementally, myopically optimizing some

More information

Mat 3770 Bin Packing or

Mat 3770 Bin Packing or Basic Algithm Spring 2014 Used when a problem can be partitioned into non independent sub problems Basic Algithm Solve each sub problem once; solution is saved f use in other sub problems Combine solutions

More information

Matching Residents to Hospitals

Matching Residents to Hospitals Midterm Review Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and

More information

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad DAA Unit- II Greedy and Dynamic Programming By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad 1 Greedy Method 2 Greedy Method Greedy Principal: are typically

More information

1.1 First Problem: Stable Matching. Six medical students and four hospitals. Student Preferences. s6 h3 h1 h4 h2. Stable Matching Problem

1.1 First Problem: Stable Matching. Six medical students and four hospitals. Student Preferences. s6 h3 h1 h4 h2. Stable Matching Problem //0 hapter Introduction: Some Representative Problems Slides by Kevin ayne. opyright 00 Pearson-ddison esley. ll rights reserved.. First Problem: Stable Matching Six medical students and four hospitals

More information

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD Course Overview Material that will be covered in the course: Basic graph algorithms Algorithm Design Techniques Greedy Algorithms Divide and Conquer Dynamic Programming Network Flows Computational intractability

More information

Recursion: Introduction and Correctness

Recursion: Introduction and Correctness Recursion: Introduction and Correctness CSE21 Winter 2017, Day 7 (B00), Day 4-5 (A00) January 25, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Today s Plan From last time: intersecting sorted lists and

More information

Lecture 9. Greedy Algorithm

Lecture 9. Greedy Algorithm Lecture 9. Greedy Algorithm 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 information

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved. Chapter 11 Approximation Algorithms Slides by Kevin Wayne. Copyright @ 2005 Pearson-Addison Wesley. All rights reserved. 1 Approximation Algorithms Q. Suppose I need to solve an NP-hard problem. What should

More information

CS60007 Algorithm Design and Analysis 2018 Assignment 1

CS60007 Algorithm Design and Analysis 2018 Assignment 1 CS60007 Algorithm Design and Analysis 2018 Assignment 1 Palash Dey and Swagato Sanyal Indian Institute of Technology, Kharagpur Please submit the solutions of the problems 6, 11, 12 and 13 (written in

More information

CS 6901 (Applied Algorithms) Lecture 3

CS 6901 (Applied Algorithms) Lecture 3 CS 6901 (Applied Algorithms) Lecture 3 Antonina Kolokolova September 16, 2014 1 Representative problems: brief overview In this lecture we will look at several problems which, although look somewhat similar

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and

More information

Knapsack. Bag/knapsack of integer capacity B n items item i has size s i and profit/weight w i

Knapsack. Bag/knapsack of integer capacity B n items item i has size s i and profit/weight w i Knapsack Bag/knapsack of integer capacity B n items item i has size s i and profit/weight w i Goal: find a subset of items of maximum profit such that the item subset fits in the bag Knapsack X: item set

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 0, Winter 08 Design and Analysis of Algorithms Lecture 8: Consolidation # (DP, Greed, NP-C, Flow) Class URL: http://vlsicad.ucsd.edu/courses/cse0-w8/ Followup on IGO, Annealing Iterative Global Optimization

More information

CS583 Lecture 11. Many slides here are based on D. Luebke slides. Review: Dynamic Programming

CS583 Lecture 11. Many slides here are based on D. Luebke slides. Review: Dynamic Programming // CS8 Lecture Jana Kosecka Dynamic Programming Greedy Algorithms Many slides here are based on D. Luebke slides Review: Dynamic Programming A meta-technique, not an algorithm (like divide & conquer) Applicable

More information

Greedy. Outline CS141. Stefano Lonardi, UCR 1. Activity selection Fractional knapsack Huffman encoding Later:

Greedy. Outline CS141. Stefano Lonardi, UCR 1. Activity selection Fractional knapsack Huffman encoding Later: October 5, 017 Greedy Chapters 5 of Dasgupta et al. 1 Activity selection Fractional knapsack Huffman encoding Later: Outline Dijkstra (single source shortest path) Prim and Kruskal (minimum spanning tree)

More information

Minimizing the Number of Tardy Jobs

Minimizing the Number of Tardy Jobs Minimizing the Number of Tardy Jobs 1 U j Example j p j d j 1 10 10 2 2 11 3 7 13 4 4 15 5 8 20 Ideas: Need to choose a subset of jobs S that meet their deadlines. Schedule the jobs that meet their deadlines

More information

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved. Chapter 11 Approximation Algorithms Slides by Kevin Wayne. Copyright @ 2005 Pearson-Addison Wesley. All rights reserved. 1 P and NP P: The family of problems that can be solved quickly in polynomial time.

More information

CS325: Analysis of Algorithms, Fall Final Exam

CS325: Analysis of Algorithms, Fall Final Exam CS: Analysis of Algorithms, Fall 0 Final Exam I don t know policy: you may write I don t know and nothing else to answer a question and receive percent of the total points for that problem whereas a completely

More information

Bin packing and scheduling

Bin packing and scheduling Sanders/van Stee: Approximations- und Online-Algorithmen 1 Bin packing and scheduling Overview Bin packing: problem definition Simple 2-approximation (Next Fit) Better than 3/2 is not possible Asymptotic

More information

CS Analysis of Recursive Algorithms and Brute Force

CS Analysis of Recursive Algorithms and Brute Force CS483-05 Analysis of Recursive Algorithms and Brute Force Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 4:30pm - 5:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 5 Greedy Algorithms Interval Scheduling Interval Partitioning Guest lecturer: Martin Furer Review In a DFS tree of an undirected graph, can there be an edge (u,v)

More information

Greedy Algorithms. Kleinberg and Tardos, Chapter 4

Greedy Algorithms. Kleinberg and Tardos, Chapter 4 Greedy Algorithms Kleinberg and Tardos, Chapter 4 1 Selecting breakpoints Road trip from Fort Collins to Durango on a given route. Fuel capacity = C. Goal: makes as few refueling stops as possible. Greedy

More information

General Methods for Algorithm Design

General Methods for Algorithm Design General Methods for Algorithm Design 1. Dynamic Programming Multiplication of matrices Elements of the dynamic programming Optimal triangulation of polygons Longest common subsequence 2. Greedy Methods

More information

CMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017

CMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017 CMSC CMSC : Lecture Greedy Algorithms for Scheduling Tuesday, Sep 9, 0 Reading: Sects.. and. of KT. (Not covered in DPV.) Interval Scheduling: We continue our discussion of greedy algorithms with a number

More information

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University Algorithms NP -Complete Problems Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr The Class P Definition 13.2 Polynomially bounded An algorithm is said to be polynomially bounded if its worst-case

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and

More information

Lecture 7: Dynamic Programming I: Optimal BSTs

Lecture 7: Dynamic Programming I: Optimal BSTs 5-750: Graduate Algorithms February, 06 Lecture 7: Dynamic Programming I: Optimal BSTs Lecturer: David Witmer Scribes: Ellango Jothimurugesan, Ziqiang Feng Overview The basic idea of dynamic programming

More information

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 17. Recurrence

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 17. Recurrence Discrete Mathematics: Logic Discrete Mathematics: Lecture 17. Recurrence greedy algorithm greedy algorithm makes the best choice at each step (locally optimal solution) according to a specified criterion

More information

if the two intervals overlap at most at end

if the two intervals overlap at most at end Activity Selection Given a set of activities represented by intervals (s i f i ), i =1 ::: n. To select a maximum number of compatible intervals (activities). Two activities (s i f i ) and (s j f j ) are

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright Pearson-Addison Wesley. All rights reserved. 4 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and finishes

More information

Algorithms Design & Analysis. Dynamic Programming

Algorithms Design & Analysis. Dynamic Programming Algorithms Design & Analysis Dynamic Programming Recap Divide-and-conquer design paradigm Today s topics Dynamic programming Design paradigm Assembly-line scheduling Matrix-chain multiplication Elements

More information

Greedy vs Dynamic Programming Approach

Greedy vs Dynamic Programming Approach Greedy vs Dynamic Programming Approach Outline Compare the methods Knapsack problem Greedy algorithms for 0/1 knapsack An approximation algorithm for 0/1 knapsack Optimal greedy algorithm for knapsack

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms Texas Tech University September, 2017 Introduction Two ideas are gleaming on the jeweler s velvet. First is the calculus, the second, the algorithm. The calculus made

More information

The Greedy Method. Design and analysis of algorithms Cs The Greedy Method

The Greedy Method. Design and analysis of algorithms Cs The Greedy Method Design and analysis of algorithms Cs 3400 The Greedy Method 1 Outline and Reading The Greedy Method Technique Fractional Knapsack Problem Task Scheduling 2 The Greedy Method Technique The greedy method

More information

Dynamic Programming 11/8/2009. Weighted Interval Scheduling. Weighted Interval Scheduling. Unweighted Interval Scheduling: Review

Dynamic Programming 11/8/2009. Weighted Interval Scheduling. Weighted Interval Scheduling. Unweighted Interval Scheduling: Review //9 Algorihms Dynamic Programming - Weighed Ineral Scheduling Dynamic Programming Weighed ineral scheduling problem. Insance A se of n jobs. Job j sars a s j, finishes a f j, and has weigh or alue j. Two

More information

6.6 Sequence Alignment

6.6 Sequence Alignment 6.6 Sequence Alignment String Similarity How similar are two strings? ocurrance o c u r r a n c e - occurrence First model the problem Q. How can we measure the distance? o c c u r r e n c e 6 mismatches,

More information

Dynamic Programming. Credits: Many of these slides were originally authored by Jeff Edmonds, York University. Thanks Jeff!

Dynamic Programming. Credits: Many of these slides were originally authored by Jeff Edmonds, York University. Thanks Jeff! Dynamic Programming Credits: Many of these slides were originally authored by Jeff Edmonds, York University. Thanks Jeff! Optimization Problems For most, the best known algorithm runs in exponential time.

More information

CSE 202 Homework 4 Matthias Springer, A

CSE 202 Homework 4 Matthias Springer, A CSE 202 Homework 4 Matthias Springer, A99500782 1 Problem 2 Basic Idea PERFECT ASSEMBLY N P: a permutation P of s i S is a certificate that can be checked in polynomial time by ensuring that P = S, and

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 10 Dynamic Programming View in slide-show mode CS 473 Lecture 10 Cevdet Aykanat and Mustafa Ozdal, Bilkent University 1 Introduction An algorithm design paradigm like divide-and-conquer

More information

COSC 341: Lecture 25 Coping with NP-hardness (2)

COSC 341: Lecture 25 Coping with NP-hardness (2) 1 Introduction Figure 1: Famous cartoon by Garey and Johnson, 1979 We have seen the definition of a constant factor approximation algorithm. The following is something even better. 2 Approximation Schemes

More information

CSI Mathematical Induction. Many statements assert that a property of the form P(n) is true for all integers n.

CSI Mathematical Induction. Many statements assert that a property of the form P(n) is true for all integers n. CSI 2101- Mathematical Induction Many statements assert that a property of the form P(n) is true for all integers n. Examples: For every positive integer n: n! n n Every set with n elements, has 2 n Subsets.

More information

Algorithms: COMP3121/3821/9101/9801

Algorithms: COMP3121/3821/9101/9801 NEW SOUTH WALES Algorithms: COMP3121/3821/9101/9801 Aleks Ignjatović School of Computer Science and Engineering University of New South Wales TOPIC 4: THE GREEDY METHOD COMP3121/3821/9101/9801 1 / 23 The

More information

APTAS for Bin Packing

APTAS for Bin Packing APTAS for Bin Packing Bin Packing has an asymptotic PTAS (APTAS) [de la Vega and Leuker, 1980] For every fixed ε > 0 algorithm outputs a solution of size (1+ε)OPT + 1 in time polynomial in n APTAS for

More information

8 Knapsack Problem 8.1 (Knapsack)

8 Knapsack Problem 8.1 (Knapsack) 8 Knapsack In Chapter 1 we mentioned that some NP-hard optimization problems allow approximability to any required degree. In this chapter, we will formalize this notion and will show that the knapsack

More information

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming Algorithms and Theory of Computation Lecture 9: Dynamic Programming Xiaohui Bei MAS 714 September 10, 2018 Nanyang Technological University MAS 714 September 10, 2018 1 / 21 Recursion in Algorithm Design

More information

- Well-characterized problems, min-max relations, approximate certificates. - LP problems in the standard form, primal and dual linear programs

- Well-characterized problems, min-max relations, approximate certificates. - LP problems in the standard form, primal and dual linear programs LP-Duality ( Approximation Algorithms by V. Vazirani, Chapter 12) - Well-characterized problems, min-max relations, approximate certificates - LP problems in the standard form, primal and dual linear programs

More information

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle Directed Hamiltonian Cycle Chapter 8 NP and Computational Intractability Claim. G has a Hamiltonian cycle iff G' does. Pf. Suppose G has a directed Hamiltonian cycle Γ. Then G' has an undirected Hamiltonian

More information

arxiv: v1 [math.oc] 3 Jan 2019

arxiv: v1 [math.oc] 3 Jan 2019 The Product Knapsack Problem: Approximation and Complexity arxiv:1901.00695v1 [math.oc] 3 Jan 2019 Ulrich Pferschy a, Joachim Schauer a, Clemens Thielen b a Department of Statistics and Operations Research,

More information

CS2223 Algorithms D Term 2009 Exam 3 Solutions

CS2223 Algorithms D Term 2009 Exam 3 Solutions CS2223 Algorithms D Term 2009 Exam 3 Solutions May 4, 2009 By Prof. Carolina Ruiz Dept. of Computer Science WPI PROBLEM 1: Asymptoptic Growth Rates (10 points) Let A and B be two algorithms with runtimes

More information

Chapter 8 Dynamic Programming

Chapter 8 Dynamic Programming Chapter 8 Dynamic Programming Copyright 2007 Pearson Addison-Wesley. All rights reserved. Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by

More information

Unit 1A: Computational Complexity

Unit 1A: Computational Complexity Unit 1A: Computational Complexity Course contents: Computational complexity NP-completeness Algorithmic Paradigms Readings Chapters 3, 4, and 5 Unit 1A 1 O: Upper Bounding Function Def: f(n)= O(g(n)) if

More information

Lecture 6: Greedy Algorithms I

Lecture 6: Greedy Algorithms I COMPSCI 330: Design and Analysis of Algorithms September 14 Lecturer: Rong Ge Lecture 6: Greedy Algorithms I Scribe: Fred Zhang 1 Overview In this lecture, we introduce a new algorithm design technique

More information

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016) The final exam will be on Thursday, May 12, from 8:00 10:00 am, at our regular class location (CSI 2117). It will be closed-book and closed-notes, except

More information

CS 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring / 1

CS 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring / 1 CS 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring 2017 1 / 1 Part I Greedy Algorithms: Tools and Techniques Chandra

More information

CS 6783 (Applied Algorithms) Lecture 3

CS 6783 (Applied Algorithms) Lecture 3 CS 6783 (Applied Algorithms) Lecture 3 Antonina Kolokolova January 14, 2013 1 Representative problems: brief overview of the course In this lecture we will look at several problems which, although look

More information

CSE 311: Foundations of Computing. Lecture 14: Induction

CSE 311: Foundations of Computing. Lecture 14: Induction CSE 311: Foundations of Computing Lecture 14: Induction Mathematical Induction Method for proving statements about all natural numbers A new logical inference rule! It only applies over the natural numbers

More information

Weighted Activity Selection

Weighted Activity Selection Weighted Activity Selection Problem This problem is a generalization of the activity selection problem that we solvd with a greedy algorithm. Given a set of activities A = {[l, r ], [l, r ],..., [l n,

More information

20. Dynamic Programming II

20. Dynamic Programming II Quiz Solution 20. Dynamic Programming II Subset sum problem, knapsack problem, greedy algorithm vs dynamic programming [Ottman/Widmayer, Kap. 7.2, 7.3, 5.7, Cormen et al, Kap. 15,35.5] n n Table Entry

More information

What is Dynamic Programming

What is Dynamic Programming What is Dynamic Programming Like DaC, Greedy algorithms, Dynamic Programming is another useful method for designing efficient algorithms. Why the name? Eye of the Hurricane: An Autobiography - A quote

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 18 Dynamic Programming (Segmented LS recap) Longest Common Subsequence Adam Smith Segmented Least Squares Least squares. Foundational problem in statistic and numerical

More information

Lecture 11 October 7, 2013

Lecture 11 October 7, 2013 CS 4: Advanced Algorithms Fall 03 Prof. Jelani Nelson Lecture October 7, 03 Scribe: David Ding Overview In the last lecture we talked about set cover: Sets S,..., S m {,..., n}. S has cost c S. Goal: Cover

More information

Lecture 13: Dynamic Programming Part 2 10:00 AM, Feb 23, 2018

Lecture 13: Dynamic Programming Part 2 10:00 AM, Feb 23, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 13: Dynamic Programming Part 2 10:00 AM, Feb 23, 2018 Contents 1 Holidays 1 1.1 Halloween..........................................

More information