Dynamic Programming
Weighted interval scheduling (Binary Choice of Opti Sub)
Jobstarts at , finishes at , and has weight .
Two jobs are compatible if they don’t overlap.
Goal: find a max-weight subset of mutually compatible jobs.
largest index such that job is compatible with .
To efficiently computer we can sort jobs in ascending order of finish time.
Constraints on the interval time (subproblem)
Seek max weights (open values)
Optimum Subproblem
Max weight with an increasing ordering subset of mutually compatible intervals.
Bellman equation
Maximum Continuous Subarray Sum-KADANE ’ S ALGORITHM (Binary Choice of Opti Sub)
Constraints on the continuous subarray (subproblem)
Seek max weights (open values)
Optimum Subproblem
Max sum with an increasing ending index. (or increasing ordering subset)
max sum of any subarray of whose rightmost index is .
Bellman equation
Knapsack problem (Two variable Opti Subp)
Goal. Pack knapsack so as to maximize the total value of items taken.
There are items: item provides value and weighs .
Value of a subset of items = sum of values of individual items.
The Knapsack has a weight limit of W.
Constraints on the weights and at most 1 items for each item (subproblem)
Seek max values (open values)
Optimum Subproblem
Max value with an increasing ending index with a change of weight limit. (or increasing ordering subset)
optimal value of knapsack problem with items subject to weight limit .
Bellman equation
Coin Changing (Multiway-choice Opti Subp)
Goal. Given n coin denominations and a target value , find the fewest coins needed to make change for (or report impossible).
Constraints on the change values (subproblem, increasing changes of values, subproblem is created by choosing any coins currently)
Seek max number of coins (open questions, because for each coin we do not know we need how many)
Optimum Subproblem
The minimum number of coins with an increasing value of changes.
min number of coins to make change for. (The current subproblem can be set by choosing any coin denomination. (Multi-way choice))
Bellman equation
RNA(String) secondary structure (Substring) (Intervals Opti Subp)
RNA. String B = over alphabet { A, C, G, U }.
Secondary structure. RNA is single-stranded so it tends to loop back and form base pairs with itself with the following rules:
[Watson–Crick] Pairs with Watson–Crick complement: A–U, U–A, C–G, or G–C.
[No sharp turns] The ends of each pair are separated by at least 4 intervening bases. If , then.
[Non-crossing] If and are two pairs in , then we cannot have .
Goal. Given an RNA molecule, find a secondary structure that maximizes the number of base pairs.
Constraints on the substrings
(subproblem, increasing ending index of the substring, subproblem is created by choosing any letter that comes before the current letter to form two new substrings.)
These two substrings for the subproblems form an interval optimal subproblems.
Seek max number of Watson-Crick pairs
Optimum Subproblem
The maximum number of WC pairs with an increasing ending index of the substring. Each subproblem is solved by all substrings within.
maximum number of base pairs in a secondary structure of the substring
Bellman equation
RNA-SECONDARY-STRUCTURE (n, b_1 , …, b_n )
FOR k = 5 TO n – 1
FOR i = 1 TO n – k
j ← i + k.
Compute M[i, j] using formula.
RETURN M[1, n].
Sequence Alignment (Substring) (Two-Variable Opti Subp)
Edit distance. [Levenshtein 1966, Needleman–Wunsch 1970]
Gap penalty ; mismatch penalty .
Cost = sum of gap and mismatch penalties.
Sequence alignment. Given two strings and , find a min-cost alignment.
An alignment M is a set of ordered pairs such that each character appears in at most one pair and no crossings.
Constraints on the two substrings
(subproblem, increasing ending index of the two strings)
Optimum Subproblem
The minimum cost of alignment with an increasing ending index of the two substrings.
min cost of aligning prefix strings and .
Bellman equation
Last updated
Was this helpful?