Dynamic Programming II: Algorithms and Applications, Lecture notes of Algorithms and Programming

[Week 8] Dynamic Programming II -- RNA Secondary Structure

Typology: Lecture notes

2018/2019

Uploaded on 06/15/2019

kefart
kefart 🇺🇸

4.4

(11)

55 documents

1 / 56

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The University of Sydney Page 1
Lecture 8:
Dynamic Programming II
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38

Partial preview of the text

Download Dynamic Programming II: Algorithms and Applications and more Lecture notes Algorithms and Programming in PDF only on Docsity!

Lecture 8:

Dynamic Programming II

– Stable Matching

– Greedy algorithms

– Divide & Conquer algorithms

– Dynamic programming algorithms

– Network flow algorithms

General techniques in this course

Key steps: Dynamic programming

1. Define subproblems

2. Find recurrences

3. Solve the base cases

4. Transform recurrence into an efficient algorithm

Recap: Weighted Interval Scheduling

  • Job j starts at s j

, finishes at f

j

, and has value v

j

  • Two jobs compatible if they don't overlap.
  • Goal: find maximum value subset of mutually compatible jobs. Time 0 1 2 3 4 5 6 7 8 9 10 11 f g h e a b c d

Recap: Dynamic Programming – Step 1

Step 1: Define subproblems

OPT(j) = value of optimal solution to the problem

consisting of job requests 1, 2, ..., j.

Recap: Dynamic Programming – Step 2

Step 2: Find recurrences

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

OPT(j) = v

j

max { + OPT (p(j)), OPT(j-1)}

Case 1 Case 2

Recap: Knapsack Problem

  • Knapsack problem.
    • Given n objects and a "knapsack."
    • Item i weighs wi > 0 kilograms and has value v (^) i > 0.
    • Knapsack has capacity of W kilograms.
    • Goal: fill knapsack so as to maximize total value. 1 Value 18 22 28 1 Weight 5 6 6 2 7 Item 1 3 4 5 2 W = 11

Knapsack Algorithm Recap

n + 1 1 Value 18 22 28 1 Weight 5 6 6 2 7 Item 1 3 4 5 2 ∅ { 1, 2 } { 1, 2, 3 } { 1, 2, 3, 4 } { 1 } { 1, 2, 3, 4, 5 } 0 0 0 0 0 0 0 1 0 1 1 1 1 1 2 0 6 6 6 1 6 3 0 7 7 7 1 7 4 0 7 7 7 1 7 5 0 7 18 18 1 18 6 0 7 19 22 1 22 7 0 7 24 24 1 28 8 0 7 25 28 1 29 9 0 7 25 29 1 34 10 0 7 25 29 1 35 11 0 7 25 40 1 40 W + 1 W = 11 OPT: { 4, 3 } value = 22 + 18 = 40

Recap: Dynamic Programming – Step 2

Step 2: Find recurrences

  • Case 1: OPT does not select item i.
    • OPT selects best of { 1, 2, …, i-1 } using weight limit w
  • Case 2: OPT selects item i.
    • new weight limit = w – wi
    • OPT selects best of { 1, 2, …, i–1 } using this new weight limit

OPT(i,w) = max { v

i

+ OPT (i-1,w-w

i

), OPT(i-1,w) }

Recap: Dynamic Programming – Step 2

Step 2: Find recurrences

  • Case 1: OPT does not select item i.
    • OPT selects best of { 1, 2, …, i-1 } using weight limit w
  • Case 2: OPT selects item i.
    • new weight limit = w – wi
    • OPT selects best of { 1, 2, …, i–1 } using this new weight limit

If w

i

>w

OPT(i,w) = OPT (i-1,w)

otherwise

OPT(i,w) = max { v

i

+ OPT (i-1,w-w

i

), OPT(i-1,w) }

Recap: Longest increasing subsequence

Given a sequence of numbers X[1..n] find the longest increasing

subsequence (i

1

, i

2

, …, i

k

), that is a subsequence where numbers in

the sequence increase.

j i
LIS 1 1 1 1 1 1 1 1

Recap: Longest increasing subsequence

Given a sequence of numbers X[1..n] find the longest increasing

subsequence (i

1

, i

2

, …, i

k

), that is a subsequence where numbers in

the sequence increase.

j i
L 1 1 2 1 1 1 1 1

If X[i] > X[j] then L[i] + 1 = 1 + 1 = 2 is this > L[i] yes L[i] = 2 move j to next position and check again

Recap: Longest increasing subsequence

Given a sequence of numbers X[1..n] find the longest increasing

subsequence (i

1

, i

2

, …, i

k

), that is a subsequence where numbers in

the sequence increase.

j i
L 1 1 2 2 1 1 1 1

If X[i] > X[j] then L[i] + 1 = 1 + 1 = 2 is this > L[i] yes L[i] = 2 move j to next position and check again

Recap: Longest increasing subsequence

Given a sequence of numbers X[1..n] find the longest increasing

subsequence (i

1

, i

2

, …, i

k

), that is a subsequence where numbers in

the sequence increase.

j i
L 1 1 2 2 2 3 1 1

If X[i] > X[j] then L[i] + 1 = 1 + 1 = 2 is this > L[i] yes L[i] = 2 move j to next position and check again