1
Dynamic Programming
Chapter 16
CPTR 318
1
Dynamic Programming
- Has nothing to do with programming in the
way we normally use that term
– More like TV programming (scheduling) – Filling in a table
- Algorithm design technique
2
Longest Common Subsequence
- Given two sequences
X = x0 x1 x2 … xm-1 Y = y0 y1 y2 … yn-1 find a longest sequence common to both
- Example:
X = A B C B D A B Y = B D C A B A
– B D A B – B C A B – B C B A
3
Longest Common Subsequence
- Given two sequences
X = x0 x1 x2 … xm-1 Y = y0 y1 y2 … yn-1 find a longest sequence common to both
- Example:
X = A B C B D A B Y = B D C A B A
– B D A B – B C A B – B C B A
4
Longest Common Subsequence
- Given two sequences
X = x0 x1 x2 … xm-1 Y = y0 y1 y2 … yn-1 find a longest sequence common to both
- Example:
X = A B C B D A B Y = B D C A B A
– B D A B – B C A B – B C B A
5
Longest Common Subsequence
- Given two sequences
X = x0 x1 x2 … xm-1 Y = y0 y1 y2 … yn-1 find a longest sequence common to both
- Example:
X = A B C B D A B Y = B D C A B A
– B D A B – B C A B – B C B A
6