12.07.2015 Views

Dynamic Programming 1

Dynamic Programming 1

Dynamic Programming 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

! E(i,j) = min[1 + E(i-1,j), 1 + E(i,j-1), diff(i,j) + E(i-1,j-1)]! Note that we could use different penalties for insert andsubstitution based on whatever goals we have! Answers fill in a 2-d table! Any computation order is all right as long as E(i-1,j),E(i,j-1), and E(i-1,j-1) are computed before E(i,j)! What are base cases? (x is any integer ≥ 0):– E(0,x) = x example: E("", "rib") = 3 (3 inserts)– E(x,0) = x example: E("ri", "") = 2 (2 inserts)! If we want to recover the edit sequence found we just keepa back pointer to the previous minimum as we grow thetableCS 312 – <strong>Dynamic</strong> <strong>Programming</strong> 32

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!