lec19 - 6.006 6.006- Introduction to Algorithms to...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
.006- troduction to Algorithms 6.006 Introduction to Algorithms Lecture 19 Dynamic Programming II rof Manolis Kellis Prof. Manolis Kellis CLRS 15.4, 25.1, 25.2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Course VI - 6.006 – Module VI – This is it Dynamic Programming 2
Background image of page 2
Dynamic Programming ptimization technique widely applicable • Optimization technique, widely applicable Optimal substructure Overlapping subproblems uesday: Simple examples alignment • Tuesday: Simple examples, alignment – Fibonacci: top-down vs. bottom-up – Crazy Eights: one-dimensional optimization • Today: More DP – Alignment: Edit distance, molecular evolution – Back to paths: All Pairs Shortest Paths DP1,DP2 • Next week: – Knapsack (shopping cart) problem – Text Justification – Structured DP: Vertex Cover on trees, phylogeny
Background image of page 3

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

View Full DocumentRight Arrow Icon
Today: Dynamic programming II • Optimal sub-structure, repeated subproblems • Review: Simple DP problems – Fibonacci numbers: Top-down vs. bottom-up – Crazy Eights: One-dimensional optimization • LCS, Edit Distance, Sequence alignment wo- imensional optimization: Matrix/path duality Two dimensional optimization: Matrix/path duality – Setting up the recurrence, Fill Matrix, Traceback ll pairs shortest paths (naïve: 2 n* elFo n • All pairs shortest paths (naïve: 2 n . n BelFo: n 4 ) – Representing solutions. Two ways to set up DP atrix multiplication: n n Floyd arshall n – Matrix multiplication: n 3 lgn. Floyd-Warshall: n 3
Background image of page 4
Hallmarks of optimization problems reedy algorithms ynamic Programming 1. Optimal substructure n optimal solution to a problem (instance) Greedy algorithms Dynamic Programming An optimal solution to a problem (instance) contains optimal solutions to subproblems. 2. Overlapping subproblems A recursive solution contains a “small” number of distinct subproblems repeated many times. 3. Greedy choice property Locally optimal choices lead to globally optimal solution Greedy Choice is not possible Globally optimal solution requires trace back through many choices gy
Background image of page 5

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

View Full DocumentRight Arrow Icon
Fibonacci Computation 1. Fibonacci Computation (not really an optimization problem, but similar intuition applies)
Background image of page 6
Computing Fibonacci numbers: Top down Fibonacci numbers are defined recursively: y – Python code def fibonacci(n): if n==1 or n==2: return 1 return fibonacci(n-1) + fibonacci(n-2) Goal: Compute n th Fibonacci number. (0)=1, F(1)=1, F(n)=F(n- )+F(n- ) F(0) 1, F(1) 1, F(n) F(n 1) F(n 2) – 1,1,2,3,5,8,13,21,34,55,89,144,233,377,… Analysis: – T(n) = T(n-1) + T(n-2) = (…) = O(2 n )
Background image of page 7

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

View Full DocumentRight Arrow Icon
Computing Fibonacci numbers: Bottom up op own approach Top-down approach – Python code def fibonacci(n): b table () fib_table[1] = 1 fib_table[2] = 1 for i in range(3,n+1): fib table[i] = fib table[i-1]+fib table[i-2] [3] 1 F[2] 1 F[1] fib_table – Analysis: T(n) = O(n) _[ ] ]_ [ ] return fib_table[n] [6] 5 F[5] 3 F[4] 2 F[3] 21 F[8] 13 F[7] 8 F[6] 89 F[11] 55 F[10] 34 F[9] ? F[12]
Background image of page 8
Crazy Eights 2. Crazy Eights One-dimensional Optimization
Background image of page 9

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

View Full DocumentRight Arrow Icon
Crazy8: Example computation i=1 i=2 i=3 i=4 i=5 c[i] 7 7 K K 8 max [ 1 223 4 score[i] Input: a sequence of cards c[0]…c[n-1] .
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

Page1 / 48

lec19 - 6.006 6.006- Introduction to Algorithms to...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online