1 / 7

More dynamic programming Longest common subsequence

More dynamic programming Longest common subsequence. Definition of Subsequences on board. Proof of optimal substructure on board. Recursive Formula derivation on board. Example from CLRS. Lambda is the null string. We fill the first row and column with zeros because the LCS of

alair
Download Presentation

More dynamic programming Longest common subsequence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. More dynamic programming Longest common subsequence

  2. Definition of Subsequences on board. • Proof of optimal substructure on board. • Recursive Formula derivation on board. • Example from CLRS.

  3. Lambda is the null string. We fill the first row and column with zeros because the LCS of a null string with anything is zero. 0 1 2 3 4 5 6 j λ C A B A yj i B D λ 0 1 A 2 B C 3 4 B 5 D A 6 7 B xi

  4. Begin filling in row major order. We place a pointer to tell where the value was obtained from to help with traceback. 0 1 2 3 4 5 6 j λ C A B A yj i B D λ 0 1 A 2 B C 3 4 B 5 D A 6 7 B xi

  5. Continue filling in row major order. 0 1 2 3 4 5 6 j λ C A B A yj i B D λ 0 1 A 2 B C 3 4 B 5 D A 6 7 B xi

  6. Final Result (from CLRS page 395)

  7. The following procedure (from CLRS page 396) will print the LCS. Initial call is to (b, X, 7, 6) • This will print BCBA. PrintLCS(7,6) (6,6) print A (5,5) (4,5) print B (3,4) (3,3) print C (2,2) (2,1) print B (1,0) See previous slide. It prints on return from call with

More Related