lec18 - 6.006 6.006- Introduction to Algorithms to...

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

.006- troduction to lgorithms 6.006 Introduction to Algorithms Lecture 18 Dynamic Programming I rof anolis Kellis Prof. Manolis Kellis CLRS 15.3, 15.4

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

View Full Document
Course VI - 6.006 – Module VI – This is it Dynamic Programming 2
Dynamic Programming ptimization technique widely applicable • Optimization technique, widely applicable Optimal substructure Overlapping subproblems oday: Simple examples alignment • Today: Simple examples, alignment – Simple examples: Fibonacci, Crazy Eights – Alignment: Edit distance, molecular evolution • Thursday: More DP – Alignment: Bound, Linear Space, Affine Gaps – Back to paths: All Pairs Shortest Paths DP1,DP2 • Next week: – Knapsack (shopping cart) problem – Text Justification – Structured DP: Vertex Cover on trees, phylogeny

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

View Full Document
Today: Dynamic programming • Fibonacci numbers – Top-down vs. bottom-up • Principles of Dynamic programming – Optimal sub-structure, repeated subproblems razy Eights Crazy Eights – One-dimensional optimization equence alignment • Sequence alignment – Two-dimensional optimization
Fibonacci Computation 1. Fibonacci Computation (not really an optimization problem, but similar intuition applies)

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

View Full Document
A simple introduction to Dynamic Programming • Fibonacci numbers 55 8 13 3 2 5 34 21
Fibonacci numbers are ubiquitous in nature abbits per generation eaves per height Rabbits per generation Leaves per height Romanesque spirals Nautilus size Coneflower spirals Leaf ordering

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

View Full Document
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 )
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]

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

View Full Document
Lessons from iterative Fibonacci algorithm • What did the iterative solution do? – Reveal identical sub-problems 1 F[1] fib_table – Order computation to enable result reuse – Systematically filled-in table of results xpressed larger problems from their subparts 3 F[4] 2 F[3] 1 F[2] – Expressed larger problems from their subparts • Ordering of computations matters – Naïve top-down approach very slow 13 F[7] 8 F[6] 5 F[5] p pp y • results of smaller problems not available • repeated work 55 F[10] 34 F[9] 21 F[8] – Systematic bottom-up approach successful • Systematically solve each sub-problem ill- table of sub- roblem results in order ? F[12] 89 F[11] Fill in table of sub problem results in order.
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 / 43

lec18 - 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
Ask a homework question - tutors are online