{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_12

# lecture_12 - Introduction to Algorithms 6.046J/18.401J...

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

Introduction to Algorithms 6.046J/18.401J Prof. Charles E. Leiserson L ECTURE 12 Dynamic programming Longest common subsequence Optimal substructure Overlapping subproblems

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

View Full Document
Introduction to Algorithms October 25, 2004 L12.2 © 2001–4 by Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example: Longest Common Subsequence (LCS) Given two sequences x [1 . . m ] and y [1 . . n ] , find a longest subsequence common to them both.
Introduction to Algorithms October 25, 2004 L12.3 © 2001–4 by Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example: Longest Common Subsequence (LCS) Given two sequences x [1 . . m ] and y [1 . . n ] , find a longest subsequence common to them both. “a” not “the”

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

View Full Document
Introduction to Algorithms October 25, 2004 L12.4 © 2001–4 by Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example: Longest Common Subsequence (LCS) Given two sequences x [1 . . m ] and y [1 . . n ] , find a longest subsequence common to them both. x : A B C B D A B y : B D C A B A “a” not “the”
Introduction to Algorithms October 25, 2004 L12.5 © 2001–4 by Charles E. Leiserson Dynamic programming Design technique, like divide-and-conquer. Example: Longest Common Subsequence (LCS) Given two sequences x [1 . . m ] and y [1 . . n ] , find a longest subsequence common to them both. x : A B C B D A B y : B D C A B A “a” not “the” BCBA = LCS( x , y ) functional notation, but not a function

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

View Full Document
Introduction to Algorithms October 25, 2004 L12.6 © 2001–4 by Charles E. Leiserson Brute-force LCS algorithm Check every subsequence of x [1 . . m ] to see if it is also a subsequence of y [1 . . n ] .
Introduction to Algorithms October 25, 2004 L12.7 © 2001–4 by Charles E. Leiserson Brute-force LCS algorithm Check every subsequence of x [1 . . m ] to see if it is also a subsequence of y [1 . . n ] . Analysis Checking = O ( n ) time per subsequence. 2 m subsequences of x (each bit-vector of length m determines a distinct subsequence of x ). Worst-case running time = O ( n 2 m ) = exponential time.

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

View Full Document
Introduction to Algorithms October 25, 2004 L12.8 © 2001–4 by Charles E. Leiserson Towards a better algorithm Simplification: 1. Look at the length of a longest-common subsequence.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}