Reading — step 1 of 5
Read
~1 min readEdit Scripts
Edit Script: + - =
Once you have the LCS, generate an edit script: a sequence of operations that transforms A into B.
A: ABCBDAB
B: BDCAB
LCS: BCAB
Edit script:
- A (delete from A)
B (keep)
- C (delete from A)
B (keep)
+ D (insert from B)
- D (delete from A)
- A (delete from A)...
Actually let's redo with LCS=BDAB:
- A
B
- C
B
D
- A
+ (none — implicit)
A
B
+ (none)
Implementation: walk the DP backtrack, emitting:
- KEEP (=) when chars match
- DELETE (-) when stepping up (consumed A's char)
- INSERT (+) when stepping left (consumed B's char)
python
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…