lec18 - 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 lgorithms 6.006 Introduction to Algorithms Lecture 18 Dynamic Programming I rof anolis Kellis Prof. Manolis Kellis CLRS 15.3, 15.4
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 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
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 • 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
Background image of page 4
Fibonacci Computation 1. Fibonacci Computation (not really an optimization problem, but similar intuition applies)
Background image of page 5

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

View Full DocumentRight Arrow Icon
A simple introduction to Dynamic Programming • Fibonacci numbers 55 8 13 3 2 5 34 21
Background image of page 6
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
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: 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 8
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 9

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

View Full DocumentRight Arrow Icon
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.
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 / 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 Right Arrow Icon
Ask a homework question - tutors are online