Lecture15

# Lecture15 - Lecture 15, Nov 16 2010 Dynamic Programming...

This preview shows pages 1–3. Sign up to view the full content.

1 179 Dynamic Programming Main problem with greedy approaches: sometimes we cannot commit up-front . Dynamic programming: » Meta-technique, not a specific algorithm. Main idea: » solve many small sub-problems , » combine solution to several small subproblems to solve larger subproblems. » continue combining until we solve the original problem. Lecture 15, Nov 16 2010 180 Simple example Problem: » Given a line with nodes v 1 , v 2 , , v n . » Each node v i has positive weight w i » Choose a subset of nodes such that Total weight of the chosen nodes is maximized No “neighbors” chosen, i.e. if v i chosen, then neither v i+1 nor v i-1 chosen For simplicity: output only the value of maximum weight set (do not list nodes) What is the problem with greedy approach ? Subproblems: W i maximum weight if we look only at nodes 1 to i . W 0 =0 Observation: W i+1 = max{ W i ,W i-1 +w i+1 } (Either use w i+1 , in which case do not use w i , or do not use w i+1 ) Running time ? 9 6 1 8 52 1 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 181 Longest Common Subsequence Consider two sequences: x = A B C B D A B |x| = m y = B D C A B A |y| = n Subsequence – “keep order, delete some elements” Goal: Find longest subsequence common to x and y Greedy: does not seem to work Brute force: » Consider all substrings of x, all substrings of y, compare.
This is the end of the preview. Sign up to access the rest of the document.

## Lecture15 - Lecture 15, Nov 16 2010 Dynamic Programming...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online