CSE 421 Weighted Interval Scheduling, Knapsack, RNA Secondary Structure

Similar documents
CSE 421 Dynamic Programming

CSE 202 Dynamic Programming II

Dynamic Programming 1

6. DYNAMIC PROGRAMMING I

Dynamic Programming: Interval Scheduling and Knapsack

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

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

CS 580: Algorithm Design and Analysis

6. DYNAMIC PROGRAMMING I

Copyright 2000, Kevin Wayne 1

6. DYNAMIC PROGRAMMING I

Dynamic Programming. Cormen et. al. IV 15

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

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

Copyright 2000, Kevin Wayne 1

CS 580: Algorithm Design and Analysis

Dynamic Programming( Weighted Interval Scheduling)

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

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

Chapter 6. Dynamic Programming. CS 350: Winter 2018

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

RNA Secondary Structure. CSE 417 W.L. Ruzzo

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

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

Dynamic programming. Curs 2015

Greedy Algorithms My T. UF

Algoritmiek, bijeenkomst 3

Knapsack and Scheduling Problems. The Greedy Method

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

Lecture 2: Divide and conquer and Dynamic programming

This means that we can assume each list ) is

CSE 421 Greedy Algorithms / Interval Scheduling

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

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

Dynamic programming. Curs 2017

Algorithm Design and Analysis

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

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

Mat 3770 Bin Packing or

Matching Residents to Hospitals

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

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

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

Recursion: Introduction and Correctness

Lecture 9. Greedy Algorithm

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

CS60007 Algorithm Design and Analysis 2018 Assignment 1

CS 6901 (Applied Algorithms) Lecture 3

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

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

Design and Analysis of Algorithms

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

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

Minimizing the Number of Tardy Jobs

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

CS325: Analysis of Algorithms, Fall Final Exam

Bin packing and scheduling

CS Analysis of Recursive Algorithms and Brute Force

Algorithm Design and Analysis

Greedy Algorithms. Kleinberg and Tardos, Chapter 4

General Methods for Algorithm Design

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

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

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

Lecture 7: Dynamic Programming I: Optimal BSTs

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

if the two intervals overlap at most at end

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

Algorithms Design & Analysis. Dynamic Programming

Greedy vs Dynamic Programming Approach

Design and Analysis of Algorithms

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

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

6.6 Sequence Alignment

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

CSE 202 Homework 4 Matthias Springer, A

CS473 - Algorithms I

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

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

Algorithms: COMP3121/3821/9101/9801

APTAS for Bin Packing

8 Knapsack Problem 8.1 (Knapsack)

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

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

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

arxiv: v1 [math.oc] 3 Jan 2019

CS2223 Algorithms D Term 2009 Exam 3 Solutions

Chapter 8 Dynamic Programming

Unit 1A: Computational Complexity

Lecture 6: Greedy Algorithms I

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

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

CS 6783 (Applied Algorithms) Lecture 3

CSE 311: Foundations of Computing. Lecture 14: Induction

Weighted Activity Selection

20. Dynamic Programming II

What is Dynamic Programming

Algorithm Design and Analysis

Lecture 11 October 7, 2013

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

Transcription:

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

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. oal: find maximum weight subset of mutually compatible jobs. a b c d e f g 9 h Time

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-

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

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.

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.

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-))

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

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] }

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)

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

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

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

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

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

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

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

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

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

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

Knapsack Problem

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.

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.

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.,

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]

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

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

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

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

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

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

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).

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

RNA Secondary Structure

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-

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.

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

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

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 ) }